Do not activate and queue entities during reconfiguration - #878
Draft
TheJulianJES wants to merge 1 commit into
Draft
Do not activate and queue entities during reconfiguration#878TheJulianJES wants to merge 1 commit into
TheJulianJES wants to merge 1 commit into
Conversation
`async_configure()` only discovers entities to aggregate their cluster configs for binding/reporting, but discovery also ran `entity.on_add()` (registering cluster listeners and other side effects) and queued the entities in `_pending_entities` — which nothing flushes on a reconfigure, so every reconfigure of a live device leaked another set of never-added entities with active listeners. Discovery now skips activating and queueing the entities when the device still has live entities, as those already listen. Without live entities — the initial join, or a rebuild after a re-interview — the entities are still activated during configuration, as e.g. the IAS zone enrollment entity has to answer a device-initiated enroll request right after the CIE address is written; `async_initialize()` then adds them and cleans up its own re-discoveries.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #878 +/- ##
=======================================
Coverage 97.19% 97.19%
=======================================
Files 57 57
Lines 10543 10545 +2
=======================================
+ Hits 10247 10249 +2
Misses 296 296 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents entity activation and queuing during live-device reconfiguration while preserving activation during initial setup and rebuilds.
Changes:
- Adds an aggregation-only entity discovery mode.
- Tests reconfiguration and post-rebuild initialization behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
zha/zigbee/device.py |
Conditionally skips entity activation and queuing. |
tests/test_device.py |
Covers live reconfiguration and rebuild behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes the second item of #725.
async_configure()only discovers entities to aggregate their cluster configs for binding/reporting, but discovery also ranentity.on_add()(registering cluster listeners and other side effects) and queued the entities in_pending_entities— which nothing flushes on a reconfigure. On the initial join this was harmless (async_initialize()added the entities and cleaned up its duplicate re-discoveries), but every reconfigure of a live device leaked another set of never-added entities with active listeners (e.g. a secondIasZoneEnrollmentlistener on the IAS cluster).Discovery now skips activating and queueing the entities when the device still has live entities, as those already listen. Without live entities, the entities are still activated during configuration: e.g. the IAS zone enrollment entity has to answer a device-initiated enroll request right after the CIE address is written.
async_initialize()then adds them and cleans up its own re-discoveries.The gate is "does the device have live entities" rather than "is the device initialized", because a rebuild after a same-quirk re-interview tears down all entities while
_initializedstays set — configuration must re-activate the entities there (verified that the IAS enrollment listener is live during the post-rebuild CIE handshake).Tests
test_async_configure_does_not_queue_entities: a reconfigure of a live device leaves no pending entities; after a rebuild, configuration queues them again and the following initialization restores the same entity set. Fails ondev.