mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Streamline setup of deCONZ siren platform (#71660)
This commit is contained in:
parent
db17d7aecf
commit
44f8c555a6
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from pydeconz.models.event import EventType
|
||||||
from pydeconz.models.light.siren import Siren
|
from pydeconz.models.light.siren import Siren
|
||||||
|
|
||||||
from homeassistant.components.siren import (
|
from homeassistant.components.siren import (
|
||||||
@ -13,7 +14,6 @@ from homeassistant.components.siren import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
@ -30,33 +30,19 @@ async def async_setup_entry(
|
|||||||
gateway.entities[DOMAIN] = set()
|
gateway.entities[DOMAIN] = set()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_siren(lights: list[Siren] | None = None) -> None:
|
def async_add_siren(_: EventType, siren_id: str) -> None:
|
||||||
"""Add siren from deCONZ."""
|
"""Add siren from deCONZ."""
|
||||||
entities = []
|
siren = gateway.api.lights.sirens[siren_id]
|
||||||
|
async_add_entities([DeconzSiren(siren, gateway)])
|
||||||
if lights is None:
|
|
||||||
lights = list(gateway.api.lights.sirens.values())
|
|
||||||
|
|
||||||
for light in lights:
|
|
||||||
|
|
||||||
if (
|
|
||||||
isinstance(light, Siren)
|
|
||||||
and light.unique_id not in gateway.entities[DOMAIN]
|
|
||||||
):
|
|
||||||
entities.append(DeconzSiren(light, gateway))
|
|
||||||
|
|
||||||
if entities:
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
config_entry.async_on_unload(
|
config_entry.async_on_unload(
|
||||||
async_dispatcher_connect(
|
gateway.api.lights.sirens.subscribe(
|
||||||
hass,
|
|
||||||
gateway.signal_new_light,
|
|
||||||
async_add_siren,
|
async_add_siren,
|
||||||
|
EventType.ADDED,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
for siren_id in gateway.api.lights.sirens:
|
||||||
async_add_siren()
|
async_add_siren(EventType.ADDED, siren_id)
|
||||||
|
|
||||||
|
|
||||||
class DeconzSiren(DeconzDevice, SirenEntity):
|
class DeconzSiren(DeconzDevice, SirenEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user