Make non-selected Roborock images diagnostic (#104233)

* Make images diagnostic

* Add return type

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Luke Lashley 2023-11-21 14:45:53 -05:00 committed by GitHub
parent b604c1c222
commit f45d373e17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ from vacuum_map_parser_roborock.map_data_parser import RoborockMapDataParser
from homeassistant.components.image import ImageEntity from homeassistant.components.image import ImageEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -66,10 +67,22 @@ class RoborockMap(RoborockCoordinatedEntity, ImageEntity):
self.map_flag = map_flag self.map_flag = map_flag
self.cached_map = self._create_image(starting_map) self.cached_map = self._create_image(starting_map)
@property
def entity_category(self) -> EntityCategory | None:
"""Return diagnostic entity category for any non-selected maps."""
if not self.is_selected:
return EntityCategory.DIAGNOSTIC
return None
@property
def is_selected(self) -> bool:
"""Return if this map is the currently selected map."""
return self.map_flag == self.coordinator.current_map
def is_map_valid(self) -> bool: def is_map_valid(self) -> bool:
"""Update this map if it is the current active map, and the vacuum is cleaning.""" """Update this map if it is the current active map, and the vacuum is cleaning."""
return ( return (
self.map_flag == self.coordinator.current_map self.is_selected
and self.image_last_updated is not None and self.image_last_updated is not None
and self.coordinator.roborock_device_info.props.status is not None and self.coordinator.roborock_device_info.props.status is not None
and bool(self.coordinator.roborock_device_info.props.status.in_cleaning) and bool(self.coordinator.roborock_device_info.props.status.in_cleaning)