mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve typing for Tado (#106992)
This commit is contained in:
parent
db53237b9a
commit
3958d89ae6
@ -2,6 +2,7 @@
|
|||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from . import TadoConnector
|
||||||
from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
|
from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
|
||||||
|
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ class TadoDeviceEntity(Entity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, device_info):
|
def __init__(self, device_info: dict[str, str]) -> None:
|
||||||
"""Initialize a Tado device."""
|
"""Initialize a Tado device."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._device_info = device_info
|
self._device_info = device_info
|
||||||
@ -34,7 +35,7 @@ class TadoHomeEntity(Entity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, tado):
|
def __init__(self, tado: TadoConnector) -> None:
|
||||||
"""Initialize a Tado home."""
|
"""Initialize a Tado home."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.home_name = tado.home_name
|
self.home_name = tado.home_name
|
||||||
@ -54,7 +55,7 @@ class TadoZoneEntity(Entity):
|
|||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_should_poll = False
|
_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."""
|
"""Initialize a Tado zone."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.zone_name = zone_name
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
|
from . import TadoConnector
|
||||||
from .const import (
|
from .const import (
|
||||||
CONDITIONS_MAP,
|
CONDITIONS_MAP,
|
||||||
DATA,
|
DATA,
|
||||||
@ -60,14 +61,14 @@ def format_condition(condition: str) -> str:
|
|||||||
return condition
|
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."""
|
"""Return Tado Mode based on Presence attribute."""
|
||||||
if "presence" in data:
|
if "presence" in data:
|
||||||
return data["presence"]
|
return data["presence"]
|
||||||
return None
|
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."""
|
"""Return whether Automatic Geofencing is enabled based on Presence Locked attribute."""
|
||||||
if "presenceLocked" in data:
|
if "presenceLocked" in data:
|
||||||
if data["presenceLocked"]:
|
if data["presenceLocked"]:
|
||||||
@ -76,7 +77,7 @@ def get_automatic_geofencing(data) -> bool:
|
|||||||
return False
|
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."""
|
"""Return Geofencing Mode based on Presence and Presence Locked attributes."""
|
||||||
tado_mode = ""
|
tado_mode = ""
|
||||||
tado_mode = data.get("presence", "unknown")
|
tado_mode = data.get("presence", "unknown")
|
||||||
@ -240,7 +241,9 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
|||||||
|
|
||||||
entity_description: TadoSensorEntityDescription
|
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."""
|
"""Initialize of the Tado Sensor."""
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
super().__init__(tado)
|
super().__init__(tado)
|
||||||
@ -261,13 +264,13 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
|||||||
self._async_update_home_data()
|
self._async_update_home_data()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_callback(self):
|
def _async_update_callback(self) -> None:
|
||||||
"""Update and write state."""
|
"""Update and write state."""
|
||||||
self._async_update_home_data()
|
self._async_update_home_data()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_home_data(self):
|
def _async_update_home_data(self) -> None:
|
||||||
"""Handle update callbacks."""
|
"""Handle update callbacks."""
|
||||||
try:
|
try:
|
||||||
tado_weather_data = self._tado.data["weather"]
|
tado_weather_data = self._tado.data["weather"]
|
||||||
@ -294,9 +297,9 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
tado,
|
tado: TadoConnector,
|
||||||
zone_name,
|
zone_name: str,
|
||||||
zone_id,
|
zone_id: int,
|
||||||
entity_description: TadoSensorEntityDescription,
|
entity_description: TadoSensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize of the Tado Sensor."""
|
"""Initialize of the Tado Sensor."""
|
||||||
@ -321,13 +324,13 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
|||||||
self._async_update_zone_data()
|
self._async_update_zone_data()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_callback(self):
|
def _async_update_callback(self) -> None:
|
||||||
"""Update and write state."""
|
"""Update and write state."""
|
||||||
self._async_update_zone_data()
|
self._async_update_zone_data()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_zone_data(self):
|
def _async_update_zone_data(self) -> None:
|
||||||
"""Handle update callbacks."""
|
"""Handle update callbacks."""
|
||||||
try:
|
try:
|
||||||
tado_zone_data = self._tado.data["zone"][self.zone_id]
|
tado_zone_data = self._tado.data["zone"][self.zone_id]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user