mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix Tado unloading (#126910)
This commit is contained in:
parent
308f25fe4c
commit
20a57d6381
@ -1,9 +1,7 @@
|
|||||||
"""Support for the (unofficial) Tado API."""
|
"""Support for the (unofficial) Tado API."""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|
||||||
@ -22,9 +20,6 @@ from .const import (
|
|||||||
CONST_OVERLAY_TADO_MODE,
|
CONST_OVERLAY_TADO_MODE,
|
||||||
CONST_OVERLAY_TADO_OPTIONS,
|
CONST_OVERLAY_TADO_OPTIONS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
UPDATE_LISTENER,
|
|
||||||
UPDATE_MOBILE_DEVICE_TRACK,
|
|
||||||
UPDATE_TRACK,
|
|
||||||
)
|
)
|
||||||
from .services import setup_services
|
from .services import setup_services
|
||||||
from .tado_connector import TadoConnector
|
from .tado_connector import TadoConnector
|
||||||
@ -55,17 +50,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
type TadoConfigEntry = ConfigEntry[TadoRuntimeData]
|
type TadoConfigEntry = ConfigEntry[TadoConnector]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class TadoRuntimeData:
|
|
||||||
"""Dataclass for Tado runtime data."""
|
|
||||||
|
|
||||||
tadoconnector: TadoConnector
|
|
||||||
update_track: Any
|
|
||||||
update_mobile_device_track: Any
|
|
||||||
update_listener: Any
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: TadoConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: TadoConfigEntry) -> bool:
|
||||||
@ -99,26 +84,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: TadoConfigEntry) -> bool
|
|||||||
await hass.async_add_executor_job(tadoconnector.update)
|
await hass.async_add_executor_job(tadoconnector.update)
|
||||||
|
|
||||||
# Poll for updates in the background
|
# Poll for updates in the background
|
||||||
update_track = async_track_time_interval(
|
entry.async_on_unload(
|
||||||
hass,
|
async_track_time_interval(
|
||||||
lambda now: tadoconnector.update(),
|
hass,
|
||||||
SCAN_INTERVAL,
|
lambda now: tadoconnector.update(),
|
||||||
|
SCAN_INTERVAL,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
update_mobile_devices = async_track_time_interval(
|
entry.async_on_unload(
|
||||||
hass,
|
async_track_time_interval(
|
||||||
lambda now: tadoconnector.update_mobile_devices(),
|
hass,
|
||||||
SCAN_MOBILE_DEVICE_INTERVAL,
|
lambda now: tadoconnector.update_mobile_devices(),
|
||||||
|
SCAN_MOBILE_DEVICE_INTERVAL,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
update_listener = entry.add_update_listener(_async_update_listener)
|
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
|
||||||
|
|
||||||
entry.runtime_data = TadoRuntimeData(
|
entry.runtime_data = tadoconnector
|
||||||
tadoconnector=tadoconnector,
|
|
||||||
update_track=update_track,
|
|
||||||
update_mobile_device_track=update_mobile_devices,
|
|
||||||
update_listener=update_listener,
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@ -147,15 +131,6 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> Non
|
|||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: TadoConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][UPDATE_TRACK]()
|
|
||||||
hass.data[DOMAIN][entry.entry_id][UPDATE_LISTENER]()
|
|
||||||
hass.data[DOMAIN][entry.entry_id][UPDATE_MOBILE_DEVICE_TRACK]()
|
|
||||||
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -121,7 +121,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tado sensor platform."""
|
"""Set up the Tado sensor platform."""
|
||||||
|
|
||||||
tado: TadoConnector = entry.runtime_data.tadoconnector
|
tado = entry.runtime_data
|
||||||
devices = tado.devices
|
devices = tado.devices
|
||||||
zones = tado.zones
|
zones = tado.zones
|
||||||
entities: list[BinarySensorEntity] = []
|
entities: list[BinarySensorEntity] = []
|
||||||
|
@ -105,7 +105,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tado climate platform."""
|
"""Set up the Tado climate platform."""
|
||||||
|
|
||||||
tado: TadoConnector = entry.runtime_data.tadoconnector
|
tado = entry.runtime_data
|
||||||
entities = await hass.async_add_executor_job(_generate_entities, tado)
|
entities = await hass.async_add_executor_job(_generate_entities, tado)
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
|
@ -38,8 +38,6 @@ TADO_HVAC_ACTION_TO_HA_HVAC_ACTION = {
|
|||||||
CONF_FALLBACK = "fallback"
|
CONF_FALLBACK = "fallback"
|
||||||
CONF_HOME_ID = "home_id"
|
CONF_HOME_ID = "home_id"
|
||||||
DATA = "data"
|
DATA = "data"
|
||||||
UPDATE_TRACK = "update_track"
|
|
||||||
UPDATE_MOBILE_DEVICE_TRACK = "update_mobile_device_track"
|
|
||||||
|
|
||||||
# Weather
|
# Weather
|
||||||
CONDITIONS_MAP = {
|
CONDITIONS_MAP = {
|
||||||
@ -207,8 +205,6 @@ DEFAULT_NAME = "Tado"
|
|||||||
TADO_HOME = "Home"
|
TADO_HOME = "Home"
|
||||||
TADO_ZONE = "Zone"
|
TADO_ZONE = "Zone"
|
||||||
|
|
||||||
UPDATE_LISTENER = "update_listener"
|
|
||||||
|
|
||||||
# Constants for Temperature Offset
|
# Constants for Temperature Offset
|
||||||
INSIDE_TEMPERATURE_MEASUREMENT = "INSIDE_TEMPERATURE_MEASUREMENT"
|
INSIDE_TEMPERATURE_MEASUREMENT = "INSIDE_TEMPERATURE_MEASUREMENT"
|
||||||
TEMP_OFFSET = "temperatureOffset"
|
TEMP_OFFSET = "temperatureOffset"
|
||||||
|
@ -28,7 +28,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tado device scannery entity."""
|
"""Set up the Tado device scannery entity."""
|
||||||
_LOGGER.debug("Setting up Tado device scanner entity")
|
_LOGGER.debug("Setting up Tado device scanner entity")
|
||||||
tado: TadoConnector = entry.runtime_data.tadoconnector
|
tado = entry.runtime_data
|
||||||
tracked: set = set()
|
tracked: set = set()
|
||||||
|
|
||||||
# Fix non-string unique_id for device trackers
|
# Fix non-string unique_id for device trackers
|
||||||
|
@ -71,10 +71,8 @@ def get_automatic_geofencing(data: dict[str, str]) -> bool:
|
|||||||
|
|
||||||
def get_geofencing_mode(data: dict[str, str]) -> 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 = data.get("presence", "unknown")
|
tado_mode = data.get("presence", "unknown")
|
||||||
|
|
||||||
geofencing_switch_mode = ""
|
|
||||||
if "presenceLocked" in data:
|
if "presenceLocked" in data:
|
||||||
if data["presenceLocked"]:
|
if data["presenceLocked"]:
|
||||||
geofencing_switch_mode = "manual"
|
geofencing_switch_mode = "manual"
|
||||||
@ -199,7 +197,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tado sensor platform."""
|
"""Set up the Tado sensor platform."""
|
||||||
|
|
||||||
tado: TadoConnector = entry.runtime_data.tadoconnector
|
tado = entry.runtime_data
|
||||||
zones = tado.zones
|
zones = tado.zones
|
||||||
entities: list[SensorEntity] = []
|
entities: list[SensorEntity] = []
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_ADD_METER_READING,
|
SERVICE_ADD_METER_READING,
|
||||||
)
|
)
|
||||||
from .tado_connector import TadoConnector
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
SCHEMA_ADD_METER_READING = vol.Schema(
|
SCHEMA_ADD_METER_READING = vol.Schema(
|
||||||
@ -44,7 +43,7 @@ def setup_services(hass: HomeAssistant) -> None:
|
|||||||
if entry is None:
|
if entry is None:
|
||||||
raise ServiceValidationError("Config entry not found")
|
raise ServiceValidationError("Config entry not found")
|
||||||
|
|
||||||
tadoconnector: TadoConnector = entry.runtime_data.tadoconnector
|
tadoconnector = entry.runtime_data
|
||||||
|
|
||||||
response: dict = await hass.async_add_executor_job(
|
response: dict = await hass.async_add_executor_job(
|
||||||
tadoconnector.set_meter_reading, call.data[CONF_READING]
|
tadoconnector.set_meter_reading, call.data[CONF_READING]
|
||||||
|
@ -67,7 +67,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tado water heater platform."""
|
"""Set up the Tado water heater platform."""
|
||||||
|
|
||||||
tado: TadoConnector = entry.runtime_data.tadoconnector
|
tado = entry.runtime_data
|
||||||
entities = await hass.async_add_executor_job(_generate_entities, tado)
|
entities = await hass.async_add_executor_job(_generate_entities, tado)
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user