Make light polling and transition listener cleanup idempotent#692
Open
Make light polling and transition listener cleanup idempotent#692
Conversation
a6f223e to
cb6dd2f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #692 +/- ##
=======================================
Coverage 97.51% 97.51%
=======================================
Files 62 62
Lines 10949 10956 +7
=======================================
+ Hits 10677 10684 +7
Misses 272 272 ☔ View full report in Codecov by Sentry. 🚀 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.
This pull request introduces several improvements and bug fixes to the polling and transition lifecycle management for ZHA light entities. The changes focus on ensuring that task and handle tracking is robust, preventing resource leaks and stale bookkeeping, especially during repeated enable/disable and transition operations. The update also adds comprehensive tests to validate these behaviors.
Lifecycle and resource management improvements:
start_pollinginzha/application/platforms/light/__init__.pyto ensure that starting polling is idempotent: it does not create duplicate polling tasks, and it properly cleans up completed tasks from_tracked_tasksbefore starting a new one.disableinzha/application/platforms/light/__init__.pyto always remove the refresh task from_tracked_tasksbefore cancelling it, suppressing errors if the task is not present._async_unsub_transition_listenerinzha/application/platforms/light/__init__.pyto correctly remove the transition listener handle from_tracked_handlesby referencing the handle before setting it toNone.Testing and validation:
tests/test_light.pyto verify that enabling a light multiple times does not orphan polling tasks, that completed polling tasks are properly replaced, and that transition listener handles are correctly unsubscribed and removed from tracking.## SummaryMakes light polling start/stop idempotent and fixes transition listener handle cleanup.
Failing tests addressed
tests/test_light.py::test_light_refreshtests/test_light.py::test_light_enable_second_pass_is_idempotent_for_polling_taskstests/test_light.py::test_async_unsub_transition_listener_second_pass_removes_old_handleVerification
pytest(branch-local targeted run): all listed tests pass.