Explicitly pass in the config_entry in letpot coordinator (#137759)

This commit is contained in:
Joris Pelgröm 2025-02-07 23:56:48 +01:00 committed by GitHub
parent fd1213b70d
commit 07fdec76e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 14 deletions

View File

@ -9,7 +9,6 @@ from letpot.converters import CONVERTERS
from letpot.exceptions import LetPotAuthenticationException, LetPotException from letpot.exceptions import LetPotAuthenticationException, LetPotException
from letpot.models import AuthenticationInfo from letpot.models import AuthenticationInfo
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL, Platform from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
@ -21,12 +20,10 @@ from .const import (
CONF_REFRESH_TOKEN_EXPIRES, CONF_REFRESH_TOKEN_EXPIRES,
CONF_USER_ID, CONF_USER_ID,
) )
from .coordinator import LetPotDeviceCoordinator from .coordinator import LetPotConfigEntry, LetPotDeviceCoordinator
PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.TIME] PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.TIME]
type LetPotConfigEntry = ConfigEntry[list[LetPotDeviceCoordinator]]
async def async_setup_entry(hass: HomeAssistant, entry: LetPotConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: LetPotConfigEntry) -> bool:
"""Set up LetPot from a config entry.""" """Set up LetPot from a config entry."""
@ -67,7 +64,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LetPotConfigEntry) -> bo
raise ConfigEntryNotReady from exc raise ConfigEntryNotReady from exc
coordinators: list[LetPotDeviceCoordinator] = [ coordinators: list[LetPotDeviceCoordinator] = [
LetPotDeviceCoordinator(hass, auth, device) LetPotDeviceCoordinator(hass, entry, auth, device)
for device in devices for device in devices
if any(converter.supports_type(device.device_type) for converter in CONVERTERS) if any(converter.supports_type(device.device_type) for converter in CONVERTERS)
] ]

View File

@ -4,23 +4,22 @@ from __future__ import annotations
import asyncio import asyncio
import logging import logging
from typing import TYPE_CHECKING
from letpot.deviceclient import LetPotDeviceClient from letpot.deviceclient import LetPotDeviceClient
from letpot.exceptions import LetPotAuthenticationException, LetPotException from letpot.exceptions import LetPotAuthenticationException, LetPotException
from letpot.models import AuthenticationInfo, LetPotDevice, LetPotDeviceStatus from letpot.models import AuthenticationInfo, LetPotDevice, LetPotDeviceStatus
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import REQUEST_UPDATE_TIMEOUT from .const import REQUEST_UPDATE_TIMEOUT
if TYPE_CHECKING:
from . import LetPotConfigEntry
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
type LetPotConfigEntry = ConfigEntry[list[LetPotDeviceCoordinator]]
class LetPotDeviceCoordinator(DataUpdateCoordinator[LetPotDeviceStatus]): class LetPotDeviceCoordinator(DataUpdateCoordinator[LetPotDeviceStatus]):
"""Class to handle data updates for a specific garden.""" """Class to handle data updates for a specific garden."""
@ -31,12 +30,17 @@ class LetPotDeviceCoordinator(DataUpdateCoordinator[LetPotDeviceStatus]):
device_client: LetPotDeviceClient device_client: LetPotDeviceClient
def __init__( def __init__(
self, hass: HomeAssistant, info: AuthenticationInfo, device: LetPotDevice self,
hass: HomeAssistant,
config_entry: LetPotConfigEntry,
info: AuthenticationInfo,
device: LetPotDevice,
) -> None: ) -> None:
"""Initialize coordinator.""" """Initialize coordinator."""
super().__init__( super().__init__(
hass, hass,
_LOGGER, _LOGGER,
config_entry=config_entry,
name=f"LetPot {device.serial_number}", name=f"LetPot {device.serial_number}",
) )
self._info = info self._info = info

View File

@ -12,8 +12,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import LetPotConfigEntry from .coordinator import LetPotConfigEntry, LetPotDeviceCoordinator
from .coordinator import LetPotDeviceCoordinator
from .entity import LetPotEntity, exception_handler from .entity import LetPotEntity, exception_handler
# Each change pushes a 'full' device status with the change. The library will cache # Each change pushes a 'full' device status with the change. The library will cache

View File

@ -13,8 +13,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import LetPotConfigEntry from .coordinator import LetPotConfigEntry, LetPotDeviceCoordinator
from .coordinator import LetPotDeviceCoordinator
from .entity import LetPotEntity, exception_handler from .entity import LetPotEntity, exception_handler
# Each change pushes a 'full' device status with the change. The library will cache # Each change pushes a 'full' device status with the change. The library will cache