Explicitly pass in the config_entry in tado coordinator (#137916)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 21:57:03 +01:00 committed by GitHub
parent c47a97a4f0
commit b338de9a30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View File

@ -87,7 +87,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: TadoConfigEntry) -> bool
@callback
def _async_import_options_from_data_if_missing(hass: HomeAssistant, entry: ConfigEntry):
def _async_import_options_from_data_if_missing(
hass: HomeAssistant, entry: TadoConfigEntry
):
options = dict(entry.options)
if CONF_FALLBACK not in options:
options[CONF_FALLBACK] = entry.data.get(

View File

@ -4,18 +4,20 @@ from __future__ import annotations
from datetime import datetime, timedelta
import logging
from typing import Any
from typing import TYPE_CHECKING, Any
from PyTado.interface import Tado
from requests import RequestException
from homeassistant.components.climate import PRESET_AWAY, PRESET_HOME
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
if TYPE_CHECKING:
from . import TadoConfigEntry
from .const import (
CONF_FALLBACK,
CONST_OVERLAY_TADO_DEFAULT,
@ -31,8 +33,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=4)
SCAN_INTERVAL = timedelta(minutes=5)
SCAN_MOBILE_DEVICE_INTERVAL = timedelta(seconds=30)
type TadoConfigEntry = ConfigEntry[TadoDataUpdateCoordinator]
class TadoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]):
"""Class to manage API calls from and to Tado via PyTado."""
@ -45,7 +45,7 @@ class TadoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]):
def __init__(
self,
hass: HomeAssistant,
entry: ConfigEntry,
config_entry: TadoConfigEntry,
tado: Tado,
debug: bool = False,
) -> None:
@ -53,13 +53,16 @@ class TadoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]):
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=SCAN_INTERVAL,
)
self._tado = tado
self._username = entry.data[CONF_USERNAME]
self._password = entry.data[CONF_PASSWORD]
self._fallback = entry.options.get(CONF_FALLBACK, CONST_OVERLAY_TADO_DEFAULT)
self._username = config_entry.data[CONF_USERNAME]
self._password = config_entry.data[CONF_PASSWORD]
self._fallback = config_entry.options.get(
CONF_FALLBACK, CONST_OVERLAY_TADO_DEFAULT
)
self._debug = debug
self.home_id: int
@ -343,16 +346,19 @@ class TadoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]):
class TadoMobileDeviceUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]):
"""Class to manage the mobile devices from Tado via PyTado."""
config_entry: TadoConfigEntry
def __init__(
self,
hass: HomeAssistant,
entry: ConfigEntry,
config_entry: TadoConfigEntry,
tado: Tado,
) -> None:
"""Initialize the Tado data update coordinator."""
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=SCAN_MOBILE_DEVICE_INTERVAL,
)