mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Explicitly pass in the config_entry in tplink_omada coordinator (#137895)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
d71a539fbc
commit
89e29dd14f
@ -55,7 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> boo
|
||||
) from ex
|
||||
|
||||
site_client = await client.get_site_client(OmadaSite("", entry.data[CONF_SITE]))
|
||||
controller = OmadaSiteController(hass, site_client)
|
||||
controller = OmadaSiteController(hass, entry, site_client)
|
||||
await controller.initialize_first_refresh()
|
||||
|
||||
entry.runtime_data = controller
|
||||
|
@ -1,10 +1,17 @@
|
||||
"""Controller for sharing Omada API coordinators between platforms."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from tplink_omada_client import OmadaSiteClient
|
||||
from tplink_omada_client.devices import OmadaSwitch
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import OmadaConfigEntry
|
||||
|
||||
from .coordinator import (
|
||||
OmadaClientsCoordinator,
|
||||
OmadaDevicesCoordinator,
|
||||
@ -21,15 +28,21 @@ class OmadaSiteController:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
) -> None:
|
||||
"""Create the controller."""
|
||||
self._hass = hass
|
||||
self._config_entry = config_entry
|
||||
self._omada_client = omada_client
|
||||
|
||||
self._switch_port_coordinators: dict[str, OmadaSwitchPortCoordinator] = {}
|
||||
self._devices_coordinator = OmadaDevicesCoordinator(hass, omada_client)
|
||||
self._clients_coordinator = OmadaClientsCoordinator(hass, omada_client)
|
||||
self._devices_coordinator = OmadaDevicesCoordinator(
|
||||
hass, config_entry, omada_client
|
||||
)
|
||||
self._clients_coordinator = OmadaClientsCoordinator(
|
||||
hass, config_entry, omada_client
|
||||
)
|
||||
|
||||
async def initialize_first_refresh(self) -> None:
|
||||
"""Initialize the all coordinators, and perform first refresh."""
|
||||
@ -39,7 +52,7 @@ class OmadaSiteController:
|
||||
gateway = next((d for d in devices if d.type == "gateway"), None)
|
||||
if gateway:
|
||||
self._gateway_coordinator = OmadaGatewayCoordinator(
|
||||
self._hass, self._omada_client, gateway.mac
|
||||
self._hass, self._config_entry, self._omada_client, gateway.mac
|
||||
)
|
||||
await self._gateway_coordinator.async_config_entry_first_refresh()
|
||||
|
||||
@ -56,7 +69,7 @@ class OmadaSiteController:
|
||||
"""Get coordinator for network port information of a given switch."""
|
||||
if switch.mac not in self._switch_port_coordinators:
|
||||
self._switch_port_coordinators[switch.mac] = OmadaSwitchPortCoordinator(
|
||||
self._hass, self._omada_client, switch
|
||||
self._hass, self._config_entry, self._omada_client, switch
|
||||
)
|
||||
|
||||
return self._switch_port_coordinators[switch.mac]
|
||||
|
@ -1,8 +1,11 @@
|
||||
"""Generic Omada API coordinator."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from tplink_omada_client import OmadaSiteClient, OmadaSwitchPortDetails
|
||||
from tplink_omada_client.clients import OmadaWirelessClient
|
||||
@ -12,6 +15,9 @@ from tplink_omada_client.exceptions import OmadaClientException
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import OmadaConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
POLL_SWITCH_PORT = 300
|
||||
@ -23,9 +29,12 @@ POLL_DEVICES = 300
|
||||
class OmadaCoordinator[_T](DataUpdateCoordinator[dict[str, _T]]):
|
||||
"""Coordinator for synchronizing bulk Omada data."""
|
||||
|
||||
config_entry: OmadaConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
name: str,
|
||||
poll_delay: int | None = 300,
|
||||
@ -34,6 +43,7 @@ class OmadaCoordinator[_T](DataUpdateCoordinator[dict[str, _T]]):
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=f"Omada API Data - {name}",
|
||||
update_interval=timedelta(seconds=poll_delay) if poll_delay else None,
|
||||
)
|
||||
@ -58,12 +68,17 @@ class OmadaSwitchPortCoordinator(OmadaCoordinator[OmadaSwitchPortDetails]):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
network_switch: OmadaSwitch,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(
|
||||
hass, omada_client, f"{network_switch.name} Ports", POLL_SWITCH_PORT
|
||||
hass,
|
||||
config_entry,
|
||||
omada_client,
|
||||
f"{network_switch.name} Ports",
|
||||
POLL_SWITCH_PORT,
|
||||
)
|
||||
self._network_switch = network_switch
|
||||
|
||||
@ -79,11 +94,12 @@ class OmadaGatewayCoordinator(OmadaCoordinator[OmadaGateway]):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
mac: str,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(hass, omada_client, "Gateway", POLL_GATEWAY)
|
||||
super().__init__(hass, config_entry, omada_client, "Gateway", POLL_GATEWAY)
|
||||
self.mac = mac
|
||||
|
||||
async def poll_update(self) -> dict[str, OmadaGateway]:
|
||||
@ -98,10 +114,11 @@ class OmadaDevicesCoordinator(OmadaCoordinator[OmadaListDevice]):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(hass, omada_client, "DeviceList", POLL_CLIENTS)
|
||||
super().__init__(hass, config_entry, omada_client, "DeviceList", POLL_CLIENTS)
|
||||
|
||||
async def poll_update(self) -> dict[str, OmadaListDevice]:
|
||||
"""Poll the site's current registered Omada devices."""
|
||||
@ -111,9 +128,14 @@ class OmadaDevicesCoordinator(OmadaCoordinator[OmadaListDevice]):
|
||||
class OmadaClientsCoordinator(OmadaCoordinator[OmadaWirelessClient]):
|
||||
"""Coordinator for getting details about the site's connected clients."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, omada_client: OmadaSiteClient) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: OmadaConfigEntry,
|
||||
omada_client: OmadaSiteClient,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(hass, omada_client, "ClientsList", POLL_CLIENTS)
|
||||
super().__init__(hass, config_entry, omada_client, "ClientsList", POLL_CLIENTS)
|
||||
|
||||
async def poll_update(self) -> dict[str, OmadaWirelessClient]:
|
||||
"""Poll the site's current active wi-fi clients."""
|
||||
|
@ -43,7 +43,9 @@ class OmadaFirmwareUpdateCoordinator(OmadaCoordinator[FirmwareUpdateStatus]): #
|
||||
devices_coordinator: OmadaDevicesCoordinator,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(hass, omada_client, "Firmware Updates", poll_delay=None)
|
||||
super().__init__(
|
||||
hass, config_entry, omada_client, "Firmware Updates", poll_delay=None
|
||||
)
|
||||
|
||||
self._devices_coordinator = devices_coordinator
|
||||
self._config_entry = config_entry
|
||||
|
Loading…
x
Reference in New Issue
Block a user