Skip to content

Make light polling and transition cleanup idempotent - #692

Open
dmulcahey wants to merge 1 commit into
devfrom
pr/fix-light-polling-transition-idempotency
Open

Make light polling and transition cleanup idempotent#692
dmulcahey wants to merge 1 commit into
devfrom
pr/fix-light-polling-transition-idempotency

Conversation

@dmulcahey

@dmulcahey dmulcahey commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Repeatedly enabling a light starts another refresh task and loses the handle used by disable(). Transition cleanup also clears _transition_listener before trying to remove that handle from _tracked_handles, retaining cancelled timers.

Keep the active polling task, discard a completed task before replacement, and remove the original transition handle before clearing it. Regression tests cover repeated enable/disable, completed-task replacement, and timer unsubscription.

Validation against dev at 66603431339afe37fa0048b70ff31d77dceb8f95: Python 3.12 full suite, 1385 passed, coverage above the 95% project gate; full pre-commit (codespell, Ruff, formatting, mypy, lock check) passed. Relevant regression checks fail on the unchanged base. GitHub CI for Python 3.12/3.13/3.14 is reported separately on the PR.

@dmulcahey
dmulcahey force-pushed the pr/fix-light-polling-transition-idempotency branch from a6f223e to cb6dd2f Compare February 27, 2026 16:04
@dmulcahey
dmulcahey changed the base branch from dm/codex-issue-exploration to dev February 27, 2026 16:04
@dmulcahey dmulcahey closed this Feb 27, 2026
@dmulcahey dmulcahey reopened this Feb 27, 2026
@codecov

codecov Bot commented Feb 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.19%. Comparing base (6660343) to head (d1aa5c3).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #692   +/-   ##
=======================================
  Coverage   97.19%   97.19%           
=======================================
  Files          57       57           
  Lines       10560    10567    +7     
=======================================
+ Hits        10264    10271    +7     
  Misses        296      296           

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

@dmulcahey
dmulcahey force-pushed the pr/fix-light-polling-transition-idempotency branch from cbdd2f8 to d1aa5c3 Compare September 5, 2026 19:07
Copilot AI lite review requested due to automatic review settings September 5, 2026 19:07
@dmulcahey dmulcahey changed the title Make light polling and transition listener cleanup idempotent Make light polling and transition cleanup idempotent Sep 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Changes are narrowly scoped, address the described resource-tracking bugs directly, and are backed by targeted regression tests.

Pull request overview

This PR fixes idempotency issues in the light platform’s background refresh polling and transition timer cleanup, preventing orphaned tasks/handles when enabling/disabling lights repeatedly and ensuring tracked resources are correctly removed.

Changes:

  • Make start_polling() idempotent by reusing an active refresh task and removing completed tasks from _tracked_tasks before replacement.
  • Fix transition listener cleanup by removing the original timer handle from _tracked_handles before clearing _transition_listener.
  • Add regression tests covering repeated enable/disable, completed-task replacement, and transition timer unsubscription.
File summaries
File Description
zha/application/platforms/light/__init__.py Ensures refresh polling tasks and transition timer handles are cleaned up deterministically and don’t become orphaned on repeated operations.
tests/test_light.py Adds regression coverage for repeated enable/disable behavior and correct task/handle tracking cleanup.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants