Skip to content

Add stale device removal to nobo_hub#176511

Merged
joostlek merged 8 commits into
home-assistant:devfrom
oyvindwe:nobo_hub-stale-devices
Jul 15, 2026
Merged

Add stale device removal to nobo_hub#176511
joostlek merged 8 commits into
home-assistant:devfrom
oyvindwe:nobo_hub-stale-devices

Conversation

@oyvindwe

Copy link
Copy Markdown
Contributor

Proposed change

  • 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

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

- 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
@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @echoromeo, mind taking a look at this pull request as it has been labeled with an integration (nobo_hub) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of nobo_hub can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign nobo_hub Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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

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.

Comment thread homeassistant/components/nobo_hub/__init__.py
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.
Copilot AI review requested due to automatic review settings July 14, 2026 18:46

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Comment thread homeassistant/components/nobo_hub/__init__.py Outdated
Comment thread tests/components/nobo_hub/test_sensor.py Outdated
Comment thread tests/components/nobo_hub/test_select.py Outdated
Comment thread tests/components/nobo_hub/test_climate.py Outdated
oyvindwe added 2 commits July 14, 2026 21:35
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.
Copilot AI review requested due to automatic review settings July 14, 2026 19:36

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Comment thread homeassistant/components/nobo_hub/sensor.py Outdated
Comment thread homeassistant/components/nobo_hub/select.py Outdated
Comment thread tests/components/nobo_hub/test_sensor.py Outdated
Comment thread tests/components/nobo_hub/test_select.py Outdated
Comment thread tests/components/nobo_hub/test_climate.py Outdated
@oyvindwe
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.
Copilot AI review requested due to automatic review settings July 14, 2026 20:04
@oyvindwe
oyvindwe marked this pull request as ready for review July 14, 2026 20:08

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/nobo_hub/sensor.py Outdated
Comment thread homeassistant/components/nobo_hub/climate.py Outdated
Comment thread homeassistant/components/nobo_hub/select.py Outdated
@oyvindwe
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.
Copilot AI review requested due to automatic review settings July 14, 2026 20:23

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/nobo_hub/__init__.py
Comment thread homeassistant/components/nobo_hub/quality_scale.yaml
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.
Copilot AI review requested due to automatic review settings July 14, 2026 20:42

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/nobo_hub/__init__.py
@oyvindwe
oyvindwe marked this pull request as ready for review July 14, 2026 20:55
Copilot AI review requested due to automatic review settings July 14, 2026 20:56

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@joostlek
joostlek merged commit cb75cee into home-assistant:dev Jul 15, 2026
33 checks passed
@oyvindwe
oyvindwe deleted the nobo_hub-stale-devices branch July 15, 2026 13:09
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants