mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Streamline setup of deCONZ alarm control panel platform (#70589)
This commit is contained in:
parent
5b7bca1d82
commit
8330d7906a
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pydeconz.models.alarm_system import AlarmSystem
|
from pydeconz.models.alarm_system import AlarmSystem
|
||||||
|
from pydeconz.models.event import EventType
|
||||||
from pydeconz.models.sensor.ancillary_control import (
|
from pydeconz.models.sensor.ancillary_control import (
|
||||||
ANCILLARY_CONTROL_ARMED_AWAY,
|
ANCILLARY_CONTROL_ARMED_AWAY,
|
||||||
ANCILLARY_CONTROL_ARMED_NIGHT,
|
ANCILLARY_CONTROL_ARMED_NIGHT,
|
||||||
@ -33,7 +34,6 @@ from homeassistant.const import (
|
|||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
)
|
)
|
||||||
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
|
||||||
@ -68,50 +68,26 @@ async def async_setup_entry(
|
|||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the deCONZ alarm control panel devices.
|
"""Set up the deCONZ alarm control panel devices."""
|
||||||
|
|
||||||
Alarm control panels are based on the same device class as sensors in deCONZ.
|
|
||||||
"""
|
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||||
gateway.entities[DOMAIN] = set()
|
gateway.entities[DOMAIN] = set()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_alarm_control_panel(
|
def async_add_sensor(_: EventType, sensor_id: str) -> None:
|
||||||
sensors: list[AncillaryControl] | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Add alarm control panel devices from deCONZ."""
|
"""Add alarm control panel devices from deCONZ."""
|
||||||
entities = []
|
sensor = gateway.api.sensors.ancillary_control[sensor_id]
|
||||||
|
if alarm_system := get_alarm_system_for_unique_id(gateway, sensor.unique_id):
|
||||||
if sensors is None:
|
async_add_entities([DeconzAlarmControlPanel(sensor, gateway, alarm_system)])
|
||||||
sensors = list(gateway.api.sensors.ancillary_control.values())
|
|
||||||
|
|
||||||
for sensor in sensors:
|
|
||||||
|
|
||||||
if (
|
|
||||||
isinstance(sensor, AncillaryControl)
|
|
||||||
and sensor.unique_id not in gateway.entities[DOMAIN]
|
|
||||||
and (
|
|
||||||
alarm_system := get_alarm_system_for_unique_id(
|
|
||||||
gateway, sensor.unique_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
is not None
|
|
||||||
):
|
|
||||||
|
|
||||||
entities.append(DeconzAlarmControlPanel(sensor, gateway, alarm_system))
|
|
||||||
|
|
||||||
if entities:
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
config_entry.async_on_unload(
|
config_entry.async_on_unload(
|
||||||
async_dispatcher_connect(
|
gateway.api.sensors.ancillary_control.subscribe(
|
||||||
hass,
|
async_add_sensor,
|
||||||
gateway.signal_new_sensor,
|
EventType.ADDED,
|
||||||
async_add_alarm_control_panel,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_alarm_control_panel()
|
for sensor_id in gateway.api.sensors.ancillary_control:
|
||||||
|
async_add_sensor(EventType.ADDED, sensor_id)
|
||||||
|
|
||||||
|
|
||||||
class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity):
|
class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user