Skip to content

Fix fan group actions raising AttributeError - #1053

Open
zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/fix-fan-group-write-attributeerror
Open

zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/fix-fan-group-write-attributeerror

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator

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's Cluster.write_attributes updates the attribute cache and emits an AttributeWrittenEvent after a write (since zigpy/zigpy#1719), and that event reads endpoint.device.ieee, which a zigpy Group doesn't have. Behind that, the synthesized default response of a multicast is read with the wrong status (zigpy/zigpy#1767), so write_attributes_safe would raise next.

This makes the fan group write the group cluster with update_cache=False and 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_mode writes fan_mode with self._cluster.write_attributes(…, update_cache=False) instead of write_attributes_safe. A send failure still raises from the send.
  • New test test_zha_group_fan_entity_unmocked_write: a two-member fan group with only send_packet mocked, 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_mode value).

Testing

  • test_zha_group_fan_entity_unmocked_write fails at 2da1a5b with the AttributeError above 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

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.
@zigpy-review-bot zigpy-review-bot added bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bugfix This PR fixes a bug bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) labels Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (2da1a5b) to head (40ee318).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZHA fan group actions fail with AttributeError: 'Group' object has no attribute 'ieee'

1 participant