diff --git a/homeassistant/components/unifi/hub/entity_loader.py b/homeassistant/components/unifi/hub/entity_loader.py index a7a1cb970ece0d..5ae3e8f789c3c2 100644 --- a/homeassistant/components/unifi/hub/entity_loader.py +++ b/homeassistant/components/unifi/hub/entity_loader.py @@ -6,7 +6,6 @@ from __future__ import annotations import asyncio -from collections.abc import Iterable from datetime import timedelta from functools import partial from typing import TYPE_CHECKING @@ -143,42 +142,36 @@ def _load_entities( """Subscribe to UniFi API handlers and create entities.""" @callback - def async_load_entities(descriptions: Iterable[UnifiEntityDescription]) -> None: - """Load and subscribe to UniFi endpoints.""" + def _add_unifi_entities() -> None: + """Add UniFi entity.""" + async_add_entities( + unifi_platform_entity(obj_id, self.hub, description) + for description in descriptions + for obj_id in description.api_handler_fn(self.hub.api) + if self._should_add_entity(description, obj_id) + ) - @callback - def _add_unifi_entities() -> None: - """Add UniFi entity.""" - async_add_entities( - unifi_platform_entity(obj_id, self.hub, description) - for description in descriptions - for obj_id in description.api_handler_fn(self.hub.api) - if self._should_add_entity(description, obj_id) - ) + _add_unifi_entities() - _add_unifi_entities() - - @callback - def _create_unifi_entity( - description: UnifiEntityDescription, event: ItemEvent, obj_id: str - ) -> None: - """Create new UniFi entity on event.""" - if self._should_add_entity(description, obj_id): - async_add_entities( - [unifi_platform_entity(obj_id, self.hub, description)] - ) - - for description in descriptions: - description.api_handler_fn(self.hub.api).subscribe( - partial(_create_unifi_entity, description), ItemEvent.ADDED + @callback + def _create_unifi_entity( + description: UnifiEntityDescription, event: ItemEvent, obj_id: str + ) -> None: + """Create new UniFi entity on event.""" + if self._should_add_entity(description, obj_id): + async_add_entities( + [unifi_platform_entity(obj_id, self.hub, description)] ) - self.hub.config.entry.async_on_unload( - async_dispatcher_connect( - self.hub.hass, - self.hub.signal_options_update, - _add_unifi_entities, - ) + for description in descriptions: + description.api_handler_fn(self.hub.api).subscribe( + partial(_create_unifi_entity, description), ItemEvent.ADDED ) - async_load_entities(descriptions) + self.hub.config.entry.async_on_unload( + async_dispatcher_connect( + self.hub.hass, + self.hub.signal_options_update, + _add_unifi_entities, + ) + )