Explicitly pass in the config_entry in refoss coordinator (#137978)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 15:45:51 +01:00 committed by GitHub
parent 4706beb6ef
commit 2418ef8e8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

View File

@ -24,7 +24,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Refoss from a config entry."""
hass.data.setdefault(DOMAIN, {})
discover = await refoss_discovery_server(hass)
refoss_discovery = DiscoveryService(hass, discover)
refoss_discovery = DiscoveryService(hass, entry, discover)
hass.data[DOMAIN][DATA_DISCOVERY_SERVICE] = refoss_discovery
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View File

@ -6,6 +6,7 @@ from refoss_ha.device import DeviceInfo
from refoss_ha.device_manager import async_build_base_device
from refoss_ha.discovery import Discovery, Listener
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -16,9 +17,12 @@ from .coordinator import RefossDataUpdateCoordinator
class DiscoveryService(Listener):
"""Discovery event handler for refoss devices."""
def __init__(self, hass: HomeAssistant, discovery: Discovery) -> None:
def __init__(
self, hass: HomeAssistant, config_entry: ConfigEntry, discovery: Discovery
) -> None:
"""Init discovery service."""
self.hass = hass
self.config_entry = config_entry
self.discovery = discovery
self.discovery.add_listener(self)
@ -32,7 +36,7 @@ class DiscoveryService(Listener):
if device is None:
return
coordo = RefossDataUpdateCoordinator(self.hass, device)
coordo = RefossDataUpdateCoordinator(self.hass, self.config_entry, device)
self.hass.data[DOMAIN][COORDINATORS].append(coordo)
await coordo.async_refresh()

View File

@ -7,6 +7,7 @@ from datetime import timedelta
from refoss_ha.controller.device import BaseDevice
from refoss_ha.exceptions import DeviceTimeoutError
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
@ -16,11 +17,16 @@ from .const import _LOGGER, DOMAIN, MAX_ERRORS
class RefossDataUpdateCoordinator(DataUpdateCoordinator[None]):
"""Manages polling for state changes from the device."""
def __init__(self, hass: HomeAssistant, device: BaseDevice) -> None:
config_entry: ConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: ConfigEntry, device: BaseDevice
) -> None:
"""Initialize the data update coordinator."""
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=f"{DOMAIN}-{device.device_info.dev_name}",
update_interval=timedelta(seconds=15),
)