Fix ZHA electrical measurement sensor initialization (#37915)
* Refactor cached ZHA channel reads. If doing a cached ZCL attribute read, do "only_from_cache" read for battery operated devices only. Mains operated devices will do a network read in case of a cache miss. * Use cached attributes for ZHA electrical measurement * Bump up ZHA zigpy dependency.
This commit is contained in:
1 parent
06bc98a3a2
commit
c0302e6eca
6 files changed
+70
-23
No files matched your search
@@ -245,7 +245,7 @@ class ZigbeeChannel(LogMixin):
|
||||
self._cluster,
|
||||
[attribute],
|
||||
allow_cache=from_cache,
|
||||
only_cache=from_cache,
|
||||
only_cache=from_cache and not self._ch_pool.is_mains_powered,
|
||||
manufacturer=manufacturer,
|
||||
)
|
||||
return result.get(attribute)
|
||||
@@ -260,7 +260,7 @@ class ZigbeeChannel(LogMixin):
|
||||
result, _ = await self.cluster.read_attributes(
|
||||
attributes,
|
||||
allow_cache=from_cache,
|
||||
only_cache=from_cache,
|
||||
only_cache=from_cache and not self._ch_pool.is_mains_powered,
|
||||
manufacturer=manufacturer,
|
||||
)
|
||||
return result
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Optional
|
||||
|
||||
import zigpy.zcl.clusters.homeautomation as homeautomation
|
||||
|
||||
from .. import registries, typing as zha_typing
|
||||
from .. import registries
|
||||
from ..const import (
|
||||
CHANNEL_ELECTRICAL_MEASUREMENT,
|
||||
REPORT_CONFIG_DEFAULT,
|
||||
@@ -51,14 +51,6 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
|
||||
|
||||
REPORT_CONFIG = ({"attr": "active_power", "config": REPORT_CONFIG_DEFAULT},)
|
||||
|
||||
def __init__(
|
||||
self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType
|
||||
) -> None:
|
||||
"""Initialize Metering."""
|
||||
super().__init__(cluster, ch_pool)
|
||||
self._divisor = None
|
||||
self._multiplier = None
|
||||
|
||||
async def async_update(self):
|
||||
"""Retrieve latest state."""
|
||||
self.debug("async_update")
|
||||
@@ -80,7 +72,9 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
|
||||
|
||||
async def fetch_config(self, from_cache):
|
||||
"""Fetch config from device and updates format specifier."""
|
||||
results = await self.get_attributes(
|
||||
|
||||
# prime the cache
|
||||
await self.get_attributes(
|
||||
[
|
||||
"ac_power_divisor",
|
||||
"power_divisor",
|
||||
@@ -89,22 +83,20 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
|
||||
],
|
||||
from_cache=from_cache,
|
||||
)
|
||||
self._divisor = results.get(
|
||||
"ac_power_divisor", results.get("power_divisor", self._divisor)
|
||||
)
|
||||
self._multiplier = results.get(
|
||||
"ac_power_multiplier", results.get("power_multiplier", self._multiplier)
|
||||
)
|
||||
|
||||
@property
|
||||
def divisor(self) -> Optional[int]:
|
||||
"""Return active power divisor."""
|
||||
return self._divisor or 1
|
||||
return self.cluster.get(
|
||||
"ac_power_divisor", self.cluster.get("power_divisor", 1)
|
||||
)
|
||||
|
||||
@property
|
||||
def multiplier(self) -> Optional[int]:
|
||||
"""Return active power divisor."""
|
||||
return self._multiplier or 1
|
||||
return self.cluster.get(
|
||||
"ac_power_multiplier", self.cluster.get("power_multiplier", 1)
|
||||
)
|
||||
|
||||
|
||||
@registries.ZIGBEE_CHANNEL_REGISTRY.register(
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"zha-quirks==0.0.42",
|
||||
"zigpy-cc==0.4.4",
|
||||
"zigpy-deconz==0.9.2",
|
||||
"zigpy==0.22.1",
|
||||
"zigpy==0.22.2",
|
||||
"zigpy-xbee==0.12.1",
|
||||
"zigpy-zigate==0.6.1"
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user