mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move add Device tracker entities to UniFi controller (#84883)
This commit is contained in:
parent
45fbbbaea1
commit
a75bad3a83
@ -206,7 +206,7 @@ class UniFiController:
|
|||||||
"""Create UniFi entity."""
|
"""Create UniFi entity."""
|
||||||
if not description.allowed_fn(
|
if not description.allowed_fn(
|
||||||
self, obj_id
|
self, obj_id
|
||||||
) or not description.supported_fn(self.api, obj_id):
|
) or not description.supported_fn(self, obj_id):
|
||||||
return
|
return
|
||||||
|
|
||||||
entity = unifi_platform_entity(obj_id, self, description)
|
entity = unifi_platform_entity(obj_id, self, description)
|
||||||
|
@ -136,6 +136,10 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up device tracker for UniFi Network integration."""
|
"""Set up device tracker for UniFi Network integration."""
|
||||||
controller: UniFiController = hass.data[UNIFI_DOMAIN][config_entry.entry_id]
|
controller: UniFiController = hass.data[UNIFI_DOMAIN][config_entry.entry_id]
|
||||||
|
controller.register_platform_add_entities(
|
||||||
|
UnifiScannerEntity, ENTITY_DESCRIPTIONS, async_add_entities
|
||||||
|
)
|
||||||
|
|
||||||
controller.entities[DOMAIN] = {CLIENT_TRACKER: set(), DEVICE_TRACKER: set()}
|
controller.entities[DOMAIN] = {CLIENT_TRACKER: set(), DEVICE_TRACKER: set()}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -153,35 +157,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
items_added()
|
items_added()
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_load_entities(description: UnifiEntityDescription) -> None:
|
|
||||||
"""Load and subscribe to UniFi devices."""
|
|
||||||
entities: list[ScannerEntity] = []
|
|
||||||
api_handler = description.api_handler_fn(controller.api)
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_create_entity(event: ItemEvent, obj_id: str) -> None:
|
|
||||||
"""Create UniFi entity."""
|
|
||||||
if not description.allowed_fn(
|
|
||||||
controller, obj_id
|
|
||||||
) or not description.supported_fn(controller.api, obj_id):
|
|
||||||
return
|
|
||||||
|
|
||||||
entity = UnifiScannerEntity(obj_id, controller, description)
|
|
||||||
if event == ItemEvent.ADDED:
|
|
||||||
async_add_entities([entity])
|
|
||||||
return
|
|
||||||
entities.append(entity)
|
|
||||||
|
|
||||||
for obj_id in api_handler:
|
|
||||||
async_create_entity(ItemEvent.CHANGED, obj_id)
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
api_handler.subscribe(async_create_entity, ItemEvent.ADDED)
|
|
||||||
|
|
||||||
for description in ENTITY_DESCRIPTIONS:
|
|
||||||
async_load_entities(description)
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def add_client_entities(controller, async_add_entities, clients):
|
def add_client_entities(controller, async_add_entities, clients):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user