Skip to content

Apply on_off reports buffered during a light transition - #989

Open
zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/light-buffer-on-off-during-transition
Open

zigpy-review-bot wants to merge 2 commits into
devfrom
zigpy-bot/light-buffer-on-off-during-transition

Conversation

@zigpy-review-bot

@zigpy-review-bot zigpy-review-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

While a light's transitioning flag is set, an on_off=False report is buffered (as brightness 0) but an on_off=True report is discarded. If something other than the entity turns the light on within the window of a turn_off (a remote bound to the bulb, or a cluster command sent through zha.issue_zigbee_cluster_command), the entity stays off after the window ends, even though the light is on and its level was buffered.

This buffers the on_off value itself and applies it in async_transition_complete (the last report in the window wins). The brightness buffer now holds brightness only.

Follow-up to #767, which fixed the on/off-only case of #766. This covers the dimmable case reported by jasonmx in #767 (Hue LTA004 log). The change is taken from their branch, so they are credited as co-author.

Changes

  • zha/application/platforms/light/__init__.py: new _transition_on_off_buffer, reset in async_transition_set_flag, filled in handle_attribute_updated for both on and off, applied in async_transition_complete (an applied on also clears _off_with_transition / _off_brightness).
  • tests/test_light.py: test_on_off_report_during_off_transition_is_applied, parametrized for an external turn-on and for on-then-off within the window.

Testing

tests/test_light.py passes (24 tests), pre-commit (ruff, mypy, codespell) passes.

Open items

Two edge cases from the review rounds are left as they were and tracked in #988: group members' buffers are never applied by the group's transition completion (already the case for the brightness buffer), and an on_off=True report followed by a current_level=0 report in the same window now resolves to on (the on_off report wins).

… "on"

While the transitioning flag was set, an on_off=False report was buffered (as
brightness 0) but an on_off=True report was discarded. When something other
than the entity turned the light on within the window of a turn_off (a bound
remote, or a cluster command sent through the ZHA service), the entity stayed
off once the window ended, even with a non-zero level buffered.

Buffer the on_off value itself and apply it in async_transition_complete; the
last report in the window wins. The brightness buffer now holds brightness only.

Co-authored-by: jasonmx <jason@merron.net>
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.58%. Comparing base (c552c7b) to head (1365322).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #989   +/-   ##
=======================================
  Coverage   97.58%   97.58%           
=======================================
  Files          61       61           
  Lines       10870    10878    +8     
=======================================
+ Hits        10607    10615    +8     
  Misses        263      263           

☔ 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.

@TheJulianJES

Copy link
Copy Markdown
Contributor

@zigpy-review-bot Check code coverage. If missing coverage is unrelated to this PR changes, possibly open another (stacked) PR for adding more coverage. Possibly also open (stacked) PR for "open items". Do review rounds.

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator Author

Coverage (full suite on the branch, 1567 tests): 97.6% overall, matching the Codecov report. The one miss that belonged to this PR was the buffered zero-level branch in async_transition_complete, which the old off-report path used to reach. I added a test for it and pushed it here (1365322), so this PR now has 25 light tests rather than the 24 its body states.

The rest of the missing coverage is unrelated to this change. Stacked on top of this PR:

Other gaps I left alone: polling and the property fallbacks in the light platform, plus uncovered lines in discovery, helpers, virtual, decorators and async_.

Review rounds ran on the stack with a Fable reviewer plus Copilot. Both found real problems in #991's first draft (a rising level after a level 0 ended the light off, stale member buffers after a group restart, and a spec-normal off sequence ending on). All were fixed and covered by tests, and the last round came back clean from both. Nothing was left open on #989 itself.

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

Labels

bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants