mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add battery voltage state attribute for ZHA devices (#30901)
* Add battery voltage state attribute for ZHA devices. * Pylint.
This commit is contained in:
parent
4d7c8e254b
commit
58520aa733
@ -22,6 +22,7 @@ from ..const import (
|
||||
SIGNAL_ATTR_UPDATED,
|
||||
SIGNAL_MOVE_LEVEL,
|
||||
SIGNAL_SET_LEVEL,
|
||||
SIGNAL_STATE_ATTR,
|
||||
)
|
||||
from ..helpers import get_attr_id_by_name
|
||||
|
||||
@ -355,6 +356,14 @@ class PowerConfigurationChannel(ZigbeeChannel):
|
||||
async_dispatcher_send(
|
||||
self._zha_device.hass, f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}", value
|
||||
)
|
||||
return
|
||||
attr_name = self.cluster.attributes.get(attrid, [attrid])[0]
|
||||
async_dispatcher_send(
|
||||
self._zha_device.hass,
|
||||
f"{self.unique_id}_{SIGNAL_STATE_ATTR}",
|
||||
attr_name,
|
||||
value,
|
||||
)
|
||||
|
||||
async def async_initialize(self, from_cache):
|
||||
"""Initialize channel."""
|
||||
|
@ -128,7 +128,7 @@ class Sensor(ZhaEntity):
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when about to be added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
self._device_state_attributes = await self.async_state_attr_provider()
|
||||
self._device_state_attributes.update(await self.async_state_attr_provider())
|
||||
|
||||
await self.async_accept_signal(
|
||||
self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||
@ -209,6 +209,12 @@ class Battery(Sensor):
|
||||
state_attrs["battery_quantity"] = battery_quantity
|
||||
return state_attrs
|
||||
|
||||
def async_update_state_attribute(self, key, value):
|
||||
"""Update a single device state attribute."""
|
||||
if key == "battery_voltage":
|
||||
self._device_state_attributes["voltage"] = f"{round(value/10, 1)}V"
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
||||
@STRICT_MATCH(channel_names=CHANNEL_ELECTRICAL_MEASUREMENT)
|
||||
class ElectricalMeasurement(Sensor):
|
||||
|
Loading…
x
Reference in New Issue
Block a user