Add stale device removal to nobo_hub#176511
Merged
Merged
Conversation
- Remove the devices of zones and components that are removed from the hub, without requiring a reload - Reconcile known zone/component ids against the hub on each push, so an id reused after removal (the hub reuses ids) is re-added - Flip stale-devices to done
Contributor
|
Hey there @echoromeo, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Automatically reconciles Nobø hub topology with Home Assistant, removing stale devices and supporting reused IDs.
Changes:
- Adds connected-only stale-device cleanup.
- Reconciles known zone/component IDs on updates.
- Updates tests and quality-scale status.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/nobo_hub/__init__.py |
Adds device cleanup callback. |
homeassistant/components/nobo_hub/climate.py |
Reconciles known zones. |
homeassistant/components/nobo_hub/select.py |
Reconciles profile zones. |
homeassistant/components/nobo_hub/sensor.py |
Reconciles known components. |
homeassistant/components/nobo_hub/quality_scale.yaml |
Marks stale-device handling complete. |
tests/components/nobo_hub/__init__.py |
Adds device identifier helper. |
tests/components/nobo_hub/test_init.py |
Tests device cleanup safeguards. |
tests/components/nobo_hub/test_climate.py |
Tests removal and reused zone IDs. |
tests/components/nobo_hub/test_select.py |
Updates zone-removal expectations. |
tests/components/nobo_hub/test_sensor.py |
Updates component-removal expectations. |
pynobo invokes the registered update callback while iterating its callback list. Removing a device from _cleanup_devices tears down its entities, which deregister their own callbacks and mutate that list while pynobo is still iterating it. Collect the stale device ids in the callback but perform the removal from hass.loop.call_soon, after pynobo's dispatch loop has unwound.
The call_soon deferral introduced an ordering hazard: when pynobo processes a buffered zone removal followed by an id-reusing add before the deferred removal runs, the re-add is rejected as a duplicate and the stale snapshot then deletes the surviving entity, leaving the zone with no entity until reload. Synchronous removal has no such window — the old device/entity is gone before the next buffered message's add. The original re-entrancy concern (mutating pynobo's callback list mid-dispatch) is harmless here (per-message dispatch; removal messages don't update survivors) and is fixed at the root upstream in echoromeo/pynobo#44.
These tests assert the entity is removed (state is None), not marked unavailable; rename them to match.
oyvindwe
marked this pull request as draft
July 14, 2026 19:42
Cover the reused-id/serial re-add path for the week-profile selector and
the temperature sensor, mirroring the existing climate test — each
platform reconciles known ids in its own _add_* closure.
Reword the three removal-test docstrings so the removal operation is the
subject ("Removing a …") to match the compound predicate.
oyvindwe
marked this pull request as draft
July 14, 2026 20:14
Each _add_* reconciles its known-id set with hub.zones/hub.components to re-detect reused ids. While disconnected pynobo may hold a stale/empty topology, so guard the intersection_update on hub.connected (as _cleanup_devices already does); otherwise the set is cleared and every entity is re-added on reconnect, colliding with its registered unique id.
Dispatch a removal and a same-id addition back-to-back without draining the event loop between them (as pynobo does with buffered messages), to lock in that synchronous _cleanup_devices deregisters the old entity before the re-add. Factor out dispatch_hub_update for the no-yield case.
oyvindwe
marked this pull request as ready for review
July 14, 2026 20:55
joostlek
approved these changes
Jul 15, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Proposed change
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: