Improve typing for Tado (#106992)
This commit is contained in:
parent
db53237b9a
commit
3958d89ae6
2 changed files with 18 additions and 14 deletions
|
@ -2,6 +2,7 @@
|
|||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import TadoConnector
|
||||
from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
|
||||
|
||||
|
||||
|
@ -11,7 +12,7 @@ class TadoDeviceEntity(Entity):
|
|||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, device_info):
|
||||
def __init__(self, device_info: dict[str, str]) -> None:
|
||||
"""Initialize a Tado device."""
|
||||
super().__init__()
|
||||
self._device_info = device_info
|
||||
|
@ -34,7 +35,7 @@ class TadoHomeEntity(Entity):
|
|||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, tado):
|
||||
def __init__(self, tado: TadoConnector) -> None:
|
||||
"""Initialize a Tado home."""
|
||||
super().__init__()
|
||||
self.home_name = tado.home_name
|
||||
|
@ -54,7 +55,7 @@ class TadoZoneEntity(Entity):
|
|||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, zone_name, home_id, zone_id):
|
||||
def __init__(self, zone_name: str, home_id: int, zone_id: int) -> None:
|
||||
"""Initialize a Tado zone."""
|
||||
super().__init__()
|
||||
self.zone_name = zone_name
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import TadoConnector
|
||||
from .const import (
|
||||
CONDITIONS_MAP,
|
||||
DATA,
|
||||
|
@ -60,14 +61,14 @@ def format_condition(condition: str) -> str:
|
|||
return condition
|
||||
|
||||
|
||||
def get_tado_mode(data) -> str | None:
|
||||
def get_tado_mode(data: dict[str, str]) -> str | None:
|
||||
"""Return Tado Mode based on Presence attribute."""
|
||||
if "presence" in data:
|
||||
return data["presence"]
|
||||
return None
|
||||
|
||||
|
||||
def get_automatic_geofencing(data) -> bool:
|
||||
def get_automatic_geofencing(data: dict[str, str]) -> bool:
|
||||
"""Return whether Automatic Geofencing is enabled based on Presence Locked attribute."""
|
||||
if "presenceLocked" in data:
|
||||
if data["presenceLocked"]:
|
||||
|
@ -76,7 +77,7 @@ def get_automatic_geofencing(data) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def get_geofencing_mode(data) -> str:
|
||||
def get_geofencing_mode(data: dict[str, str]) -> str:
|
||||
"""Return Geofencing Mode based on Presence and Presence Locked attributes."""
|
||||
tado_mode = ""
|
||||
tado_mode = data.get("presence", "unknown")
|
||||
|
@ -240,7 +241,9 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
|||
|
||||
entity_description: TadoSensorEntityDescription
|
||||
|
||||
def __init__(self, tado, entity_description: TadoSensorEntityDescription) -> None:
|
||||
def __init__(
|
||||
self, tado: TadoConnector, entity_description: TadoSensorEntityDescription
|
||||
) -> None:
|
||||
"""Initialize of the Tado Sensor."""
|
||||
self.entity_description = entity_description
|
||||
super().__init__(tado)
|
||||
|
@ -261,13 +264,13 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
|||
self._async_update_home_data()
|
||||
|
||||
@callback
|
||||
def _async_update_callback(self):
|
||||
def _async_update_callback(self) -> None:
|
||||
"""Update and write state."""
|
||||
self._async_update_home_data()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _async_update_home_data(self):
|
||||
def _async_update_home_data(self) -> None:
|
||||
"""Handle update callbacks."""
|
||||
try:
|
||||
tado_weather_data = self._tado.data["weather"]
|
||||
|
@ -294,9 +297,9 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
tado,
|
||||
zone_name,
|
||||
zone_id,
|
||||
tado: TadoConnector,
|
||||
zone_name: str,
|
||||
zone_id: int,
|
||||
entity_description: TadoSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize of the Tado Sensor."""
|
||||
|
@ -321,13 +324,13 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
|||
self._async_update_zone_data()
|
||||
|
||||
@callback
|
||||
def _async_update_callback(self):
|
||||
def _async_update_callback(self) -> None:
|
||||
"""Update and write state."""
|
||||
self._async_update_zone_data()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _async_update_zone_data(self):
|
||||
def _async_update_zone_data(self) -> None:
|
||||
"""Handle update callbacks."""
|
||||
try:
|
||||
tado_zone_data = self._tado.data["zone"][self.zone_id]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue