Skip to content

Do not activate and queue entities during reconfiguration - #878

Draft
TheJulianJES wants to merge 1 commit into
zigpy:devfrom
TheJulianJES:tjj/configure-no-entity-side-effects
Draft

Do not activate and queue entities during reconfiguration#878
TheJulianJES wants to merge 1 commit into
zigpy:devfrom
TheJulianJES:tjj/configure-no-entity-side-effects

Conversation

@TheJulianJES

Copy link
Copy Markdown
Contributor

Fixes the second item of #725.

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. 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 second IasZoneEnrollment listener 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 _initialized stays 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 on dev.

`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

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

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

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

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.

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.

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