From 6c4926b1e291bff507ae9e460fcfa968a9e9e239 Mon Sep 17 00:00:00 2001 From: abmantis Date: Sun, 19 Jan 2025 23:38:20 +0000 Subject: [PATCH] Separate polling attributes in homeautomation cluster As suggested in https://github.com/zigpy/zha/pull/339#issuecomment-2599403130 this adds an `ZCL_POLLING_ATTRS` to define attributes that should be polled separatelly from the ones that can have reporting config. This also moves some attributes that do no support reporting config out of `REPORT_CONFIG`. --- tests/test_cluster_handlers.py | 5 --- zha/zigbee/cluster_handlers/homeautomation.py | 32 ++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/test_cluster_handlers.py b/tests/test_cluster_handlers.py index 7827be9a..5fee3fe2 100644 --- a/tests/test_cluster_handlers.py +++ b/tests/test_cluster_handlers.py @@ -286,18 +286,13 @@ async def poll_control_device_mock(zha_gateway: Gateway) -> Device: 1, { "ac_frequency", - "ac_frequency_max", "active_power", - "active_power_max", "apparent_power", "rms_current", "rms_current_ph_b", "rms_current_ph_c", "rms_current_max", - "rms_current_max_b", - "rms_current_max_c", "rms_voltage", - "rms_voltage_max", }, ), ], diff --git a/zha/zigbee/cluster_handlers/homeautomation.py b/zha/zigbee/cluster_handlers/homeautomation.py index 180ab286..0eadec4b 100644 --- a/zha/zigbee/cluster_handlers/homeautomation.py +++ b/zha/zigbee/cluster_handlers/homeautomation.py @@ -61,6 +61,36 @@ class MeasurementType(enum.IntFlag): POWER_QUALITY_MEASUREMENT = 256 REPORT_CONFIG = ( + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.active_power.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.apparent_power.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.rms_current.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.rms_current_ph_b.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.rms_current_ph_c.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.rms_voltage.name, + config=REPORT_CONFIG_OP, + ), + AttrReportConfig( + attr=ElectricalMeasurement.AttributeDefs.ac_frequency.name, + config=REPORT_CONFIG_OP, + ), + ) + ZCL_POLLING_ATTRS = ( AttrReportConfig( attr=ElectricalMeasurement.AttributeDefs.active_power.name, config=REPORT_CONFIG_OP, @@ -136,7 +166,7 @@ async def async_update(self): # This is a polling cluster handler. Don't allow cache. attrs = [ a["attr"] - for a in self.REPORT_CONFIG + for a in self.ZCL_POLLING_ATTRS if a["attr"] not in self.cluster.unsupported_attributes ] result = await self.get_attributes(attrs, from_cache=False, only_cache=False)