mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +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 pydeconz.models.event import EventType
|
||||
from pydeconz.models.light.siren import Siren
|
||||
|
||||
from homeassistant.components.siren import (
|
||||
@ -13,7 +14,6 @@ from homeassistant.components.siren import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .deconz_device import DeconzDevice
|
||||
@ -30,33 +30,19 @@ async def async_setup_entry(
|
||||
gateway.entities[DOMAIN] = set()
|
||||
|
||||
@callback
|
||||
def async_add_siren(lights: list[Siren] | None = None) -> None:
|
||||
def async_add_siren(_: EventType, siren_id: str) -> None:
|
||||
"""Add siren from deCONZ."""
|
||||
entities = []
|
||||
|
||||
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)
|
||||
siren = gateway.api.lights.sirens[siren_id]
|
||||
async_add_entities([DeconzSiren(siren, gateway)])
|
||||
|
||||
config_entry.async_on_unload(
|
||||
async_dispatcher_connect(
|
||||
hass,
|
||||
gateway.signal_new_light,
|
||||
gateway.api.lights.sirens.subscribe(
|
||||
async_add_siren,
|
||||
EventType.ADDED,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_siren()
|
||||
for siren_id in gateway.api.lights.sirens:
|
||||
async_add_siren(EventType.ADDED, siren_id)
|
||||
|
||||
|
||||
class DeconzSiren(DeconzDevice, SirenEntity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user