mirror of https://github.com/home-assistant/core
Add strict typing to goalzero (#57680)
This commit is contained in:
parent
3127074f76
commit
abf6720cd3
|
@ -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.*
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
11
mypy.ini
11
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
|
||||
|
|
Loading…
Reference in New Issue