Add battery voltage state attribute for ZHA devices (#30901)
* Add battery voltage state attribute for ZHA devices. * Pylint.
This commit is contained in:
1 parent
4d7c8e254b
commit
58520aa733
2 files changed
+16
-1
No files matched your search
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user