mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27: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_ATTR_UPDATED,
|
||||||
SIGNAL_MOVE_LEVEL,
|
SIGNAL_MOVE_LEVEL,
|
||||||
SIGNAL_SET_LEVEL,
|
SIGNAL_SET_LEVEL,
|
||||||
|
SIGNAL_STATE_ATTR,
|
||||||
)
|
)
|
||||||
from ..helpers import get_attr_id_by_name
|
from ..helpers import get_attr_id_by_name
|
||||||
|
|
||||||
@ -355,6 +356,14 @@ class PowerConfigurationChannel(ZigbeeChannel):
|
|||||||
async_dispatcher_send(
|
async_dispatcher_send(
|
||||||
self._zha_device.hass, f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}", value
|
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):
|
async def async_initialize(self, from_cache):
|
||||||
"""Initialize channel."""
|
"""Initialize channel."""
|
||||||
|
@ -128,7 +128,7 @@ class Sensor(ZhaEntity):
|
|||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_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(
|
await self.async_accept_signal(
|
||||||
self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
self._channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||||
@ -209,6 +209,12 @@ class Battery(Sensor):
|
|||||||
state_attrs["battery_quantity"] = battery_quantity
|
state_attrs["battery_quantity"] = battery_quantity
|
||||||
return state_attrs
|
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)
|
@STRICT_MATCH(channel_names=CHANNEL_ELECTRICAL_MEASUREMENT)
|
||||||
class ElectricalMeasurement(Sensor):
|
class ElectricalMeasurement(Sensor):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user