mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Fix ZHA battery level when value is reported via signal (#24371)
* fix battery signal * review comment
This commit is contained in:
parent
7c5da67d74
commit
a79224aba8
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user