Fix ZHA battery level when value is reported via signal (#24371)

* fix battery signal
* review comment
This commit is contained in:
David F. Mulcahey 2019-06-07 11:02:35 -04:00 committed by Alexei Chetroi
parent 7c5da67d74
commit a79224aba8

View File

@ -1,6 +1,7 @@
"""Device entity for Zigbee Home Automation."""
import logging
import numbers
import time
from homeassistant.core import callback
@ -101,6 +102,18 @@ class ZhaDeviceEntity(ZhaEntity):
# only do this on add to HA because it is static
await self._async_init_battery_values()
def async_update_state_attribute(self, key, value):
"""Update a single device state attribute."""
if key == 'battery_level':
if not isinstance(value, numbers.Number) or value == -1:
return
value = value / 2
value = int(round(value))
self._device_state_attributes.update({
key: value
})
self.async_schedule_update_ha_state()
async def async_update(self):
"""Handle polling."""
if self._zha_device.last_seen is None: