Skip to content

Commit

Permalink
Fix ZHA battery when readings produce an unknown value (home-assistan…
Browse files Browse the repository at this point in the history
…t#23854)

* check for unknown readings

* only publish valid readings

* remove unused constant
  • Loading branch information
dmulcahey authored and balloob committed May 14, 2019
1 parent eaf4a75 commit 9b21774
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/zha/device_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ async def async_get_latest_battery_reading(self):
"""Get the latest battery reading from channels cache."""
battery = await self._battery_channel.get_attribute_value(
'battery_percentage_remaining')
if battery is not None:
# per zcl specs battery percent is reported at 200% ¯\_(ツ)_/¯
# per zcl specs battery percent is reported at 200% ¯\_(ツ)_/¯
if battery is not None and battery != -1:
battery = battery / 2
battery = int(round(battery))
self._device_state_attributes['battery_level'] = battery

0 comments on commit 9b21774

Please sign in to comment.