mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
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:
parent
bd8c723e08
commit
0a7b4d18dc
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user