From abf6720cd3d12d5bed3194754481aa39933c349e Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 14 Oct 2021 18:20:08 -0400 Subject: [PATCH] Add strict typing to goalzero (#57680) --- .strict-typing | 1 + homeassistant/components/goalzero/__init__.py | 2 +- homeassistant/components/goalzero/binary_sensor.py | 4 +++- homeassistant/components/goalzero/sensor.py | 4 +++- homeassistant/components/goalzero/switch.py | 8 +++++--- mypy.ini | 11 +++++++++++ 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.strict-typing b/.strict-typing index 7710f637090..907c51442a1 100644 --- a/.strict-typing +++ b/.strict-typing @@ -48,6 +48,7 @@ homeassistant.components.frontend.* homeassistant.components.fritz.* homeassistant.components.geo_location.* homeassistant.components.gios.* +homeassistant.components.goalzero.* homeassistant.components.group.* homeassistant.components.guardian.* homeassistant.components.history.* diff --git a/homeassistant/components/goalzero/__init__.py b/homeassistant/components/goalzero/__init__.py index 7a179c46210..53daa29de8a 100644 --- a/homeassistant/components/goalzero/__init__.py +++ b/homeassistant/components/goalzero/__init__.py @@ -54,7 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except exceptions.ConnectError as ex: raise ConfigEntryNotReady(f"Failed to connect to device: {ex}") from ex - async def async_update_data(): + async def async_update_data() -> None: """Fetch data from API endpoint.""" try: await api.get_state() diff --git a/homeassistant/components/goalzero/binary_sensor.py b/homeassistant/components/goalzero/binary_sensor.py index 21eecc678ad..0e61c7178bb 100644 --- a/homeassistant/components/goalzero/binary_sensor.py +++ b/homeassistant/components/goalzero/binary_sensor.py @@ -1,6 +1,8 @@ """Support for Goal Zero Yeti Sensors.""" from __future__ import annotations +from typing import cast + from homeassistant.components.binary_sensor import ( DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_CONNECTIVITY, @@ -81,4 +83,4 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity): @property def is_on(self) -> bool: """Return if the service is on.""" - return self.api.data.get(self.entity_description.key) == 1 + return cast(bool, self.api.data.get(self.entity_description.key) == 1) diff --git a/homeassistant/components/goalzero/sensor.py b/homeassistant/components/goalzero/sensor.py index 957891e67ed..bbf3fba753f 100644 --- a/homeassistant/components/goalzero/sensor.py +++ b/homeassistant/components/goalzero/sensor.py @@ -1,6 +1,8 @@ """Support for Goal Zero Yeti Sensors.""" from __future__ import annotations +from typing import cast + from homeassistant.components.sensor import ( STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, @@ -170,4 +172,4 @@ class YetiSensor(YetiEntity, SensorEntity): @property def native_value(self) -> str: """Return the state.""" - return self.api.data.get(self.entity_description.key) + return cast(str, self.api.data.get(self.entity_description.key)) diff --git a/homeassistant/components/goalzero/switch.py b/homeassistant/components/goalzero/switch.py index 767c728e62b..2932413465a 100644 --- a/homeassistant/components/goalzero/switch.py +++ b/homeassistant/components/goalzero/switch.py @@ -1,6 +1,8 @@ """Support for Goal Zero Yeti Switches.""" from __future__ import annotations +from typing import Any, cast + from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME @@ -65,15 +67,15 @@ class YetiSwitch(YetiEntity, SwitchEntity): @property def is_on(self) -> bool: """Return state of the switch.""" - return self.api.data.get(self.entity_description.key) + return cast(bool, self.api.data.get(self.entity_description.key)) - async def async_turn_off(self, **kwargs) -> None: + async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the switch.""" payload = {self.entity_description.key: 0} await self.api.post_state(payload=payload) self.coordinator.async_set_updated_data(data=payload) - async def async_turn_on(self, **kwargs) -> None: + async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the switch.""" payload = {self.entity_description.key: 1} await self.api.post_state(payload=payload) diff --git a/mypy.ini b/mypy.ini index 440f410d0ab..636fbfe5287 100644 --- a/mypy.ini +++ b/mypy.ini @@ -539,6 +539,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.goalzero.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.group.*] check_untyped_defs = true disallow_incomplete_defs = true