def battery_icon(self): """Return the battery icon for the vacuum cleaner.""" charging = False if self.status is not None: charging = 'charg' in self.status.lower() return icon_for_battery_level( battery_level=self.battery_level, charging=charging)
def battery_icon(self): """Return the battery icon for the vacuum cleaner.""" if self.supported_features & SUPPORT_BATTERY == 0: return return icon_for_battery_level( battery_level=self.battery_level, charging=self._charging)
def battery_icon(self): """Return the battery icon for the vacuum cleaner.""" charging = False if self.status is not None: charging = 'charg' in self.status.lower() return icon_for_battery_level(battery_level=self.battery_level, charging=charging)
def icon(self): """Icon to use in the frontend, if any.""" if self.resource_type == 'devices/battery' and self.extra: battery_level = BATTERY_LEVELS[self.extra.get('battery')] return icon_for_battery_level(battery_level=battery_level, charging=None) return 'mdi:{}'.format(FITBIT_RESOURCES_LIST[self.resource_type][2])
def battery_icon(self): """Return the battery icon for the vacuum cleaner.""" from libpurecoollink.const import Dyson360EyeMode charging = self._device.state.state in [ Dyson360EyeMode.INACTIVE_CHARGING] return icon_for_battery_level( battery_level=self.battery_level, charging=charging)
def test_battery_icon(self): """Test icon generator for battery sensor.""" from homeassistant.util.icon import icon_for_battery_level self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, True)) self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, False)) self.assertEqual('mdi:battery-outline', icon_for_battery_level(5, True)) self.assertEqual('mdi:battery-outline', icon_for_battery_level(5, False)) self.assertEqual('mdi:battery-charging-100', icon_for_battery_level(100, True)) self.assertEqual('mdi:battery', icon_for_battery_level(100, False)) iconbase = 'mdi:battery' for level in range(0, 100, 5): print('Level: %d. icon: %s, charging: %s' % (level, icon_for_battery_level(level, False), icon_for_battery_level(level, True))) if level <= 10: postfix_charging = '-outline' elif level <= 30: postfix_charging = '-charging-20' elif level <= 50: postfix_charging = '-charging-40' elif level <= 70: postfix_charging = '-charging-60' elif level <= 90: postfix_charging = '-charging-80' else: postfix_charging = '-charging-100' if 5 < level < 95: postfix = '-{}'.format(int(round(level / 10 - .01)) * 10) elif level <= 5: postfix = '-outline' else: postfix = '' self.assertEqual(iconbase + postfix, icon_for_battery_level(level, False)) self.assertEqual(iconbase + postfix_charging, icon_for_battery_level(level, True))
def test_battery_icon(self): """Test icon generator for battery sensor.""" from homeassistant.util.icon import icon_for_battery_level self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, True)) self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, False)) self.assertEqual('mdi:battery-outline', icon_for_battery_level(5, True)) self.assertEqual('mdi:battery-outline', icon_for_battery_level(5, False)) self.assertEqual('mdi:battery-charging-100', icon_for_battery_level(100, True)) self.assertEqual('mdi:battery', icon_for_battery_level(100, False)) iconbase = 'mdi:battery' for level in range(0, 100, 5): print('Level: %d. icon: %s, charging: %s' % (level, icon_for_battery_level( level, False), icon_for_battery_level(level, True))) if level <= 10: postfix_charging = '-outline' elif level <= 30: postfix_charging = '-charging-20' elif level <= 50: postfix_charging = '-charging-40' elif level <= 70: postfix_charging = '-charging-60' elif level <= 90: postfix_charging = '-charging-80' else: postfix_charging = '-charging-100' if 5 < level < 95: postfix = '-{}'.format(int(round(level / 10 - .01)) * 10) elif level <= 5: postfix = '-outline' else: postfix = '' self.assertEqual(iconbase + postfix, icon_for_battery_level(level, False)) self.assertEqual(iconbase + postfix_charging, icon_for_battery_level(level, True))
def icon(self): """Return the icon to use in the frontend, if any.""" device_battery = self._device[ios.ATTR_BATTERY] battery_state = device_battery[ios.ATTR_BATTERY_STATE] battery_level = device_battery[ios.ATTR_BATTERY_LEVEL] charging = True icon_state = DEFAULT_ICON_STATE if (battery_state == ios.ATTR_BATTERY_STATE_FULL or battery_state == ios.ATTR_BATTERY_STATE_UNPLUGGED): charging = False icon_state = "{}-off".format(DEFAULT_ICON_STATE) elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN: battery_level = None charging = False icon_state = "{}-unknown".format(DEFAULT_ICON_LEVEL) if self.type == "state": return icon_state return icon_for_battery_level(battery_level=battery_level, charging=charging)
def icon(self): """Icon to use in the frontend, if any.""" if self._sensor_type == 'battery' and self._state is not None: return icon_for_battery_level(battery_level=int(self._state), charging=False) return ICON_MAP.get(self._sensor_type)