Exemplo n.º 1
0
 def _beep(self, alt_sound=False):
     ''' play beep through gpio buzzer or speakers '''
     if "GPIO_BUZZER_PIN" in self.config and self.config["GPIO_BUZZER_PIN"]:
         self.get_module("gpio").command("beep", alt_sound)
     else:
         filename = os.path.join(RESOURCES_FOLDER, 'ding.wav')
         if alt_sound:
             filename = os.path.join(RESOURCES_FOLDER, 'dong.wav')
         # play sound with sox (ignore if it fails)
         cur_pwr = self.states["player"]["power"]
         self._set_power(True)
         if not cur_pwr:
             time.sleep(0.1)
         run_proc("/usr/bin/play %s" % filename)
         if not cur_pwr:
             self._set_power(False)
Exemplo n.º 2
0
    def run(self):
        if self.enable_squeezelite:
            # we start squuezelite manually with our optimal settings
            run_proc("service squeezelite stop", ignore_error=True)
            exec_path = "/usr/bin/squeezelite"
            args = [exec_path, "-C", "1", "-n", self.player_name, "-a", "4096:1024"]
            if self.monitor.config["ALSA_VOLUME_CONTROL"] and self.monitor.config["ALSA_VOLUME_CONTROL"] != VOLUME_CONTROL_DISABLED:
                args += ["-V", self.monitor.config["ALSA_VOLUME_CONTROL"]]
            if self.monitor.config["ALSA_SOUND_DEVICE"]:
                args += ["-o", self.monitor.config["ALSA_SOUND_DEVICE"]]
            if self.monitor.config["ENABLE_DEBUG"]:
                LOGGER.debug("Starting squeezelite: %s" % " ".join(args))
                self._squeezelite_proc = subprocess.Popen(args)
            else:
                self._squeezelite_proc = subprocess.Popen(args, stdout=DEVNULL, stderr=subprocess.STDOUT)
        # connect to the roon websockets api
        appinfo = {
            "extension_id": "pi_monitor_%s" % HOSTNAME,
            "display_name": "Pi Monitor (%s)" % HOSTNAME,
            "display_version": "1.0.0",
            "publisher": "marcelveldt",
            "email": "*****@*****.**",
            "website": "https://github.com/marcelveldt/pi-monitor"
        }
        token = self.monitor.config.get("ROON_AUTH_TOKEN","")
        self._roonapi = RoonApi(appinfo, token, blocking_init=True)
        self.monitor.config["ROON_AUTH_TOKEN"] = self._roonapi.token
        self._roonapi.register_state_callback(self._roon_state_callback, event_filter="zones_changed", id_filter=self.player_name)
        if self.monitor.config.get("ROON_ENABLE_SOURCE_CONTROL", True):
            # register this player as a source control in Roon
            self._roonapi.register_source_control(HOSTNAME, HOSTNAME, self._roon_source_control_callback, "standby")
        self.monitor.register_state_callback(self._monitor_state_changed_event, "player")

        # some players need to be unmuted when freshly started
        if self.output_id:
            self._roonapi.mute(self.output_id, False)

        # store token
        if self._roonapi.token:
            self.monitor.config["ROON_AUTH_TOKEN"] = self._roonapi.token

        # mainloop: just keep the thread alive
        while not self._exit.isSet():
            self._exit.wait(1200)
Exemplo n.º 3
0
 def run(self):
     # we start squuezelite manually with our optimal settings
     run_proc("service squeezelite stop", ignore_error=True)
     exec_path = "/usr/bin/squeezelite"
     args = [exec_path, "-C", "1", "-n", HOSTNAME, "-a", "4096:1024", "-m", self._playerid]
     if self.monitor.config["ALSA_VOLUME_CONTROL"] and self.monitor.config["ALSA_VOLUME_CONTROL"] != VOLUME_CONTROL_DISABLED:
         args += ["-V", self.monitor.config["ALSA_VOLUME_CONTROL"]]
     if self.monitor.config["ALSA_SOUND_DEVICE"]:
         args += ["-o", self.monitor.config["ALSA_SOUND_DEVICE"]]
     if self.monitor.config["ENABLE_DEBUG"]:
         LOGGER.debug("Starting squeezelite: %s" % " ".join(args))
         self._squeezelite_proc = subprocess.Popen(args)
     else:
         self._squeezelite_proc = subprocess.Popen(args, stdout=DEVNULL, stderr=subprocess.STDOUT)
     # auto discover LMS server....
     lmsserver = None
     while not lmsserver and not self._exit.isSet():
         LOGGER.info("disovering LMS server ...")
         servers = LMSDiscovery().all()
         if servers:
             lmsserver = servers[0]  # for now, just use the first server discovered
             break
         else:
             self._exit.wait(2)
     if lmsserver:
         self._host = lmsserver["host"]
         self._port = lmsserver["port"]
         LOGGER.info("LMS server discovered - host: %s - port: %s" % (self._host, self._port))
     else:
         return
     # main loop
     while not self._exit.isSet():
         cur_state = self._get_state()
         if cur_state != self._last_state:
             self._last_state = cur_state
             self.monitor.states["squeezelite"]["state"] = cur_state
             self._update_metadata()
         if cur_state == "playing":
             self._update_metadata()
             LOOP_WAIT = 0.5
         else:
             LOOP_WAIT = 2
         self._exit.wait(LOOP_WAIT)
Exemplo n.º 4
0
 def _process_command(self, target, cmd, cmd_data=None):
     ''' process command from the queue '''
     try:
         LOGGER.debug("processing command %s for target %s with data %s" %
                      (cmd, target, str(cmd_data)))
         if target == "player":
             # redirect player commands
             self._player_command(cmd, cmd_data)
         elif target == "power":
             # power commands
             if cmd == "power":
                 self._set_power(cmd_data)
             elif cmd == "poweron":
                 self._set_power(True, cmd_data)
             elif cmd == "poweroff":
                 self._set_power(False, cmd_data)
         elif target == "system":
             # system commands
             if cmd == "saveconfig":
                 self._saveconfig()
             elif cmd == "run_proc" and cmd_data:
                 run_proc(cmd_data)
             elif cmd in ["restart", "reboot"]:
                 self.states["messages"].append("Reboot in progress!")
                 LOGGER.warning("System will now reboot!")
                 os.system("reboot")
             elif cmd == "reload":
                 self.states["messages"].append("The service is reloading!")
                 LOGGER.info("Restart of service requested!\n")
                 os.kill(os.getpid(), 15)
             elif cmd in ["ping", "beep", "buzz"]:
                 self._beep(cmd_data)
         elif target and cmd:
             # direct command to module
             mod = self.get_module(target)
             result = mod.command(cmd, cmd_data)
             LOGGER.debug(
                 "redirected command %s with data %s to module %s with result %s"
                 % (cmd, str(cmd_data), target, result))
     except Exception:
         LOGGER.exception("error while executing command %s for target %s" %
                          (cmd, target))
Exemplo n.º 5
0
 def __init__(self, monitor):
     self.monitor = monitor
     self.monitor.states["spotify"] = PlayerMetaData("Spotify")
     run_proc("service spotify-connect-web stop", ignore_error=True) # make sure that the original service is stopped
     run_proc("service raspotify stop", ignore_error=True) # make sure that the original service is stopped
     threading.Thread.__init__(self)
Exemplo n.º 6
0
 def __init__(self, monitor):
     self.monitor = monitor
     self.monitor.states["airplay"] = PlayerMetaData("Airplay")
     run_proc("service shairport-sync stop", ignore_error=True
              )  # make sure that the original service is stopped
     threading.Thread.__init__(self)