diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index 7afde3e5f78..c1701479a43 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -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.""" diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index ce02bf11d9d..5c51717b161 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -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):