parameters: (self, level, wait_period=60)
docstring: Enables charging and waits for device to be charged to given level.
  
      Args:
        level: level of charge to wait for.
        wait_period: time in seconds to wait between checking.
      Raises:
        device_errors.DeviceChargingError: If error while charging is detected.
docstring_summary: Enables charging and waits for device to be charged to given level.
docstring_tokens: Enables charging and waits for device to be charged to given level .
function: def ChargeDeviceToLevel(self, level, wait_period=60):
      """Enables charging and waits for device to be charged to given level.
  
      Args:
        level: level of charge to wait for.
        wait_period: time in seconds to wait between checking.
      Raises:
        device_errors.DeviceChargingError: If error while charging is detected.
      """
      self.SetCharging(True)
      charge_status = {
          'charge_failure_count': 0,
          'last_charge_value': 0
      }
      def device_charged():
        battery_level = self.GetBatteryInfo().get('level')
        if battery_level is None:
          logging.warning('Unable to find current battery level.')
          battery_level = 100
        else:
          logging.info('current battery level: %s', battery_level)
          battery_level = int(battery_level)
  
        # Use > so that it will not reset if charge is going down.
        if battery_level > charge_status['last_charge_value']:
          charge_status['last_charge_value'] = battery_level
          charge_status['charge_failure_count'] = 0
        else:
          charge_status['charge_failure_count'] += 1
  
        if (not battery_level >= level
            and charge_status['charge_failure_count'] >= _MAX_CHARGE_ERROR):
          raise device_errors.DeviceChargingError(
              'Device not charging properly. Current level:%s Previous level:%s'
               % (battery_level, charge_status['last_charge_value']))
        return battery_level >= level
  
      timeout_retry.WaitFor(device_charged, wait_period=wait_period)
function_tokens: def ChargeDeviceToLevel ( self , level , wait_period = 60 ) : self . SetCharging ( True ) charge_status = { 'charge_failure_count' : 0 , 'last_charge_value' : 0 } def device_charged ( ) : battery_level = self . GetBatteryInfo ( ) . get ( 'level' ) if battery_level is None : logging . warning ( 'Unable to find current battery level.' ) battery_level = 100 else : logging . info ( 'current battery level: %s' , battery_level ) battery_level = int ( battery_level ) # Use > so that it will not reset if charge is going down. if battery_level > charge_status [ 'last_charge_value' ] : charge_status [ 'last_charge_value' ] = battery_level charge_status [ 'charge_failure_count' ] = 0 else : charge_status [ 'charge_failure_count' ] += 1 if ( not battery_level >= level and charge_status [ 'charge_failure_count' ] >= _MAX_CHARGE_ERROR ) : raise device_errors . DeviceChargingError ( 'Device not charging properly. Current level:%s Previous level:%s' % ( battery_level , charge_status [ 'last_charge_value' ] ) ) return battery_level >= level timeout_retry . WaitFor ( device_charged , wait_period = wait_period )