mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Update ios.py (#7160)
* Update ios.py as discussed. the part: if battery_state == ios.ATTR_BATTERY_STATE_FULL: returning_icon_level = DEFAULT_ICON_LEVEL kinda screws up the charging icon. i might just miss a logical solution for that though. let me know what you think. it might not be beautiful but i think its an overall improve over the current "double battery" solution * Update ios.py chound fix and full_battery_charge fix * Update ios.py removed new line * Update ios.py * Update ios.py * Update ios.py * Update ios.py * Update ios.py * Update ios.py * merged request from robbie * Update ios.py * Update ios.py * Update ios.py
This commit is contained in:
parent
2d57c6a1c7
commit
07fcf22aeb
@ -14,7 +14,8 @@ SENSOR_TYPES = {
|
||||
"state": ["Battery State", None]
|
||||
}
|
||||
|
||||
DEFAULT_ICON = "mdi:battery"
|
||||
DEFAULT_ICON_LEVEL = "mdi:battery"
|
||||
DEFAULT_ICON_STATE = "mdi:power-plug"
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
@ -62,7 +63,6 @@ class IOSSensor(Entity):
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement this sensor expresses itself in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
@ -84,28 +84,44 @@ class IOSSensor(Entity):
|
||||
battery_state = device_battery[ios.ATTR_BATTERY_STATE]
|
||||
battery_level = device_battery[ios.ATTR_BATTERY_LEVEL]
|
||||
rounded_level = round(battery_level, -1)
|
||||
returning_icon = DEFAULT_ICON
|
||||
returning_icon_level = DEFAULT_ICON_LEVEL
|
||||
if battery_state == ios.ATTR_BATTERY_STATE_FULL:
|
||||
returning_icon = DEFAULT_ICON
|
||||
returning_icon_level = DEFAULT_ICON_LEVEL
|
||||
if battery_state == ios.ATTR_BATTERY_STATE_CHARGING:
|
||||
returning_icon_state = DEFAULT_ICON_STATE
|
||||
else:
|
||||
returning_icon_state = "{}-off".format(DEFAULT_ICON_STATE)
|
||||
elif battery_state == ios.ATTR_BATTERY_STATE_CHARGING:
|
||||
# Why is MDI missing 10, 50, 70?
|
||||
if rounded_level in (20, 30, 40, 60, 80, 90, 100):
|
||||
returning_icon = "{}-charging-{}".format(DEFAULT_ICON,
|
||||
str(rounded_level))
|
||||
returning_icon_level = "{}-charging-{}".format(
|
||||
DEFAULT_ICON_LEVEL, str(rounded_level))
|
||||
returning_icon_state = DEFAULT_ICON_STATE
|
||||
else:
|
||||
returning_icon = "{}-charging".format(DEFAULT_ICON)
|
||||
returning_icon_level = "{}-charging".format(
|
||||
DEFAULT_ICON_LEVEL)
|
||||
returning_icon_state = DEFAULT_ICON_STATE
|
||||
elif battery_state == ios.ATTR_BATTERY_STATE_UNPLUGGED:
|
||||
if rounded_level < 10:
|
||||
returning_icon = "{}-outline".format(DEFAULT_ICON)
|
||||
returning_icon_level = "{}-outline".format(
|
||||
DEFAULT_ICON_LEVEL)
|
||||
returning_icon_state = "{}-off".format(DEFAULT_ICON_STATE)
|
||||
elif battery_level > 95:
|
||||
returning_icon = DEFAULT_ICON
|
||||
returning_icon_state = "{}-off".format(DEFAULT_ICON_STATE)
|
||||
returning_icon_level = "{}-outline".format(
|
||||
DEFAULT_ICON_LEVEL)
|
||||
else:
|
||||
returning_icon = "{}-{}".format(DEFAULT_ICON,
|
||||
returning_icon_level = "{}-{}".format(DEFAULT_ICON_LEVEL,
|
||||
str(rounded_level))
|
||||
returning_icon_state = "{}-off".format(DEFAULT_ICON_STATE)
|
||||
elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN:
|
||||
returning_icon = "{}-unknown".format(DEFAULT_ICON)
|
||||
returning_icon_level = "{}-unknown".format(DEFAULT_ICON_LEVEL)
|
||||
returning_icon_state = "{}-unknown".format(DEFAULT_ICON_LEVEL)
|
||||
|
||||
return returning_icon
|
||||
if self.type == "state":
|
||||
return returning_icon_state
|
||||
else:
|
||||
return returning_icon_level
|
||||
|
||||
def update(self):
|
||||
"""Get the latest state of the sensor."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user