mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Streamline setup of deCONZ light platform (#70822)
This commit is contained in:
parent
195811843b
commit
bd8e705252
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, Generic, TypedDict, TypeVar
|
from typing import Any, Generic, TypedDict, TypeVar
|
||||||
|
|
||||||
from pydeconz.interfaces.lights import LightResources
|
|
||||||
from pydeconz.models import ResourceType
|
from pydeconz.models import ResourceType
|
||||||
from pydeconz.models.event import EventType
|
from pydeconz.models.event import EventType
|
||||||
from pydeconz.models.group import Group
|
from pydeconz.models.group import Group
|
||||||
@ -85,33 +84,32 @@ async def async_setup_entry(
|
|||||||
entity_registry.async_remove(entity_id)
|
entity_registry.async_remove(entity_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_light(lights: list[LightResources] | None = None) -> None:
|
def async_add_light(_: EventType, light_id: str) -> None:
|
||||||
"""Add light from deCONZ."""
|
"""Add light from deCONZ."""
|
||||||
entities = []
|
light = gateway.api.lights[light_id]
|
||||||
|
assert isinstance(light, Light)
|
||||||
|
if light.type in POWER_PLUGS:
|
||||||
|
return
|
||||||
|
|
||||||
if lights is None:
|
async_add_entities([DeconzLight(light, gateway)])
|
||||||
lights = gateway.api.lights.values()
|
|
||||||
|
|
||||||
for light in lights:
|
|
||||||
if (
|
|
||||||
isinstance(light, Light)
|
|
||||||
and light.type not in POWER_PLUGS
|
|
||||||
and light.unique_id not in gateway.entities[DOMAIN]
|
|
||||||
):
|
|
||||||
entities.append(DeconzLight(light, gateway))
|
|
||||||
|
|
||||||
if entities:
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
config_entry.async_on_unload(
|
config_entry.async_on_unload(
|
||||||
async_dispatcher_connect(
|
gateway.api.lights.lights.subscribe(
|
||||||
hass,
|
|
||||||
gateway.signal_new_light,
|
|
||||||
async_add_light,
|
async_add_light,
|
||||||
|
EventType.ADDED,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
for light_id in gateway.api.lights.lights:
|
||||||
|
async_add_light(EventType.ADDED, light_id)
|
||||||
|
|
||||||
async_add_light()
|
config_entry.async_on_unload(
|
||||||
|
gateway.api.lights.fans.subscribe(
|
||||||
|
async_add_light,
|
||||||
|
EventType.ADDED,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for light_id in gateway.api.lights.fans:
|
||||||
|
async_add_light(EventType.ADDED, light_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_group(_: EventType, group_id: str) -> None:
|
def async_add_group(_: EventType, group_id: str) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user