def stopPlaying(self): for speakerIp in self.sonos.get_speaker_ips(): sonosSpeaker = SoCo(speakerIp) all_info = sonosSpeaker.get_speaker_info() for item in all_info: logging.info("Stopping for speaker %s: %s" % (item, all_info[item])) sonos.stop() LCDScreen.updateStatus("Sonos" , "Music Stopped" )
def handle(self, *args, **options): try: splash = SplashScreen() splash.ShowSplash() logging.info( 'Service command starting') svc = JukeboxService() svc.Run() logging.info( 'Service command ending') except: logging.error('Error running service %s' % sys.exc_info()[1]) LCDScreen.updateStatus("ERROR", str(sys.exc_info()[1]) )
def __init__(self): super(JukeboxService, self).__init__() try: self.signalReceiver = JukeboxSignalReceiver(self) self.keyProcessor = JukeboxKeyProcessor() self.signalReceiver.start() self.lastSignalTime = datetime.datetime.now() self.signalLock = threading.Lock() except: err = str(sys.exc_info()[1]) LCDScreen.updateStatus("ERR", err) logging.error('Error initialising jukebox service %s' % err)
class SplashScreen(object): lcd = None def __init__(self): self.lcd = LCDScreen() self.lcd.start() def ShowSplash(self): self.lcd.screenOn() LCDScreen.updateStatus("Sonos Jukebox", "Coopes 2014") sleep(2) LCDScreen.updateStatus("Sonos Jukebox", "Starting....") sleep(1)
def ProcessKey(self, shortCutKeys): logging.info('Sent short cut "%s"' % shortCutKeys) LCDScreen.updateStatus("Keys Received", shortCutKeys) try: shortCut = self.shortCutMgr.getShortCut(shortCutKeys) except: shortCut = None # Is this a known shortcut? if shortCut != None: LCDScreen.updateStatus("Shortcut", shortCut.track ) speakerConfig = self.configMgr.getConifgItem( "TARGET_SPEAKER") logging.info('Short cut track is"%s" running from "%s"' % (shortCut.track, shortCut.type)) logging.info('Successfully read speaker to send to as "%s"' % (speakerConfig.value)) # tell sonos how to play its shortcut if shortCut.type =="Pandora": self.sonosPlayer = SonosForPandora() self.sonosPlayer.playStation(shortCut.track, speakerConfig.value) else: logging.error('Unsupported shortcut type %s' % shortCut.type ) LCDScreen.updateStatus("ERROR", "UNK TYPE: %s" % shortCut.type ) sleep(5) LCDScreen.updateStatus("Sonos Jukebox", "Ready....") else: logging.error('Shortcut not found for %s' % shortCutKeys ) LCDScreen.updateStatus("ERROR", "UNK S/CUT: %s" % shortCutKeys ) sleep(5)
def Run(self): logging.info( 'Jukebox Service running') self.lastSignalTime = datetime.datetime.now() LCDScreen.updateStatus("Sonos Jukebox", "Ready....") try: while 1: sleep(1) keyPress = self.SignalsToKeyUpdater() # get any key , then process them ! if keyPress != None : logging.info( 'Key press waiting to be processed. Sending to processor') self.keyProcessor.ProcessKey(keyPress) LCDScreen.updateStatus("Sonos Jukebox", "Ready....") except: err = str(sys.exc_info()[1]) LCDScreen.updateStatus("ERR", err) logging.error('Error processing keys %s' % err)
def playStation(self, stationNameLike, onSpeakerLike): LCDScreen.updateStatus("Pandora", "Loading music") stationId = self.rpandora.getIdForStation(stationNameLike) stationName = self.rpandora.getNameForStation(stationNameLike) LCDScreen.updateStatus("Pl: %s" % stationName, "On %s" % onSpeakerLike ) for speakerIp in self.sonos.get_speaker_ips(): try: sonosSpeaker = SoCo(str(speakerIp)) all_info = sonosSpeaker.get_speaker_info() if onSpeakerLike in all_info['zone_name'] : logging.info("Playing on speaker %s" % str(speakerIp)) sonosSpeaker.play_uri("pndrradio:%s" % str(stationId), '') LCDScreen.updateStatus("Pl: %s" % stationName, "On %s" % all_info['zone_name'] ) else: logging.info('Skipping player "%s"' % all_info['zone_name']) except: logging.error('Failed calling %s' % speakerIp)
def ShowSplash(self): self.lcd.screenOn() LCDScreen.updateStatus("Sonos Jukebox", "Coopes 2014") sleep(2) LCDScreen.updateStatus("Sonos Jukebox", "Starting....") sleep(1)
def __init__(self): self.lcd = LCDScreen() self.lcd.start()