feat: implement dynamic map update listeners and filtering on HomeTrait#861
Merged
allenporter merged 1 commit intoJul 3, 2026
Conversation
This change enables Home Assistant to dynamically add and remove maps/camera entities without restarting. Resolves HA issue: home-assistant/core#175400
Lash-L
approved these changes
Jul 3, 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 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.
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:home_map_infocache 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
HomeTraitand implements dynamic map eviction so callers can dynamically align their entities with the active map list.Proposed Changes
roborock/devices/traits/v1/home.pyHomeTraitwithTraitUpdateListenerand triggeredself._notify_update()when the cache is loaded, updated, or when a refresh concludes.add_update_listenerto immediately execute the callback with the initial state ifhome_map_infois already populated. This allows subscribers to use a single code path for initial entity generation and subsequent updates.home_map_infoandhome_map_contentproperties 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 therefresh()logic extremely clean and free of cache-eviction/file-writing complexity.Testing
test_home_trait_listener_notificationsto verify callback triggers on cache loads, discovery updates, refreshes, and immediate callbacks at subscription time.test_home_trait_map_evictionto verify that deleted maps are dynamically excluded from lookup results when the device maps list updates.577tests passed successfully.