From 42a3d42de76a44959e91fc3155a8126fa5e6aa31 Mon Sep 17 00:00:00 2001 From: MS2620 <113364931+MS2620@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:52:57 +0100 Subject: [PATCH] Fix Q7 map image refresh handling (#184333) --- homeassistant/components/roborock/image.py | 22 +++------------------- tests/components/roborock/test_image.py | 4 ++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/roborock/image.py b/homeassistant/components/roborock/image.py index cde95f388cc0..d6c8e750fe14 100644 --- a/homeassistant/components/roborock/image.py +++ b/homeassistant/components/roborock/image.py @@ -6,7 +6,6 @@ from typing import override from roborock.devices.traits.v1.home import HomeTrait from roborock.devices.traits.v1.map_content import MapContent -from roborock.exceptions import RoborockException from homeassistant.components.image import ImageEntity from homeassistant.config_entries import ConfigEntry @@ -224,16 +223,7 @@ class RoborockMapQ10(RoborockCoordinatedEntityB01Q10, ImageEntity): class RoborockMapQ7(RoborockCoordinatedEntityB01Q7, ImageEntity): - """A class to visualize the current map of a Q7 device. - - `python-roborock` here is pinned to >=5.31.1, which predates the - unsolicited-map-push support added in 7.1.0 (see README) — so unlike the - Q10 equivalent this entity does not rely on push updates arriving on - their own. It does an explicit `map.refresh()` + `map_content.refresh()` - once when added to hass so an image is available immediately, and again - whenever the coordinator's periodic status poll completes while a clean - is in progress (map content only meaningfully changes during cleaning). - """ + """A class to visualize the current map of a Q7 device.""" _attr_content_type = "image/png" _attr_entity_category = EntityCategory.DIAGNOSTIC @@ -250,18 +240,12 @@ class RoborockMapQ7(RoborockCoordinatedEntityB01Q7, ImageEntity): @override async def async_added_to_hass(self) -> None: - """Register a trait listener and fetch an initial map.""" + """Fetch the initial map and register for map updates.""" await super().async_added_to_hass() + await self.coordinator.async_refresh_q7_map() self.async_on_remove( self._map_content_trait.add_update_listener(self._handle_map_update) ) - try: - await self.coordinator.api.map.refresh() - await self._map_content_trait.refresh() - except RoborockException as ex: - _LOGGER.debug( - "Initial Q7 map fetch failed (will retry on next poll): %s", ex - ) self._handle_map_update() @callback diff --git a/tests/components/roborock/test_image.py b/tests/components/roborock/test_image.py index ccb1a6246a11..ed9fd581990c 100644 --- a/tests/components/roborock/test_image.py +++ b/tests/components/roborock/test_image.py @@ -461,7 +461,7 @@ async def test_q7_map_initial_fetch_exception( fake_q7_vacuum: FakeDevice, caplog: pytest.LogCaptureFixture, ) -> None: - """Test Q7 map initial fetch handles RoborockException gracefully.""" + """Test Q7 map initial fetch handles a refresh failure gracefully.""" caplog.set_level(logging.DEBUG, logger="homeassistant.components.roborock") assert fake_q7_vacuum.b01_q7_properties is not None @@ -472,4 +472,4 @@ async def test_q7_map_initial_fetch_exception( assert mock_roborock_entry.state is ConfigEntryState.LOADED assert hass.states.get("image.roborock_q7_map") is not None - assert "Initial Q7 map fetch failed (will retry on next poll)" in caplog.text + assert "Failed to refresh Q7 map: boom" in caplog.text