Check that the current roboorck map exists before updating it. (#142341)

* Check that the current map exists

* Add a few extra checks

* Update coordinator.py

Co-authored-by: Allen Porter <allen.porter@gmail.com>

* fixlint

---------

Co-authored-by: Allen Porter <allen.porter@gmail.com>
This commit is contained in:
Luke Lashley 2025-04-05 19:45:00 -04:00 committed by GitHub
parent bd8c723e08
commit 0a7b4d18dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View File

@ -226,7 +226,7 @@ class RoborockDataUpdateCoordinator(DataUpdateCoordinator[DeviceProp]):
"""Update the currently selected map."""
# The current map was set in the props update, so these can be done without
# worry of applying them to the wrong map.
if self.current_map is None:
if self.current_map is None or self.current_map not in self.maps:
# This exists as a safeguard/ to keep mypy happy.
return
try:
@ -302,13 +302,17 @@ class RoborockDataUpdateCoordinator(DataUpdateCoordinator[DeviceProp]):
# If the vacuum is currently cleaning and it has been IMAGE_CACHE_INTERVAL
# since the last map update, you can update the map.
new_status = self.roborock_device_info.props.status
if self.current_map is not None and (
(
new_status.in_cleaning
and (dt_util.utcnow() - self.maps[self.current_map].last_updated)
> IMAGE_CACHE_INTERVAL
if (
self.current_map is not None
and (current_map := self.maps.get(self.current_map))
and (
(
new_status.in_cleaning
and (dt_util.utcnow() - current_map.last_updated)
> IMAGE_CACHE_INTERVAL
)
or self.last_update_state != new_status.state_name
)
or self.last_update_state != new_status.state_name
):
try:
await self.update_map()

View File

@ -381,7 +381,10 @@ class RoborockCurrentRoom(RoborockCoordinatedEntityV1, SensorEntity):
@property
def options(self) -> list[str]:
"""Return the currently valid rooms."""
if self.coordinator.current_map is not None:
if (
self.coordinator.current_map is not None
and self.coordinator.current_map in self.coordinator.maps
):
return list(
self.coordinator.maps[self.coordinator.current_map].rooms.values()
)
@ -390,7 +393,10 @@ class RoborockCurrentRoom(RoborockCoordinatedEntityV1, SensorEntity):
@property
def native_value(self) -> str | None:
"""Return the value reported by the sensor."""
if self.coordinator.current_map is not None:
if (
self.coordinator.current_map is not None
and self.coordinator.current_map in self.coordinator.maps
):
return self.coordinator.maps[self.coordinator.current_map].current_room
return None