Explicitly pass in the config_entry in overkiz coordinator (#138046)

explicitly pass in the config_entry in coordinator
pull/137224/head
Michael 2025-02-09 17:37:07 +01:00 committed by GitHub
parent d0e2a9e0bf
commit 6fe47a0f1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 14 deletions

View File

@ -39,7 +39,6 @@ from .const import (
LOGGER, LOGGER,
OVERKIZ_DEVICE_TO_PLATFORM, OVERKIZ_DEVICE_TO_PLATFORM,
PLATFORMS, PLATFORMS,
UPDATE_INTERVAL,
UPDATE_INTERVAL_ALL_ASSUMED_STATE, UPDATE_INTERVAL_ALL_ASSUMED_STATE,
UPDATE_INTERVAL_LOCAL, UPDATE_INTERVAL_LOCAL,
) )
@ -104,13 +103,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: OverkizDataConfigEntry)
coordinator = OverkizDataUpdateCoordinator( coordinator = OverkizDataUpdateCoordinator(
hass, hass,
entry,
LOGGER, LOGGER,
name="device events",
client=client, client=client,
devices=setup.devices, devices=setup.devices,
places=setup.root_place, places=setup.root_place,
update_interval=UPDATE_INTERVAL,
config_entry_id=entry.entry_id,
) )
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from collections.abc import Callable, Coroutine from collections.abc import Callable, Coroutine
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any from typing import TYPE_CHECKING, Any
from aiohttp import ClientConnectorError, ServerDisconnectedError from aiohttp import ClientConnectorError, ServerDisconnectedError
from pyoverkiz.client import OverkizClient from pyoverkiz.client import OverkizClient
@ -26,7 +26,10 @@ from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util.decorator import Registry from homeassistant.util.decorator import Registry
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES, LOGGER if TYPE_CHECKING:
from . import OverkizDataConfigEntry
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES, LOGGER, UPDATE_INTERVAL
EVENT_HANDLERS: Registry[ EVENT_HANDLERS: Registry[
str, Callable[[OverkizDataUpdateCoordinator, Event], Coroutine[Any, Any, None]] str, Callable[[OverkizDataUpdateCoordinator, Event], Coroutine[Any, Any, None]]
@ -36,26 +39,26 @@ EVENT_HANDLERS: Registry[
class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]): class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]):
"""Class to manage fetching data from Overkiz platform.""" """Class to manage fetching data from Overkiz platform."""
config_entry: OverkizDataConfigEntry
_default_update_interval: timedelta _default_update_interval: timedelta
def __init__( def __init__(
self, self,
hass: HomeAssistant, hass: HomeAssistant,
config_entry: OverkizDataConfigEntry,
logger: logging.Logger, logger: logging.Logger,
*, *,
name: str,
client: OverkizClient, client: OverkizClient,
devices: list[Device], devices: list[Device],
places: Place | None, places: Place | None,
update_interval: timedelta,
config_entry_id: str,
) -> None: ) -> None:
"""Initialize global data updater.""" """Initialize global data updater."""
super().__init__( super().__init__(
hass, hass,
logger, logger,
name=name, config_entry=config_entry,
update_interval=update_interval, name="device events",
update_interval=UPDATE_INTERVAL,
) )
self.data = {} self.data = {}
@ -63,8 +66,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]):
self.devices: dict[str, Device] = {d.device_url: d for d in devices} self.devices: dict[str, Device] = {d.device_url: d for d in devices}
self.executions: dict[str, dict[str, str]] = {} self.executions: dict[str, dict[str, str]] = {}
self.areas = self._places_to_area(places) if places else None self.areas = self._places_to_area(places) if places else None
self.config_entry_id = config_entry_id self._default_update_interval = UPDATE_INTERVAL
self._default_update_interval = update_interval
self.is_stateless = all( self.is_stateless = all(
device.protocol in (Protocol.RTS, Protocol.INTERNAL) device.protocol in (Protocol.RTS, Protocol.INTERNAL)
@ -164,7 +166,7 @@ async def on_device_created_updated(
) -> None: ) -> None:
"""Handle device unavailable / disabled event.""" """Handle device unavailable / disabled event."""
coordinator.hass.async_create_task( coordinator.hass.async_create_task(
coordinator.hass.config_entries.async_reload(coordinator.config_entry_id) coordinator.hass.config_entries.async_reload(coordinator.config_entry.entry_id)
) )