original_docstring:  Update device states based on the found devices. 
docstring: Update device states based on the found devices.
docstring_tokens: Update device states based on the found devices .
code: def update_devices(self, found_devices=None):
          """ Update device states based on the found devices. """
          self.lock.acquire()
  
          found_devices = found_devices or self.device_scanner.scan_devices()
  
          now = datetime.now()
  
          known_dev = self.known_devices
  
          temp_tracking_devices = [device for device in known_dev
                                   if known_dev[device]['track']]
  
          for device in found_devices:
              # Are we tracking this device?
              if device in temp_tracking_devices:
                  temp_tracking_devices.remove(device)
  
                  known_dev[device]['last_seen'] = now
  
                  self.states.set(
                      known_dev[device]['entity_id'], components.STATE_HOME,
                      known_dev[device]['default_state_attr'])
  
          # For all devices we did not find, set state to NH
          # But only if they have been gone for longer then the error time span
          # Because we do not want to have stuff happening when the device does
          # not show up for 1 scan beacuse of reboot etc
          for device in temp_tracking_devices:
              if now - known_dev[device]['last_seen'] > self.error_scanning:
  
                  self.states.set(known_dev[device]['entity_id'],
                                  components.STATE_NOT_HOME,
                                  known_dev[device]['default_state_attr'])
  
          # If we come along any unknown devices we will write them to the
          # known devices file but only if we did not encounter an invalid
          # known devices file
          if not self.invalid_known_devices_file:
  
              known_dev_path = self.path_known_devices_file
  
              unknown_devices = [device for device in found_devices
                                 if device not in known_dev]
  
              if unknown_devices:
                  try:
                      # If file does not exist we will write the header too
                      is_new_file = not os.path.isfile(known_dev_path)
  
                      with open(known_dev_path, 'a') as outp:
                          self.logger.info((
                              "DeviceTracker:Found {} new devices,"
                              " updating {}").format(len(unknown_devices),
                                                     known_dev_path))
  
                          writer = csv.writer(outp)
  
                          if is_new_file:
                              writer.writerow((
                                  "device", "name", "track", "picture"))
  
                          for device in unknown_devices:
                              # See if the device scanner knows the name
                              # else defaults to unknown device
                              name = (self.device_scanner.get_device_name(device)
                                      or "unknown_device")
  
                              writer.writerow((device, name, 0, ""))
                              known_dev[device] = {'name': name,
                                                   'track': False,
                                                   'picture': ""}
  
                  except IOError:
                      self.logger.exception((
                          "DeviceTracker:Error updating {}"
                          "with {} new devices").format(known_dev_path,
                                                        len(unknown_devices)))
  
          self.lock.release()
code_tokens: def update_devices ( self , found_devices = None ) : self . lock . acquire ( ) found_devices = found_devices or self . device_scanner . scan_devices ( ) now = datetime . now ( ) known_dev = self . known_devices temp_tracking_devices = [ device for device in known_dev if known_dev [ device ] [ 'track' ] ] for device in found_devices : if device in temp_tracking_devices : temp_tracking_devices . remove ( device ) known_dev [ device ] [ 'last_seen' ] = now self . states . set ( known_dev [ device ] [ 'entity_id' ] , components . STATE_HOME , known_dev [ device ] [ 'default_state_attr' ] ) for device in temp_tracking_devices : if now - known_dev [ device ] [ 'last_seen' ] > self . error_scanning : self . states . set ( known_dev [ device ] [ 'entity_id' ] , components . STATE_NOT_HOME , known_dev [ device ] [ 'default_state_attr' ] ) if not self . invalid_known_devices_file : known_dev_path = self . path_known_devices_file unknown_devices = [ device for device in found_devices if device not in known_dev ] if unknown_devices : try : is_new_file = not os . path . isfile ( known_dev_path ) with open ( known_dev_path , 'a' ) as outp : self . logger . info ( ( "DeviceTracker:Found {} new devices," " updating {}" ) . format ( len ( unknown_devices ) , known_dev_path ) ) writer = csv . writer ( outp ) if is_new_file : writer . writerow ( ( "device" , "name" , "track" , "picture" ) ) for device in unknown_devices : name = ( self . device_scanner . get_device_name ( device ) or "unknown_device" ) writer . writerow ( ( device , name , 0 , "" ) ) known_dev [ device ] = { 'name' : name , 'track' : False , 'picture' : "" } except IOError : self . logger . exception ( ( "DeviceTracker:Error updating {}" "with {} new devices" ) . format ( known_dev_path , len ( unknown_devices ) ) ) self . lock . release ( )
short_docstring: Update device states based on the found devices.
short_docstring_tokens: Update device states based on the found devices .
comment: """ Update device states based on the found devices. """$SEP$# Are we tracking this device?$SEP$# For all devices we did not find, set state to NH$SEP$# But only if they have been gone for longer then the error time span$SEP$# Because we do not want to have stuff happening when the device does$SEP$# not show up for 1 scan beacuse of reboot etc$SEP$# If we come along any unknown devices we will write them to the$SEP$# known devices file but only if we did not encounter an invalid$SEP$# known devices file$SEP$# If file does not exist we will write the header too$SEP$# See if the device scanner knows the name$SEP$# else defaults to unknown device