def play(file_name): try: if file_name is not None: cmd = "mplayer -ao alsa -really-quiet -noconsolecontrols " call(cmd+file_name, shell=True) CloudLog.debug("SoundSystem", file_name) except Exception, e: CloudLog.error("SoundSystem.Play", "Error playing sound", e)
def _getClient(self): CloudLog.debug(self._component, "Connecting.") try: client = HarmonyClient.create_and_connect_client(self._ip_address, self._port, self._uuid) CloudLog.debug(self._component, "Connected.") return client except Exception, e: CloudLog.error(self._component, "Error connecting to the Harmony Bridge", e) return None
def _getClient(self): CloudLog.debug(self._component, "Connecting.") try: client = HarmonyClient.create_and_connect_client( self._ip_address, self._port, self._uuid) CloudLog.debug(self._component, "Connected.") return client except Exception, e: CloudLog.error(self._component, "Error connecting to the Harmony Bridge", e) return None
def listen(controller): component = "KeyPadController" runLoop = True modifier = None modTimer = datetime.min keyModifier = { "\t": "Off", "/": "VirginBlue", "*": "NightRed", "\x7f": "DimWhite", "+": "UP", "-": "DOWN" } while runLoop: CloudLog.debug(component, "Waiting for key") charInput = GetCh() CloudLog.debug(component, "Got Key") if modTimer + timedelta(seconds=4) < datetime.now(): modifier = None modTimer = datetime.min if charInput == "q" or charInput == "Q": CloudLog.log(component, "User Interupt (Q)") controller.shutdown() runLoop = False elif charInput == "r" or charInput == "R": controller.config.read() elif keyModifier.get(charInput) is not None: modifier = keyModifier.get(charInput) modTimer = datetime.now() else: if charInput == "\r": charInput = "H" modifier = None elif charInput == "0": modifier = None CloudLog.log(component + ":KeyPress", charInput + ":" + str(modifier)) controller.executeCommandByKeyCode(charInput, modifier) modifier = None modTimer = datetime.min
def run(self): component = "KeyPadController" runLoop = True modifier = None modTimer = datetime.min keyModifier = { "\t": "Off", "/": "VirginBlue", "*": "NightRed", "\x7f": "DimWhite", "+": "UP", "-": "DOWN" } while runLoop: CloudLog.debug(component, "Waiting for key") charInput = GetCh() CloudLog.debug(component, "Got Key") if modTimer + timedelta(seconds=4) < datetime.now(): modifier = None modTimer = datetime.min if charInput == "q" or charInput == "Q": CloudLog.log(component, "User Interupt (Q)") runLoop = False elif keyModifier.get(charInput) is not None: modifier = keyModifier.get(charInput) modTimer = datetime.now() else: CloudLog.log(component + ":KeyPress", charInput + ":" + str(modifier)) try: command = self._commands[charInput] self._announce({"command": command, "modifier": modifier}) except: pass modifier = None modTimer = datetime.min
result["request"]["activity_id"] = activity_id client = self._getClient() if client: try: response = client.start_activity(activity_id) result["completed"] = True result["response"] = response except Exception, e: CloudLog.error(self._component, "Unable to start activity", e) result["error"] = str(e) finally: self._disconnectClient(client) else: CloudLog.error(self._component, "No Harmony Bridge available.") result["error"] = "No bridge available" CloudLog.debug(self._component, json.dumps(result)) return result def currentActivity(self): result = {"completed": False, "request": {}} result["request"]["command"] = "/currentActivity" client = self._getClient() if client: try: response = client.get_current_activity() result["completed"] = True result["response"] = response except Exception, e: CloudLog.error(self._component, "Unable to get current activity", e) result["error"] = str(e) finally:
e) def sendCommand(self, lights, command): result = {"completed": False, "request": {}} result["request"]["lights"] = lights result["request"]["command"] = command if self._ready: try: response = self._phue.set_light(lights, command) result["completed"] = True result["response"] = response except Exception, e: CloudLog.error(self._component, "Error calling phue", e) else: CloudLog.error(self._component, "Device not ready.") CloudLog.debug(self._component, json.dumps(result)) return result def status(self): result = {"completed": False, "request": {}} result["request"]["command"] = "/status" if self._ready: try: response = self._phue.get_api() result["completed"] = True result["response"] = response except Exception, e: CloudLog.error(self._component, "Error calling phue", e) else: CloudLog.error(self._component, "Device not ready.") CloudLog.debug(self._component, json.dumps(result))