Skip to content

Comments

Fix stuck light transitioning flag after task cancellation#672

Draft
TheJulianJES wants to merge 4 commits intozigpy:devfrom
TheJulianJES:tjj/light_restart_mode_automation_cancelled_error
Draft

Fix stuck light transitioning flag after task cancellation#672
TheJulianJES wants to merge 4 commits intozigpy:devfrom
TheJulianJES:tjj/light_restart_mode_automation_cancelled_error

Conversation

@TheJulianJES
Copy link
Contributor

@TheJulianJES TheJulianJES commented Feb 22, 2026

DRAFT.

The Git diff is horrible to look at, but it's just try/finally being added in those parts and one small guard (59611bf).

AI summary

When a mode: restart automation fires while a light turn-on or turn-off is in progress, Home Assistant cancels the running asyncio task. If that cancellation lands between async_transition_set_flag() and async_transition_start_timer(), the _transitioning_individual flag is left True with no timer to clear it. The light then ignores all incoming attribute reports indefinitely.

  • Wrap the body of async_turn_on and async_turn_off in try/finally blocks. The finally clause calls async_transition_complete() when the flag is stuck (set but no timer running), covering task cancellation and unexpected exceptions.
  • As a side effect, a pre-existing bug is also fixed: when the second move_to_level call in the new_color_provided_while_off path failed, the code returned without calling async_transition_complete() or starting the transition timer — leaving the flag stuck.
    • An explicit guard is now added there, consistent with all other early-return error paths (59611bf).

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 72.64151% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.43%. Comparing base (aa03919) to head (59611bf).

Files with missing lines Patch % Lines
zha/application/platforms/light/__init__.py 72.64% 29 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #672      +/-   ##
==========================================
- Coverage   97.44%   97.43%   -0.02%     
==========================================
  Files          62       62              
  Lines       10731    10740       +9     
==========================================
+ Hits        10457    10464       +7     
- Misses        274      276       +2     

☔ View full report in Codecov by Sentry.
📢 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant