original_docstring:  Poll Hue for new lights/existing lights' statuses 
docstring: Poll Hue for new lights/existing lights' statuses
docstring_tokens: Poll Hue for new lights / existing lights ' statuses
code: def _discover(self, hub_idx):
          """ Poll Hue for new lights/existing lights' statuses """
          if self.hub[hub_idx] is None or self.discovery == True:
              return True
          self.discovery = True
          LOGGER.info('Hub {} Starting Hue discovery...'.format(hub_idx))
  
          self.lights[hub_idx] = self._get_lights(hub_idx)
          if not self.lights[hub_idx]:
              LOGGER.error('Hub {} Discover: Failed to read Lights from the Hue Bridge'.format(hub_idx))
              self.discovery = False
              return False
          
          LOGGER.info('Hub {} {} bulbs found. Checking status and adding to ISY if necessary.'.format(hub_idx, len(self.lights[hub_idx])))
  
          for lamp_id, data in self.lights[hub_idx].items():
              address = id_2_addr(data['uniqueid'])
              name = data['name']
              
              if not address in self.nodes:
                  if data['type'] == "Extended color light":
                      LOGGER.info('Hub {} Found Extended Color Bulb: {}({})'.format(hub_idx, name, address))
                      self.addNode(HueEColorLight(self, self.address, address, name, lamp_id, data, hub_idx))
                  elif data['type'] == "Color light":
                      LOGGER.info('Hub {} Found Color Bulb: {}({})'.format(hub_idx, name, address))
                      self.addNode(HueColorLight(self, self.address, address, name, lamp_id, data, hub_idx))
                  elif data['type'] == "Color temperature light":
                      LOGGER.info('Hub {} Found White Ambiance Bulb: {}({})'.format(hub_idx, name, address))
                      self.addNode(HueWhiteLight(self, self.address, address, name, lamp_id, data, hub_idx))
                  elif data['type'] == "Dimmable light":
                      LOGGER.info('Hub {} Found Dimmable Bulb: {}({})'.format(hub_idx, name, address))
                      self.addNode(HueDimmLight(self, self.address, address, name, lamp_id, data, hub_idx))
                  else:
                      LOGGER.info('Hub {} Found Unsupported {} Bulb: {}({})'.format(hub_idx, data['type'], name, address))
  
          self.scenes[hub_idx] = self._get_scenes(hub_idx)
          if not self.scenes[hub_idx]:
              LOGGER.error('Hub {} Discover: Failed to read Scenes from the Hue Bridge'.format(hub_idx))
          
          self.groups[hub_idx] = self._get_groups(hub_idx)
          if not self.groups[hub_idx]:
              LOGGER.error('Hub {} Discover: Failed to read Groups from the Hue Bridge'.format(hub_idx))
              self.discovery = False
              return False
  
          LOGGER.info('Hub {} {} groups found. Checking status and adding to ISY if necessary.'.format(hub_idx, len(self.groups[hub_idx])))
  
          for group_id, data in self.groups[hub_idx].items():
              scene_idx = 0
              if len(self.hub) > 1:
                  address = 'huegrp'+hub_idx.split('.')[-1]+group_id
              else:
                  address = 'huegrp'+group_id
              if group_id == '0':
                  name = 'All Lights'
              else:
                  name = data['name']
              
              if 'lights' in data and len(data['lights']) > 0:
                  if not address in self.nodes:
                      LOGGER.info("Hub {} Found {} {} with {} light(s)".format(hub_idx, data['type'], name, len(data['lights'])))
                      self.addNode(HueGroup(self, self.address, address, name, group_id, data, hub_idx))
                      if self.scenes[hub_idx]:
                          for scene_id, scene_data in self.scenes[hub_idx].items():
                              if 'group' in scene_data:
                                  if scene_data['group'] == group_id:
                                      self.scene_lookup.append({ "hub": hub_idx, "group": int(group_id), "idx": scene_idx, "id": scene_id, "name": scene_data['name']})
                                      LOGGER.info(f"Hub {hub_idx} {data['type']} {name} {scene_data['type']} {scene_idx}:{scene_id}:{scene_data['name']}")
                                      scene_idx += 1
              else:
                  if address in self.nodes:
                      LOGGER.info("Hub {} {} {} does not have any lights in it, removing a node".format(hub_idx, data['type'], name))
                      self.delNode(address)
          
          LOGGER.info('Hub {} Discovery complete'.format(hub_idx))
          self.discovery = False
          return True
