@@ -112,19 +112,6 @@ def is_selected(self) -> bool:
112112 """Return if this map is the currently selected map."""
113113 return self .map_flag == self .coordinator .current_map
114114
115- def is_map_valid (self ) -> bool :
116- """Update the map if it is valid.
117-
118- Update this map if it is the currently active map, and the
119- vacuum is cleaning, or if it has never been set at all.
120- """
121- return self .cached_map == b"" or (
122- self .is_selected
123- and self .image_last_updated is not None
124- and self .coordinator .roborock_device_info .props .status is not None
125- and bool (self .coordinator .roborock_device_info .props .status .in_cleaning )
126- )
127-
128115 async def async_added_to_hass (self ) -> None :
129116 """When entity is added to hass load any previously cached maps from disk."""
130117 await super ().async_added_to_hass ()
@@ -137,15 +124,22 @@ def _handle_coordinator_update(self) -> None:
137124 # Bump last updated every third time the coordinator runs, so that async_image
138125 # will be called and we will evaluate on the new coordinator data if we should
139126 # update the cache.
140- if (
141- dt_util .utcnow () - self .image_last_updated
142- ).total_seconds () > IMAGE_CACHE_INTERVAL and self .is_map_valid ():
127+ if self .is_selected and (
128+ (
129+ (dt_util .utcnow () - self .image_last_updated ).total_seconds ()
130+ > IMAGE_CACHE_INTERVAL
131+ and self .coordinator .roborock_device_info .props .status is not None
132+ and bool (self .coordinator .roborock_device_info .props .status .in_cleaning )
133+ )
134+ or self .cached_map == b""
135+ ):
136+ # This will tell async_image it should update.
143137 self ._attr_image_last_updated = dt_util .utcnow ()
144138 super ()._handle_coordinator_update ()
145139
146140 async def async_image (self ) -> bytes | None :
147141 """Update the image if it is not cached."""
148- if self .is_map_valid () :
142+ if self .is_selected :
149143 response = await asyncio .gather (
150144 * (
151145 self .cloud_api .get_map_v1 (),
0 commit comments