Tweak marking private methods in UniFi, no need to mark inner functio… (#113964)
parent
6800034d5a
commit
bbb80caed3
|
@ -61,11 +61,11 @@ class UnifiEntityLoader:
|
|||
|
||||
async def initialize(self) -> None:
|
||||
"""Initialize API data and extra client support."""
|
||||
await self.refresh_api_data()
|
||||
self.restore_inactive_clients()
|
||||
await self._refresh_api_data()
|
||||
self._restore_inactive_clients()
|
||||
self.wireless_clients.update_clients(set(self.hub.api.clients.values()))
|
||||
|
||||
async def refresh_api_data(self) -> None:
|
||||
async def _refresh_api_data(self) -> None:
|
||||
"""Refresh API data from network application."""
|
||||
results = await asyncio.gather(
|
||||
*[update() for update in self.api_updaters],
|
||||
|
@ -76,7 +76,7 @@ class UnifiEntityLoader:
|
|||
LOGGER.warning("Exception on update %s", result)
|
||||
|
||||
@callback
|
||||
def restore_inactive_clients(self) -> None:
|
||||
def _restore_inactive_clients(self) -> None:
|
||||
"""Restore inactive clients.
|
||||
|
||||
Provide inactive clients to device tracker and switch platform.
|
||||
|
@ -110,7 +110,7 @@ class UnifiEntityLoader:
|
|||
|
||||
@callback
|
||||
def load_entities(self) -> None:
|
||||
"""Populate UniFi platforms with entities."""
|
||||
"""Load entities into the registered UniFi platforms."""
|
||||
for (
|
||||
async_add_entities,
|
||||
entity_class,
|
||||
|
@ -125,7 +125,7 @@ class UnifiEntityLoader:
|
|||
def _should_add_entity(
|
||||
self, description: UnifiEntityDescription, obj_id: str
|
||||
) -> bool:
|
||||
"""Check if entity should be added."""
|
||||
"""Validate if entity is allowed and supported before creating it."""
|
||||
return bool(
|
||||
(description.key, obj_id) not in self.known_objects
|
||||
and description.allowed_fn(self.hub, obj_id)
|
||||
|
@ -139,11 +139,11 @@ class UnifiEntityLoader:
|
|||
descriptions: tuple[UnifiEntityDescription, ...],
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Subscribe to UniFi API handlers and create entities."""
|
||||
"""Load entities and subscribe for future entities."""
|
||||
|
||||
@callback
|
||||
def _add_unifi_entities() -> None:
|
||||
"""Add UniFi entity."""
|
||||
def add_unifi_entities() -> None:
|
||||
"""Add currently known UniFi entities."""
|
||||
async_add_entities(
|
||||
unifi_platform_entity(obj_id, self.hub, description)
|
||||
for description in descriptions
|
||||
|
@ -151,10 +151,20 @@ class UnifiEntityLoader:
|
|||
if self._should_add_entity(description, obj_id)
|
||||
)
|
||||
|
||||
_add_unifi_entities()
|
||||
add_unifi_entities()
|
||||
|
||||
self.hub.config.entry.async_on_unload(
|
||||
async_dispatcher_connect(
|
||||
self.hub.hass,
|
||||
self.hub.signal_options_update,
|
||||
add_unifi_entities,
|
||||
)
|
||||
)
|
||||
|
||||
# Subscribe for future entities
|
||||
|
||||
@callback
|
||||
def _create_unifi_entity(
|
||||
def create_unifi_entity(
|
||||
description: UnifiEntityDescription, event: ItemEvent, obj_id: str
|
||||
) -> None:
|
||||
"""Create new UniFi entity on event."""
|
||||
|
@ -165,13 +175,5 @@ class UnifiEntityLoader:
|
|||
|
||||
for description in descriptions:
|
||||
description.api_handler_fn(self.hub.api).subscribe(
|
||||
partial(_create_unifi_entity, description), ItemEvent.ADDED
|
||||
partial(create_unifi_entity, description), ItemEvent.ADDED
|
||||
)
|
||||
|
||||
self.hub.config.entry.async_on_unload(
|
||||
async_dispatcher_connect(
|
||||
self.hub.hass,
|
||||
self.hub.signal_options_update,
|
||||
_add_unifi_entities,
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue