Repository navigation
Don't poll electrical measurement multipliers and divisors - #943
Conversation
Since the cluster handler removal, `AggregatedClusterPoller` polls every attribute that an enabled sibling sensor configures for reporting. The electrical measurement sensors configure reporting for their own multiplier and divisor attributes, so these are now read on every poll, although #348 deliberately left them out of polling. Skip each sensor's own scaling attributes (incl. the `power_multiplier` / `power_divisor` fallbacks) when building the poll list. They are still read at initialization and configured for reporting.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #943 +/- ##
==========================================
- Coverage 97.23% 97.22% -0.01%
==========================================
Files 61 61
Lines 10668 10678 +10
==========================================
+ Hits 10373 10382 +9
- Misses 295 296 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tested this on a large ZHA network with 50 devices being polled for electrical measurements.I was trouble shooting some network performance issues. After applying this PR and restarting HA Core, PTI captures showed approximately 166 → 82 electrical-measurement Read Attributes transactions per minute, a reduction of about 50%. |
Summary
Fixes #942.
#348 set up reporting for the electrical measurement multiplier and divisor attributes and deliberately left them out of polling: they are read on startup, and a device that changes them at runtime reports the new value. Up to #657, the EM cluster handler polled a fixed
ZCL_POLLING_ATTRSlist that never contained them.Since #657,
AggregatedClusterPoller.async_updatebuilds the poll list from every attribute that an enabled sibling sensor configures for reporting. The EM sensors configure reporting for their own multiplier and divisor attributes, so these are now read on every poll (every 30–45 s). On a SONOFF S60 this is 9 attributes per poll instead of 3, which zigpy splits into two Read Attributes requests (at most 5 attributes each) instead of one.Changes
Sensorgets a_scaling_attribute_namesproperty (empty by default).BaseElectricalMeasurementreturns its multiplier and divisor attribute names, including thepower_multiplier/power_divisorfallbacks.AggregatedClusterPoller.async_updateskips each sibling's own scaling attributes when building the poll list.AttrConfigs are untouched, only the poller ignores these attributes. The AC power/current/voltage multipliers and divisors are read fresh on startup, the DC ones with cache allowed (read_on_startup=False).REPORT_CONFIG); since Replace cluster handlers with entity attributes #657 they areread_on_startup=False. This PR leaves that as is, but with polling gone they are now refreshed only at initialization and by reports, the same as the AC ones. Switching them toread_on_startup=Truewould be a one-line follow-up per attribute if wanted.multiplier/divisorhave no reporting config, so they were never polled.Why not a per-attribute flag on
AttrConfig: the scaling attributes are already named on each EM sensor class (the same names the_multiplier/_divisorproperties read). Deriving the skip list from them keeps one source of truth, covers new EM sensors automatically, and avoids adding a flag to the 40 reporting-configured multiplier/divisorAttrConfigentries.Testing
test_em_poller_skips_multiplier_and_divisor_attributes(SONOFF S60 device fixture): AC multipliers/divisors are still read on startup and configured for reporting, and the poll is a single read ofactive_power,rms_current,rms_voltage.test_em_poller_skips_fallback_multiplier_and_divisor_attributes(generic EM mock): the poll includes no multiplier or divisor attribute, including thepower_*fallbacks.devand pass with this change. Full test suite: 1460 passed. pre-commit (codespell, ruff, mypy) passes.Related: #941