def setup_platform(hass, config, add_devices, discovery_info=None): """Setup Harmony platform.""" import pyharmony global DEVICES name = config.get(CONF_NAME) host = config.get(CONF_HOST) port = config.get(CONF_PORT) _LOGGER.info('Loading Harmony platform: ' + name) harmony_conf_file = hass.config.path('harmony_' + slugify(name) + '.conf') try: _LOGGER.debug('calling pyharmony.ha_get_token for remote at: ' + host + ':' + port) token = urllib.parse.quote_plus(pyharmony.ha_get_token(host, port)) except ValueError as err: _LOGGER.critical(err.args[0] + ' for remote: ' + name) return False _LOGGER.debug('received token: ' + token) DEVICES = [ HarmonyRemote(config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT), config.get(ATTR_ACTIVITY), harmony_conf_file, token) ] add_devices(DEVICES, True) register_services(hass) return True
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Harmony platform.""" import pyharmony global DEVICES name = config.get(CONF_NAME) host = config.get(CONF_HOST) port = config.get(CONF_PORT) _LOGGER.debug("Loading Harmony platform: %s", name) harmony_conf_file = hass.config.path( '{}{}{}'.format('harmony_', slugify(name), '.conf')) try: _LOGGER.debug("Calling pyharmony.ha_get_token for remote at: %s:%s", host, port) token = urllib.parse.quote_plus(pyharmony.ha_get_token(host, port)) except ValueError as err: _LOGGER.warning("%s for remote: %s", err.args[0], name) return False _LOGGER.debug("Received token: %s", token) DEVICES = [HarmonyRemote( config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT), config.get(ATTR_ACTIVITY), harmony_conf_file, token)] add_devices(DEVICES, True) register_services(hass) return True
def start(self): super(PyHarmony, self).start() errors = 0 self.current_activity_isy = False # Setup the Harmony client self.parent.logger.info(self.lpfx + " Initializing Client") self.token = ha_get_token(self.host, self.port) self.client = ha_get_client(self.token, self.host, self.port) self.parent.logger.info(self.lpfx + " Client: " + str(self.client)) self.harmony_config = self.client.get_config() # # Build a FauxMo Herlper for this device? fcnt = 1 if self.spoken_prefix is not None: myfauxmo = {"type": "FauxMo", "name": "FauxMo%s%d" % (self.name, fcnt), "use_spoken": False, "devices": []} for a in self.harmony_config["activity"]: if a["label"] != "PowerOff": # Max of 5 devices per fauxmo seems to work best if len(myfauxmo["devices"]) == 5: self.parent.add_helper(myfauxmo) myfauxmo["devices"] = [] fcnt += 1 myfauxmo["name"] = "FauxMo%s%d" % (self.name, fcnt) # Print the Harmony Activities to the log print("%s Activity: %s Id: %s" % (self.lpfx, a["label"], a["id"])) self.parent.logger.info(self.lpfx + "Activity: %s Id: %s" % (a["label"], a["id"])) # Truncate the activity id to 16 bit integer to use as the port so # we always get the same port number. myfauxmo["devices"].append( { "name": "%s %s" % (self.spoken_prefix, a["label"]), "type": "PyHarmony", "port": 0xFFFF & int(a["id"]), "type_name": self.name, "command": "activity", "on_event": a["id"], "off_event": -1, } ) self.parent.add_helper(myfauxmo) # Intialize our isy variables if self.set_current_activity(): # Subscribe to changes of the isy variable self.handler = self.current_activity_isy.val.subscribe("changed", partial(self.current_activity_changed)) self.parent.sched.add_job(self.set_current_activity, "cron", second="15,45") else: errors += 1 if errors > 0: raise ValueError("See Log")
def _get_client(self): self.l_info("get_client", "Initializing PyHarmony Client") try: self.token = ha_get_token(self.host, self.port) except: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = ''.join( format_exception(exc_type, exc_value, exc_traceback)) self.l_error("get_client", err_str) self._set_st(0) return False self.l_info("get_client", "PyHarmony token= " + str(self.token)) try: self.client = ha_get_client(self.token, self.host, self.port) except: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = ''.join( format_exception(exc_type, exc_value, exc_traceback)) self.l_error("get_client", err_str) self._set_st(0) return False self._set_st(1) self.l_info("get_client", "PyHarmony client= " + str(self.client)) return True
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Harmony platform.""" import pyharmony host = None activity = None if CONF_DEVICE_CACHE not in hass.data: hass.data[CONF_DEVICE_CACHE] = [] if discovery_info: # Find the discovered device in the list of user configurations override = next((c for c in hass.data[CONF_DEVICE_CACHE] if c.get(CONF_NAME) == discovery_info.get(CONF_NAME)), False) port = DEFAULT_PORT if override: activity = override.get(ATTR_ACTIVITY) port = override.get(CONF_PORT, DEFAULT_PORT) host = (discovery_info.get(CONF_NAME), discovery_info.get(CONF_HOST), port) # Ignore hub name when checking if this hub is known - ip and port only if host and host[1:] in (h.host for h in DEVICES): _LOGGER.debug("Discovered host already known: %s", host) return elif CONF_HOST in config: host = ( config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT), ) activity = config.get(ATTR_ACTIVITY) else: hass.data[CONF_DEVICE_CACHE].append(config) return name, address, port = host _LOGGER.info("Loading Harmony Platform: %s at %s:%s, startup activity: %s", name, address, port, activity) try: _LOGGER.debug("Calling pyharmony.ha_get_token for remote at: %s:%s", address, port) token = urllib.parse.quote_plus(pyharmony.ha_get_token(address, port)) _LOGGER.debug("Received token: %s", token) except ValueError as err: _LOGGER.warning("%s for remote: %s", err.args[0], name) return False harmony_conf_file = hass.config.path('{}{}{}'.format( 'harmony_', slugify(name), '.conf')) device = HarmonyRemote(name, address, port, activity, harmony_conf_file, token) DEVICES.append(device) add_devices([device]) register_services(hass) return True
def harmony_hub_client(host, port=5222): token = ha_get_token(host, port) client = ha_get_client(token, host, port) return client
def start(self): super(PyHarmony, self).start() errors = 0 self.current_activity_isy = False # Setup the Harmony client self.parent.logger.info(self.lpfx + " Initializing Client") self.token = ha_get_token(self.host, self.port) self.client = ha_get_client(self.token, self.host, self.port) self.parent.logger.info(self.lpfx + " Client: " + str(self.client)) self.harmony_config = self.client.get_config() # # Build a FauxMo Herlper for this device? fcnt = 1 if self.spoken_prefix is not None: myfauxmo = { 'type': "FauxMo", 'name': "FauxMo%s%d" % (self.name, fcnt), 'use_spoken': False, 'devices': [] } for a in self.harmony_config['activity']: if a['label'] != 'PowerOff': # Max of 5 devices per fauxmo seems to work best if len(myfauxmo['devices']) == 5: self.parent.add_helper(myfauxmo) myfauxmo['devices'] = [] fcnt += 1 myfauxmo['name'] = "FauxMo%s%d" % (self.name, fcnt) # Print the Harmony Activities to the log print("%s Activity: %s Id: %s" % (self.lpfx, a['label'], a['id'])) self.parent.logger.info(self.lpfx + "Activity: %s Id: %s" % (a['label'], a['id'])) # Truncate the activity id to 16 bit integer to use as the port so # we always get the same port number. myfauxmo['devices'].append({ 'name': "%s %s" % (self.spoken_prefix, a['label']), 'type': 'PyHarmony', 'port': 0xFFFF & int(a['id']), 'type_name': self.name, 'command': 'activity', 'on_event': a['id'], 'off_event': -1, }) self.parent.add_helper(myfauxmo) # Intialize our isy variables if self.set_current_activity(): # Subscribe to changes of the isy variable self.handler = self.current_activity_isy.val.subscribe( 'changed', partial(self.current_activity_changed)) self.parent.sched.add_job(self.set_current_activity, 'cron', second='15,45') else: errors += 1 if errors > 0: raise ValueError("See Log")