def add_activity(self, number, name): node = self.parent.addNode( HarmonyActivity(self, number, get_valid_node_name(name))) self.activity_nodes[number] = node return node
def _discover(self): # Clear the hubs now so we clear some that may have been improperly added. self.clear_hubs() # # Look for the hubs... # self.setDriver('GV7', 2) auto_discover = self.getDriver('GV8') if auto_discover is None: auto_discover = 1 else: auto_discover = int(auto_discover) if (auto_discover == 0): self.l_info( 'discover', 'harmony_discover: skipping since auto discover={0}...'.format( auto_discover)) discover_result = list() else: self.l_info('discover', 'harmony_discover: starting...') from pyharmony import discovery as harmony_discovery harmony_discovery.logger = LOGGER try: discover_result = harmony_discovery.discover(scan_attempts=10, scan_interval=1) except (OSError) as err: self.setDriver('GV7', 9) self.l_error( 'discover', 'pyharmony discover failed. May need to restart this nodeserver: {}' .format(err)) return self.l_info('discover', 'harmony_discover: {0}'.format(discover_result)) # # Add the nodes # self.setDriver('GV7', 3) # # First from customParams. # for param in self.polyConfig['customParams']: # Look for customParam starting with hub_ match = re.match("hub_(.*)", param, re.I) if match is not None: # The hub address is everything following the hub_ address = match.group(1) self.l_info('discover', 'got param {0} address={1}'.format(param, address)) # Get the customParam value which is json code # { "name": "HarmonyHub FamilyRoom", "host": "192.168.1.86" } cfg = self.polyConfig['customParams'][param] try: cfgd = json.loads(cfg) except: err = sys.exc_info()[0] self.l_error( 'discover', 'failed to parse cfg={0} Error: {1}'.format(cfg, err)) # Check that name and host are defined. addit = True if not 'name' in cfgd: self.l_error( 'discover', 'No name in customParam {0} value={1}'.format( param, cfg)) addit = False if not 'host' in cfgd: self.l_error( 'discover', 'No host in customParam {0} value={1}'.format( param, cfg)) addit = False if addit: self.hubs.append({ 'address': address, 'name': get_valid_node_name(cfgd['name']), 'host': cfgd['host'], 'port': 5222 }) # # Next the discovered ones # for config in discover_result: addit = True if 'current_fw_version' in config: if config['current_fw_version'] == '4.15.206': self.l_error( 'discover', 'current_fw_version={} which is not supported. See: {}' .format( config['current_fw_version'], 'https://community.logitech.com/s/question/0D55A00008D4bZ4SAJ/harmony-hub-firmware-update-fixes-vulnerabilities' )) addit = False else: self.l_error( 'discover', 'current_fw_version not in config? Will try to use anyway {}' .format(config)) if addit: self.hubs.append({ 'address': 'h' + id_to_address(config['uuid'], 13), 'name': get_valid_node_name(config['friendlyName']), 'host': config['ip'], 'port': config['port'], 'save': True }) # # Build the profile # It needs the hub_list set, so we will reset it later. if self._build_profile(): # # Now really add them. hl = self.hubs self.clear_hubs() for cnode in hl: self.add_hub(cnode['address'], cnode['name'], cnode['host'], cnode['port']) self.save_hubs()
def add_device(self, number, name): # TODO: Pass in name and address as optional args. node = self.parent.addNode( HarmonyDevice(self, number, get_valid_node_name(name))) self.device_nodes[number] = node return node