Skip to content

feat: implement dynamic map update listeners and filtering on HomeTrait#861

Merged
allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:implement-dynamic-map-listeners
Jul 3, 2026
Merged

feat: implement dynamic map update listeners and filtering on HomeTrait#861
allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:implement-dynamic-map-listeners

Conversation

@allenporter

Copy link
Copy Markdown
Contributor

Motivation

With Home Assistant moving towards supporting dynamic devices (resolving home-assistant/core#175400), the integration needs the ability to add and remove map/camera entities at runtime without requiring a full integration reload.

Previously, HomeTrait:

  1. Had no listener pattern to notify callers of updates.
  2. Did not clean up deleted maps from the home_map_info cache when they were removed on the device, meaning stale maps remained present in Home Assistant indefinitely.

This PR adds a standard update listener pattern to HomeTrait and implements dynamic map eviction so callers can dynamically align their entities with the active map list.

Proposed Changes

roborock/devices/traits/v1/home.py

  • Implement Trait Listener: Subclassed HomeTrait with TraitUpdateListener and triggered self._notify_update() when the cache is loaded, updated, or when a refresh concludes.
  • Immediate Callbacks at Subscription: Overrode add_update_listener to immediately execute the callback with the initial state if home_map_info is already populated. This allows subscribers to use a single code path for initial entity generation and subsequent updates.
  • Dynamic Map Eviction: Updated home_map_info and home_map_content properties to dynamically filter and return only maps that are currently active on the device (self._maps_trait.map_info). Stale map entries are omitted at lookup time, keeping the refresh() logic extremely clean and free of cache-eviction/file-writing complexity.

Testing

  • Added unit test test_home_trait_listener_notifications to verify callback triggers on cache loads, discovery updates, refreshes, and immediate callbacks at subscription time.
  • Added unit test test_home_trait_map_eviction to verify that deleted maps are dynamically excluded from lookup results when the device maps list updates.
  • Ran the test suite: all 577 tests passed successfully.

This change enables Home Assistant to dynamically add and remove maps/camera entities without restarting. Resolves HA issue: home-assistant/core#175400
@allenporter allenporter requested a review from Lash-L July 3, 2026 04:09
@allenporter allenporter merged commit a793c8e into Python-roborock:main Jul 3, 2026
7 checks passed
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