Repository navigation
Fix fan group actions raising AttributeError - #1053
Open
zigpy-review-bot wants to merge 1 commit into
Open
zigpy-review-bot wants to merge 1 commit into
zigpy-review-bot wants to merge 1 commit into
Conversation
A fan group writes `fan_mode` to the group's multicast cluster. Since zigpy's `write_attributes` started updating the attribute cache and emitting `AttributeWrittenEvent` after every write, it reads `endpoint.device.ieee` there, and a group has none: every fan group action (turn on/off, set percentage, set preset) raised AttributeError after the multicast had been sent. A multicast write gets no reply from the members and nothing reads the group cluster's attribute cache (the group state follows the members' own fan mode), so write with `update_cache=False` and don't check the synthesized default response's status.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1053 +/- ##
=======================================
Coverage 97.48% 97.48%
=======================================
Files 61 61
Lines 10870 10870
=======================================
Hits 10597 10597
Misses 273 273 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Severity: medium (the audit's estimate)
Every ZHA fan group action (turn on, turn off, set percentage, set preset) raises
AttributeError: 'Group' object has no attribute 'ieee'after the multicast write was sent. zigpy'sCluster.write_attributesupdates the attribute cache and emits anAttributeWrittenEventafter a write (since zigpy/zigpy#1719), and that event readsendpoint.device.ieee, which a zigpyGroupdoesn't have. Behind that, the synthesized default response of a multicast is read with the wrong status (zigpy/zigpy#1767), sowrite_attributes_safewould raise next.This makes the fan group write the group cluster with
update_cache=Falseand without a per-attribute status check: a multicast gets no reply from the members, and nothing reads the group cluster's attribute cache (the group state follows the members' own fan mode).Changes
FanGroup._async_set_fan_modewritesfan_modewithself._cluster.write_attributes(…, update_cache=False)instead ofwrite_attributes_safe. A send failure still raises from the send.test_zha_group_fan_entity_unmocked_write: a two-member fan group with onlysend_packetmocked, so zigpy's real write path runs; it sets a percentage, a preset and turns the group off, and checks the three multicast Write Attributes frames (group address, Fan cluster,fan_modevalue).Testing
test_zha_group_fan_entity_unmocked_writefails at 2da1a5b with theAttributeErrorabove and passes with the fix.tests/test_fan.py: all 35 tests pass; pre-commit (codespell, ruff, mypy) passes on the changed files.Opened by the scheduled code audit; not requested by a maintainer.
Fixes #1052