def start(self): super(PyHue, self).start() errors = 0 for device in self.pdevices: try: self.add_device(device) except ValueError as e: self.parent.logger.error(str(e)) errors += 1 lpfx = self.lpfx + 'auto_add_isy:' for child in self.parent.isy.nodes.allLowerNodes: if child[0] is 'node' or child[0] is 'group': self.parent.logger.info(child) mnode = self.parent.isy.nodes[child[2]] spoken = mnode.spoken if spoken is not None: # TODO: Should this be a comman seperate list of which echo will respond? # TODO: Or should that be part of notes? if spoken == '1': spoken = mnode.name self.parent.logger.info(lpfx + "add_spoken_device: name=" + mnode.name + ", spoken=" + str(spoken)) cnode = False if child[0] is 'node': # Is it a controller of a scene? cgroup = mnode.get_groups(responder=False) if len(cgroup) > 0: cnode = self.parent.isy.nodes[cgroup[0]] self.parent.logger.info(lpfx + " is a scene controller of " + str(cgroup[0]) + '=' + str(cnode) + ' "' + cnode.name + '"') else: cnode = mnode if len(mnode.controllers) > 0: mnode = self.parent.isy.nodes[mnode.controllers[0]] self.pdevices.append(pyhue_isy_node_handler(self,spoken,mnode,cnode)) for var in self.parent.isy.variables.children: # var is a tuple of type, name, number # TODO: Use ([^\/]+) instead of (.*) ? match_obj = re.match( r'.*\.Spoken\.(.*)', var[1], re.I) if match_obj: var_obj = self.parent.isy.variables[var[0]][var[2]] self.pdevices.append(pyhue_isy_var_handler(self,match_obj.group(1),var)) #errors += 1 if errors > 0: raise ValueError("See Log") hueUpnp_config.devices = self.pdevices hueUpnp_config.logger = self.parent.logger if self.host is None: hueUpnp_config.standard['IP'] = self.parent.config['this_host']['host'] else: hueUpnp_config.standard['IP'] = self.host hueUpnp_config.standard['HTTP_PORT'] = self.http_port hueUpnp_config.standard['DEBUG'] = True self.hue_upnp = hue_upnp(hueUpnp_config) self.parent.sched.add_job(partial(self.hue_upnp.run,0), misfire_grace_time=360, id=self.name)
def connect(self, listen): done = False cnt = 0 while (not done): cnt += 1 self.l_debug('connect', 'ISY connect try {}'.format(cnt)) try: self.isy = pyisy.ISY(self.isy_host, self.isy_port, self.isy_user, self.isy_password, False, 1.1, LOGGER) done = True except Exception as ex: # Can any other exception happen? template = "An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) self.l_error('connect', message, exc_info=True) self.l_info('connect', ' ISY Connected: ' + str(self.isy.connected)) if not self.isy.connected: if cnt == 10: self.l_error('connect', 'Tried to connect 10 times, giving up') done = True else: self.l_error('connect', 'ISY not connected, will try again') if not self.isy.connected: return False # Now that we are all setup, we can accept device changes from the isy. # FIXME: But this means from the time we connect till now, we can miss # FIXME: device status changes, do we care? self.isy.auto_update = True if not self.refresh(): return False # # Now start up the hue_upnp... # self.l_info('connect', 'Default config: {}'.format(hueUpnp_config)) hueUpnp_config.devices = self.pdevices hueUpnp_config.logger = LOGGER hueUpnp_config.standard['IP'] = self.host hueUpnp_config.standard['PORT'] = self.port hueUpnp_config.standard['DEBUG'] = True self.hue_upnp = hue_upnp(hueUpnp_config) self.listening = listen self.hue_upnp.run(listen=listen)
def connect(self): # FIXME: How to set different logger level for Events? self.isy = PyISY.ISY(self.isy_host, self.isy_port, self.isy_user, self.isy_password, False, "1.1", LOGGER) self.l_info('connect', ' ISY Connected: ' + str(self.isy.connected)) if not self.isy.connected: return False if not self.refresh(): return False self.l_info('connect', 'Default config: {}'.format(hueUpnp_config)) hueUpnp_config.devices = self.pdevices hueUpnp_config.logger = LOGGER hueUpnp_config.standard['IP'] = self.host hueUpnp_config.standard['PORT'] = self.port hueUpnp_config.standard['DEBUG'] = True self.hue_upnp = hue_upnp(hueUpnp_config) self.hue_upnp.run() self.listening = True
def start(self): super(PyHue, self).start() errors = 0 for device in self.pdevices: try: self.add_device(device) except ValueError as e: self.parent.logger.error(str(e)) errors += 1 lpfx = self.lpfx + 'auto_add_isy:' for child in self.parent.isy.nodes.allLowerNodes: if child[0] is 'node' or child[0] is 'group': self.parent.logger.info(child) mnode = self.parent.isy.nodes[child[2]] spoken = mnode.spoken if spoken is not None: # TODO: Should this be a comman seperate list of which echo will respond? # TODO: Or should that be part of notes? if spoken == '1': spoken = mnode.name self.parent.logger.info(lpfx + "add_spoken_device: name=" + mnode.name + ", spoken=" + str(spoken)) cnode = False if child[0] is 'node': # Is it a controller of a scene? cgroup = mnode.get_groups(responder=False) if len(cgroup) > 0: cnode = self.parent.isy.nodes[cgroup[0]] self.parent.logger.info( lpfx + " is a scene controller of " + str(cgroup[0]) + '=' + str(cnode) + ' "' + cnode.name + '"') else: cnode = mnode if len(mnode.controllers) > 0: mnode = self.parent.isy.nodes[mnode.controllers[0]] self.pdevices.append( pyhue_isy_node_handler(self, spoken, mnode, cnode)) for var in self.parent.isy.variables.children: # var is a tuple of type, name, number # TODO: Use ([^\/]+) instead of (.*) ? match_obj = re.match(r'.*\.Spoken\.(.*)', var[1], re.I) if match_obj: var_obj = self.parent.isy.variables[var[0]][var[2]] self.pdevices.append( pyhue_isy_var_handler(self, match_obj.group(1), var)) #errors += 1 if errors > 0: raise ValueError("See Log") hueUpnp_config.devices = self.pdevices hueUpnp_config.logger = self.parent.logger if self.host is None: hueUpnp_config.standard['IP'] = self.parent.config['this_host'][ 'host'] else: hueUpnp_config.standard['IP'] = self.host hueUpnp_config.standard['HTTP_PORT'] = self.http_port hueUpnp_config.standard['DEBUG'] = True self.hue_upnp = hue_upnp(hueUpnp_config) self.parent.sched.add_job(partial(self.hue_upnp.run, 0), misfire_grace_time=360, id=self.name)