From 69e0227682eec31d365e2efab9aec58f66972f49 Mon Sep 17 00:00:00 2001 From: Luke Lashley Date: Wed, 26 Jun 2024 08:13:49 -0400 Subject: [PATCH] Add Roborock to strict typing (#120379) --- .strict-typing | 1 + homeassistant/components/roborock/image.py | 6 ++++-- homeassistant/components/roborock/number.py | 3 ++- homeassistant/components/roborock/switch.py | 10 +++++----- mypy.ini | 10 ++++++++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.strict-typing b/.strict-typing index 2a6edfedd324..a6deb6eca3ae 100644 --- a/.strict-typing +++ b/.strict-typing @@ -370,6 +370,7 @@ homeassistant.components.rhasspy.* homeassistant.components.ridwell.* homeassistant.components.ring.* homeassistant.components.rituals_perfume_genie.* +homeassistant.components.roborock.* homeassistant.components.roku.* homeassistant.components.romy.* homeassistant.components.rpi_power.* diff --git a/homeassistant/components/roborock/image.py b/homeassistant/components/roborock/image.py index afe1e781a888..33b8b0a2c901 100644 --- a/homeassistant/components/roborock/image.py +++ b/homeassistant/components/roborock/image.py @@ -1,6 +1,7 @@ """Support for Roborock image.""" import asyncio +from datetime import datetime import io from itertools import chain @@ -48,6 +49,7 @@ class RoborockMap(RoborockCoordinatedEntity, ImageEntity): """A class to let you visualize the map.""" _attr_has_entity_name = True + image_last_updated: datetime def __init__( self, @@ -76,7 +78,7 @@ class RoborockMap(RoborockCoordinatedEntity, ImageEntity): self._attr_entity_category = EntityCategory.DIAGNOSTIC @property - def available(self): + def available(self) -> bool: """Determines if the entity is available.""" return self.cached_map != b"" @@ -98,7 +100,7 @@ class RoborockMap(RoborockCoordinatedEntity, ImageEntity): and bool(self.coordinator.roborock_device_info.props.status.in_cleaning) ) - def _handle_coordinator_update(self): + def _handle_coordinator_update(self) -> None: # Bump last updated every third time the coordinator runs, so that async_image # will be called and we will evaluate on the new coordinator data if we should # update the cache. diff --git a/homeassistant/components/roborock/number.py b/homeassistant/components/roborock/number.py index 8aa20fad838f..a432c527b0e6 100644 --- a/homeassistant/components/roborock/number.py +++ b/homeassistant/components/roborock/number.py @@ -107,7 +107,8 @@ class RoborockNumberEntity(RoborockEntity, NumberEntity): @property def native_value(self) -> float | None: """Get native value.""" - return self.get_cache(self.entity_description.cache_key).value + val: float = self.get_cache(self.entity_description.cache_key).value + return val async def async_set_native_value(self, value: float) -> None: """Set number value.""" diff --git a/homeassistant/components/roborock/switch.py b/homeassistant/components/roborock/switch.py index 7e17844666e4..9a34060fe962 100644 --- a/homeassistant/components/roborock/switch.py +++ b/homeassistant/components/roborock/switch.py @@ -167,9 +167,9 @@ class RoborockSwitch(RoborockEntity, SwitchEntity): @property def is_on(self) -> bool | None: """Return True if entity is on.""" - return ( - self.get_cache(self.entity_description.cache_key).value.get( - self.entity_description.attribute - ) - == 1 + status = self.get_cache(self.entity_description.cache_key).value.get( + self.entity_description.attribute ) + if status is None: + return status + return bool(status) diff --git a/mypy.ini b/mypy.ini index 740eb4f2b5b3..d94e5a371942 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3463,6 +3463,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.roborock.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.roku.*] check_untyped_defs = true disallow_incomplete_defs = true