Repository navigation
Scope quirk attribute update state to the cluster instance - #1896
Open
zigpy-review-bot wants to merge 3 commits into
Open
zigpy-review-bot wants to merge 3 commits into
zigpy-review-bot wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1896 +/- ##
==========================================
- Coverage 99.51% 99.49% -0.02%
==========================================
Files 61 61
Lines 12733 13129 +396
==========================================
+ Hits 12671 13063 +392
- Misses 62 66 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Draft
2 of 4 tasks
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation correctly scopes transient state and has comprehensive regression coverage; only a minor documentation wording issue remains.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Scopes quirk attribute-update state to individual cluster instances, preventing deferred or forwarded updates from being incorrectly suppressed.
Changes:
- Replaces global context variables with per-cluster tracking.
- Adds coverage for deferred, forwarded, manufacturer-specific, nested, and failing updates.
| File | Description |
|---|---|
zigpy/zcl/__init__.py |
Implements cluster-scoped quirk update tracking. |
tests/test_zcl.py |
Tests isolation, cleanup, and deferred behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Proposed change
While a reported or read attribute is passed through a quirk's
_update_attribute, zigpy suppresses theAttributeUpdatedEventfor that attribute (#1754) and remembers the manufacturer code to look it up with (#1760). Both were context variables, and neither was tied to the cluster instance the attribute belongs to. That made them apply in places they were never meant for:_update_attributeinherit context variables. If such a task or timer updates the same attribute later, the value only ends up in the attribute cache: noAttributeUpdatedEventis emitted, so the update isn't persisted and ZHA isn't notified. This is the "Separate issue" described in Fix IKEA battery percentage being doubled twice after firmware read zha-device-handlers#5397: the IKEA battery quirk reads the firmware version in a background task and then corrects the battery percentage, and HA keeps showing the uncorrected value until something else refreshes the entity or the next battery report arrives.This PR replaces both context variables with a single dict on the cluster instance, mapping the attribute IDs currently being passed through the quirk to their manufacturer codes. It's only filled for the duration of the synchronous
_update_attributecall, so it can't apply to anything running later, and it only applies to the cluster instance that received the attribute._update_attributecalls for that attribute ID on that cluster behave as before.Additional information
AttributeReportedEvent50, thenAttributeUpdatedEvent100)._update_attributeis now treated like any other update the quirk does on its own. It emits anAttributeUpdatedEvent, and the attribute is looked up without the manufacturer code. If the cluster defines several attributes with that ID, a deferred update by integer ID is therefore ambiguous and is stored as a legacy value, where it previously updated the manufacturer-specific attribute by accident. I found no quirk in zha-device-handlers that does this.test_quirk_deferred_attribute_update_emits_event(task and timer, report and read),test_quirk_forwards_attribute_update_to_other_endpoint(report and read) andtest_quirk_manufacturer_code_context_other_cluster(known and unknown attribute) cover the three cases above and fail ondevwithout the fix.test_quirk_attribute_update_nested_and_failingcovers nesting and cleanup after an exception.