Skip to content

Add map entities when home data arrives, not only at setup - #43

Merged
Lash-L merged 1 commit into
Python-roborock:mainfrom
paolostivanin:add-map-entities-when-home-data-arrives
Oct 11, 2026
Merged

Lash-L merged 1 commit into
Python-roborock:mainfrom
paolostivanin:add-map-entities-when-home-data-arrives

Conversation

@paolostivanin

Copy link
Copy Markdown
Contributor

The problem

On a two-robot setup, one of my vacuums (Rocky) comes up with no map image entity and no rotation select after most Home Assistant restarts. The other one (Rocky Jr) is always fine. Reloading the config entry by hand fixes it every time, which is what pointed at a race rather than a config issue.

Both platforms build their entities exactly once, in async_setup_entry, and skip any coordinator whose home data has not landed yet:

for coord in config_entry.runtime_data:
    if coord.properties_api.home is not None:
        for map_info in (coord.properties_api.home.home_map_info or {}).values():
            ...

That is not None is treated as an invariant, but it is a race. The core Roborock coordinator calls discover_home() during its own setup, and a device that happens to be busy at that moment raises RoborockDeviceBusy, which the coordinator swallows with an _LOGGER.info. Home data then arrives a little later through the normal update cycle - but async_setup_entry has already returned, so that device is silently left with no entities.

There is no warning and no retry, so from the user side it just looks like the integration randomly drops a robot. image.py and select.py have the same guard, which is why the map and its rotation select always disappear together.

The fix

Keep a set of the (device, map_flag) pairs already added, and re-run the scan on every coordinator update instead of only at setup. Entities appear as soon as their home data does, and the dedupe set makes the repeated scan a no-op once everything is present.

As a side effect this also picks up maps created in the Roborock app while Home Assistant is running, which previously also required a manual reload.

Listeners are registered via config_entry.async_on_unload(coord.async_add_listener(...)) so they are torn down with the entry.

Notes

  • No config or entity-naming changes - unique_ids are built exactly as before, so existing entities are untouched on upgrade.
  • ruff check passes. ruff format wants to reformat two pre-existing lines (a stray blank line in image.py, the RoborockMapRotationSelect class signature); I left those alone to keep the diff to the actual change.
  • Tested on HA 2026.7.4 with two V1 robots (a117 + a159) that reproduce the race on nearly every boot. Both maps and both rotation selects now come up on their own, no manual reload.

🤖 Generated with Claude Code

@paolostivanin
paolostivanin force-pushed the add-map-entities-when-home-data-arrives branch from 88f3c06 to 1d26979 Compare July 30, 2026 08:24
@Lash-L
Lash-L force-pushed the add-map-entities-when-home-data-arrives branch from 1d26979 to fc83c97 Compare October 11, 2026 17:38

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased cleanly on top of #42. Both hassfest and HACS checks are green. Excellent fix!

@Lash-L
Lash-L merged commit 3dbdd00 into Python-roborock:main Oct 11, 2026
2 checks passed
@paolostivanin
paolostivanin deleted the add-map-entities-when-home-data-arrives branch October 12, 2026 06:25
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