From 07fcf22aebca2f579056caecf4a63dbfbb963bdb Mon Sep 17 00:00:00 2001 From: Nikolas Beutler Date: Sat, 22 Apr 2017 05:16:59 +0200 Subject: [PATCH] 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 --- homeassistant/components/sensor/ios.py | 42 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/sensor/ios.py b/homeassistant/components/sensor/ios.py index 35f03d7a1c1..3173eec4285 100644 --- a/homeassistant/components/sensor/ios.py +++ b/homeassistant/components/sensor/ios.py @@ -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, - str(rounded_level)) + 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."""