Add strict typing to goalzero (#57680)

This commit is contained in:
Robert Hillis 2021-10-14 18:20:08 -04:00 committed by GitHub
parent 3127074f76
commit abf6720cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 6 deletions

View File

@ -48,6 +48,7 @@ homeassistant.components.frontend.*
homeassistant.components.fritz.* homeassistant.components.fritz.*
homeassistant.components.geo_location.* homeassistant.components.geo_location.*
homeassistant.components.gios.* homeassistant.components.gios.*
homeassistant.components.goalzero.*
homeassistant.components.group.* homeassistant.components.group.*
homeassistant.components.guardian.* homeassistant.components.guardian.*
homeassistant.components.history.* homeassistant.components.history.*

View File

@ -54,7 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except exceptions.ConnectError as ex: except exceptions.ConnectError as ex:
raise ConfigEntryNotReady(f"Failed to connect to device: {ex}") from 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.""" """Fetch data from API endpoint."""
try: try:
await api.get_state() await api.get_state()

View File

@ -1,6 +1,8 @@
"""Support for Goal Zero Yeti Sensors.""" """Support for Goal Zero Yeti Sensors."""
from __future__ import annotations from __future__ import annotations
from typing import cast
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_BATTERY_CHARGING,
DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_CONNECTIVITY,
@ -81,4 +83,4 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return if the service is on.""" """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)

View File

@ -1,6 +1,8 @@
"""Support for Goal Zero Yeti Sensors.""" """Support for Goal Zero Yeti Sensors."""
from __future__ import annotations from __future__ import annotations
from typing import cast
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
@ -170,4 +172,4 @@ class YetiSensor(YetiEntity, SensorEntity):
@property @property
def native_value(self) -> str: def native_value(self) -> str:
"""Return the state.""" """Return the state."""
return self.api.data.get(self.entity_description.key) return cast(str, self.api.data.get(self.entity_description.key))

View File

@ -1,6 +1,8 @@
"""Support for Goal Zero Yeti Switches.""" """Support for Goal Zero Yeti Switches."""
from __future__ import annotations from __future__ import annotations
from typing import Any, cast
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
@ -65,15 +67,15 @@ class YetiSwitch(YetiEntity, SwitchEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return state of the switch.""" """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.""" """Turn off the switch."""
payload = {self.entity_description.key: 0} payload = {self.entity_description.key: 0}
await self.api.post_state(payload=payload) await self.api.post_state(payload=payload)
self.coordinator.async_set_updated_data(data=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.""" """Turn on the switch."""
payload = {self.entity_description.key: 1} payload = {self.entity_description.key: 1}
await self.api.post_state(payload=payload) await self.api.post_state(payload=payload)

View File

@ -539,6 +539,17 @@ no_implicit_optional = true
warn_return_any = true warn_return_any = true
warn_unreachable = 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.*] [mypy-homeassistant.components.group.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true