Follow-ups from the #884 review: override discard logging, quirk-provided test config, DEFAULT test fixture

Open
#887 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
backend, testing

Research direction

Start with aggregate_cluster_configs in zha/zigbee/cluster_config.py around line 119, where attr_name and the cluster are available, and compare the aggregate before and after the merge to log discarded overrides; a prototype commit is referenced in the issue. For the test side, DEFAULT in tests/test_cluster_config.py (line 23) should be replaced by asserting configured[em_attrs.active_power] != RELAXED. The QuirkBuilder change is blocked on a zhaquirks release, so leave that for later. Done means the discard is logged and the test no longer pins ZHA's built-in default.

Written by the indexing model from the issue text.

Description

code quality

Tracking the inline review comments from #884 that were deliberately deferred rather than addressed in that PR. Filed at TheJulianJES's request (https://github.com/zigpy/zha/pull/884#discussion_r3919402668). All three still apply on dev at 66603431. The one genuine bug from that review is filed separately.

1. Log when an entity's reporting config is discarded by an override

https://github.com/zigpy/zha/pull/884#discussion_r3910746401

Whether an override wins depends on which entities happened to be discovered, and the discard is otherwise invisible: ClusterConfigureReportingEvent carries only the final result, so "why did this device's voltage reporting get slower after an update" has no answer in a normal ZHA debug log and no way to attribute it to a particular entity.

AggregatedAttrConfig.merge does not know the attribute name, so this wants either the name passed in or the log placed at the aggregate_cluster_configs call site (zha/zigbee/cluster_config.py:119), which already has attr_name and the cluster and can compare the aggregate before and after the merge.

TheJulianJES prototyped it as 66044f4ffbfba5ba8cea487f471448922b515ce5 and left it out of #884.

2. Switch the override test to a real QuirkBuilder-provided config

https://github.com/zigpy/zha/pull/884#discussion_r3910699558

test_cluster_config.py patches ElectricalMeasurementRMSCurrent._server_cluster_config to simulate a device-specific override. TheJulianJES's note: this should become a quirks QuirkBuilder actually providing the override config, which needs the zhaquirks bump, which needs a ZHA release containing #884. Patching internals was accepted as the interim.

3. DEFAULT in test_cluster_config.py silently pins ZHA's built-in active_power config

https://github.com/zigpy/zha/pull/884#discussion_r3910746384

DEFAULT = ReportingConfig(min_interval=5, max_interval=900, reportable_change=1) (tests/test_cluster_config.py:23) is not a free-standing fixture — the final assertion configured[em_attrs.active_power] == DEFAULT only holds because it duplicates what ElectricalMeasurementActivePower._server_cluster_config declares for active_power (zha/application/platforms/sensor/init.py:1074-1079). Still identical on dev.

That reportable_change=1 is exactly what the divisor-aware EM reporting follow-up changes, so this assertion will fail on that PR for a reason unrelated to what the test is about. The test's real subject is that the override did not leak to attributes that did not ask for it, which assert configured[em_attrs.active_power] != RELAXED states without pinning the default.

Low priority — it fails loudly and is a one-line fix — but worth knowing before the divisor-aware change lands.

Dominant language
Python
Stars
96
Forks
84
Avg merge
2d 4h
Merged PRs (30d)
30

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zigpy/zha

All issues in zigpy/zha

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.