code_tokens: def _discover ( self , hub_idx ) : if self . hub [ hub_idx ] is None or self . discovery == True : return True self . discovery = True LOGGER . info ( 'Hub {} Starting Hue discovery...' . format ( hub_idx ) ) self . lights [ hub_idx ] = self . _get_lights ( hub_idx ) if not self . lights [ hub_idx ] : LOGGER . error ( 'Hub {} Discover: Failed to read Lights from the Hue Bridge' . format ( hub_idx ) ) self . discovery = False return False LOGGER . info ( 'Hub {} {} bulbs found. Checking status and adding to ISY if necessary.' . format ( hub_idx , len ( self . lights [ hub_idx ] ) ) ) for lamp_id , data in self . lights [ hub_idx ] . items ( ) : address = id_2_addr ( data [ 'uniqueid' ] ) name = data [ 'name' ] if not address in self . nodes : if data [ 'type' ] == "Extended color light" : LOGGER . info ( 'Hub {} Found Extended Color Bulb: {}({})' . format ( hub_idx , name , address ) ) self . addNode ( HueEColorLight ( self , self . address , address , name , lamp_id , data , hub_idx ) ) elif data [ 'type' ] == "Color light" : LOGGER . info ( 'Hub {} Found Color Bulb: {}({})' . format ( hub_idx , name , address ) ) self . addNode ( HueColorLight ( self , self . address , address , name , lamp_id , data , hub_idx ) ) elif data [ 'type' ] == "Color temperature light" : LOGGER . info ( 'Hub {} Found White Ambiance Bulb: {}({})' . format ( hub_idx , name , address ) ) self . addNode ( HueWhiteLight ( self , self . address , address , name , lamp_id , data , hub_idx ) ) elif data [ 'type' ] == "Dimmable light" : LOGGER . info ( 'Hub {} Found Dimmable Bulb: {}({})' . format ( hub_idx , name , address ) ) self . addNode ( HueDimmLight ( self , self . address , address , name , lamp_id , data , hub_idx ) ) else : LOGGER . info ( 'Hub {} Found Unsupported {} Bulb: {}({})' . format ( hub_idx , data [ 'type' ] , name , address ) ) self . scenes [ hub_idx ] = self . _get_scenes ( hub_idx ) if not self . scenes [ hub_idx ] : LOGGER . error ( 'Hub {} Discover: Failed to read Scenes from the Hue Bridge' . format ( hub_idx ) ) self . groups [ hub_idx ] = self . _get_groups ( hub_idx ) if not self . groups [ hub_idx ] : LOGGER . error ( 'Hub {} Discover: Failed to read Groups from the Hue Bridge' . format ( hub_idx ) ) self . discovery = False return False LOGGER . info ( 'Hub {} {} groups found. Checking status and adding to ISY if necessary.' . format ( hub_idx , len ( self . groups [ hub_idx ] ) ) ) for group_id , data in self . groups [ hub_idx ] . items ( ) : scene_idx = 0 if len ( self . hub ) > 1 : address = 'huegrp' + hub_idx . split ( '.' ) [ - 1 ] + group_id else : address = 'huegrp' + group_id if group_id == '0' : name = 'All Lights' else : name = data [ 'name' ] if 'lights' in data and len ( data [ 'lights' ] ) > 0 : if not address in self . nodes : LOGGER . info ( "Hub {} Found {} {} with {} light(s)" . format ( hub_idx , data [ 'type' ] , name , len ( data [ 'lights' ] ) ) ) self . addNode ( HueGroup ( self , self . address , address , name , group_id , data , hub_idx ) ) if self . scenes [ hub_idx ] : for scene_id , scene_data in self . scenes [ hub_idx ] . items ( ) : if 'group' in scene_data : if scene_data [ 'group' ] == group_id : self . scene_lookup . append ( { "hub" : hub_idx , "group" : int ( group_id ) , "idx" : scene_idx , "id" : scene_id , "name" : scene_data [ 'name' ] } ) LOGGER . info ( f"Hub {hub_idx} {data['type']} {name} {scene_data['type']} {scene_idx}:{scene_id}:{scene_data['name']}" ) scene_idx += 1 else : if address in self . nodes : LOGGER . info ( "Hub {} {} {} does not have any lights in it, removing a node" . format ( hub_idx , data [ 'type' ] , name ) ) self . delNode ( address ) LOGGER . info ( 'Hub {} Discovery complete' . format ( hub_idx ) ) self . discovery = False return True
short_docstring: Poll Hue for new lights/existing lights' statuses
short_docstring_tokens: Poll Hue for new lights / existing lights ' statuses
comment: """ Poll Hue for new lights/existing lights' statuses """