Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate polling attributes in electrical measurement cluster #354

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tests/test_cluster_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
),
],
Expand Down
50 changes: 19 additions & 31 deletions zha/zigbee/cluster_handlers/homeautomation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from zha.zigbee.cluster_handlers import AttrReportConfig, ClusterHandler, registries
from zha.zigbee.cluster_handlers.const import (
CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT,
REPORT_CONFIG_DEFAULT,
REPORT_CONFIG_OP,
)

Expand Down Expand Up @@ -65,10 +64,6 @@ class MeasurementType(enum.IntFlag):
attr=ElectricalMeasurement.AttributeDefs.active_power.name,
config=REPORT_CONFIG_OP,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.active_power_max.name,
config=REPORT_CONFIG_DEFAULT,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.apparent_power.name,
config=REPORT_CONFIG_OP,
Expand All @@ -85,35 +80,30 @@ class MeasurementType(enum.IntFlag):
attr=ElectricalMeasurement.AttributeDefs.rms_current_ph_c.name,
config=REPORT_CONFIG_OP,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.rms_current_max.name,
config=REPORT_CONFIG_DEFAULT,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.rms_current_max_ph_b.name,
config=REPORT_CONFIG_DEFAULT,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.rms_current_max_ph_c.name,
config=REPORT_CONFIG_DEFAULT,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.rms_voltage.name,
config=REPORT_CONFIG_OP,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.rms_voltage_max.name,
config=REPORT_CONFIG_DEFAULT,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_frequency.name,
config=REPORT_CONFIG_OP,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_frequency_max.name,
config=REPORT_CONFIG_DEFAULT,
),
)
ZCL_POLLING_ATTRS = {
Copy link
Contributor

@TheJulianJES TheJulianJES Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we might want ZCL_POLLING_ATTRS to be a list instead of a set, so that the attributes are always polled in the same (expected) order. So, just ZCL_POLLING_ATTRS = [...].

Since we don't poll the divider/multiplier here at the moment, this might not matter, but I think it would be better anyways and keep the same order from before when a (sorted) dict was used.

(Since we're not searching for anything in ZCL_POLLING_ATTRS, a list should be fine performance-wise. Might even save a bit on memory if we use a list. Though it's not like that really matters here..)

ElectricalMeasurement.AttributeDefs.ac_frequency.name,
ElectricalMeasurement.AttributeDefs.ac_frequency_max.name,
ElectricalMeasurement.AttributeDefs.active_power.name,
ElectricalMeasurement.AttributeDefs.active_power_max.name,
ElectricalMeasurement.AttributeDefs.apparent_power.name,
ElectricalMeasurement.AttributeDefs.rms_current.name,
ElectricalMeasurement.AttributeDefs.rms_current_max.name,
ElectricalMeasurement.AttributeDefs.rms_current_max_ph_b.name,
ElectricalMeasurement.AttributeDefs.rms_current_max_ph_c.name,
ElectricalMeasurement.AttributeDefs.rms_current_ph_b.name,
ElectricalMeasurement.AttributeDefs.rms_current_ph_c.name,
ElectricalMeasurement.AttributeDefs.rms_voltage.name,
ElectricalMeasurement.AttributeDefs.rms_voltage_max.name,
}
ZCL_INIT_ATTRS = {
ElectricalMeasurement.AttributeDefs.ac_current_divisor.name: True,
ElectricalMeasurement.AttributeDefs.ac_current_multiplier.name: True,
Expand All @@ -134,12 +124,10 @@ async def async_update(self):
self.debug("async_update")

# This is a polling cluster handler. Don't allow cache.
attrs = [
a["attr"]
for a in self.REPORT_CONFIG
if a["attr"] not in self.cluster.unsupported_attributes
]
result = await self.get_attributes(attrs, from_cache=False, only_cache=False)
attrs = self.ZCL_POLLING_ATTRS - self.cluster.unsupported_attributes
result = await self.get_attributes(
list(attrs), from_cache=False, only_cache=False
)
if result:
for attr, value in result.items():
self.attribute_updated(
Expand Down
Loading