Fix Q7 map image refresh handling (#184333)

This commit is contained in:
MS2620
2026-10-05 17:52:57 +02:00
committed by GitHub
parent 70f7d12680
commit 42a3d42de7
2 changed files with 5 additions and 21 deletions
+3 -19
View File
@@ -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
+2 -2
View File
@@ -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