8000 Update ios.py by biacz · Pull Request #7160 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Update ios.py #7160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions homeassistant/components/sensor/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"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):
Expand Down Expand Up @@ -62,7 +63,6 @@ def unique_id(self):
@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):
Expand All @@ -84,28 +84,44 @@ def icon(self):
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."""
Expand Down
0