mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Give the UniFi integration better control over what data to load (#112804)
This commit is contained in:
parent
2b0b3c238a
commit
bf5537eb5a
@ -5,6 +5,7 @@ Make sure expected clients are available for platforms.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -16,6 +17,7 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from ..const import LOGGER
|
||||||
from ..entity import UnifiEntity, UnifiEntityDescription
|
from ..entity import UnifiEntity, UnifiEntityDescription
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -30,6 +32,17 @@ class UnifiEntityLoader:
|
|||||||
def __init__(self, hub: UnifiHub) -> None:
|
def __init__(self, hub: UnifiHub) -> None:
|
||||||
"""Initialize the UniFi entity loader."""
|
"""Initialize the UniFi entity loader."""
|
||||||
self.hub = hub
|
self.hub = hub
|
||||||
|
self.api_updaters = (
|
||||||
|
hub.api.clients.update,
|
||||||
|
hub.api.clients_all.update,
|
||||||
|
hub.api.devices.update,
|
||||||
|
hub.api.dpi_apps.update,
|
||||||
|
hub.api.dpi_groups.update,
|
||||||
|
hub.api.port_forwarding.update,
|
||||||
|
hub.api.sites.update,
|
||||||
|
hub.api.system_information.update,
|
||||||
|
hub.api.wlans.update,
|
||||||
|
)
|
||||||
|
|
||||||
self.platforms: list[
|
self.platforms: list[
|
||||||
tuple[
|
tuple[
|
||||||
@ -43,6 +56,16 @@ class UnifiEntityLoader:
|
|||||||
self.known_objects: set[tuple[str, str]] = set()
|
self.known_objects: set[tuple[str, str]] = set()
|
||||||
"""Tuples of entity description key and object ID of loaded entities."""
|
"""Tuples of entity description key and object ID of loaded entities."""
|
||||||
|
|
||||||
|
async def refresh_api_data(self) -> None:
|
||||||
|
"""Refresh API data from network application."""
|
||||||
|
results = await asyncio.gather(
|
||||||
|
*[update() for update in self.api_updaters],
|
||||||
|
return_exceptions=True,
|
||||||
|
)
|
||||||
|
for result in results:
|
||||||
|
if result is not None:
|
||||||
|
LOGGER.warning("Exception on update %s", result)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def register_platform(
|
def register_platform(
|
||||||
self,
|
self,
|
||||||
|
@ -88,7 +88,7 @@ class UnifiHub:
|
|||||||
|
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
"""Set up a UniFi Network instance."""
|
"""Set up a UniFi Network instance."""
|
||||||
await self.api.initialize()
|
await self.entity_loader.refresh_api_data()
|
||||||
|
|
||||||
assert self.config.entry.unique_id is not None
|
assert self.config.entry.unique_id is not None
|
||||||
self.is_admin = self.api.sites[self.config.entry.unique_id].role == "admin"
|
self.is_admin = self.api.sites[self.config.entry.unique_id].role == "admin"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user