Prevent duplicate poll tasks in pollable sensors#693
Open
Conversation
16b7900 to
db67e88
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #693 +/- ##
=======================================
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 improves the lifecycle management of polling tasks for
PolledElectricalMeasurementsensors in the ZHA integration. The main focus is to prevent orphaned or duplicate polling tasks by making polling enable/disable operations idempotent and ensuring completed tasks are properly cleaned up. Additionally, new tests have been added to validate these behaviors.Polling task lifecycle improvements:
maybe_start_polling()inzha/application/platforms/sensor/__init__.pyto avoid creating duplicate polling tasks and to remove completed tasks from_tracked_tasksbefore starting a new one. This ensures only one active polling task exists and prevents stale task accumulation.disable()inzha/application/platforms/sensor/__init__.pyto safely remove the polling task from_tracked_tasksbefore cancelling, preventing orphaned tasks and ensuring proper cleanup.Test coverage enhancements:
test_pollable_sensor_enable_non_idempotent_disable_leaves_orphan_poll_taskandtest_pollable_sensor_replaces_completed_polling_tasktotests/test_sensor.pyto verify that enabling/disabling sensors does not leak or duplicate polling tasks, and that completed tasks are replaced and cleaned up as expected.## SummaryPrevents duplicate poll task creation for pollable sensors on repeated enable calls and hardens disable cleanup.
Failing tests addressed
tests/test_sensor.py::test_pollable_sensor_enable_non_idempotent_disable_leaves_orphan_poll_taskVerification
pytest(branch-local targeted run): listed test passes.