2021-09-18 19:59:04 +00:00
|
|
|
"""Support for deCONZ siren."""
|
2021-11-16 16:25:56 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
2022-05-11 11:30:16 +00:00
|
|
|
from pydeconz.models.event import EventType
|
2022-04-24 08:27:56 +00:00
|
|
|
from pydeconz.models.light.siren import Siren
|
2021-09-18 19:59:04 +00:00
|
|
|
|
|
|
|
from homeassistant.components.siren import (
|
|
|
|
ATTR_DURATION,
|
|
|
|
DOMAIN,
|
|
|
|
SirenEntity,
|
2022-04-08 07:13:12 +00:00
|
|
|
SirenEntityFeature,
|
2021-09-18 19:59:04 +00:00
|
|
|
)
|
2021-11-16 16:25:56 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-09-18 19:59:04 +00:00
|
|
|
|
|
|
|
from .deconz_device import DeconzDevice
|
2022-04-08 07:13:12 +00:00
|
|
|
from .gateway import get_gateway_from_config_entry
|
2021-09-18 19:59:04 +00:00
|
|
|
|
|
|
|
|
2021-11-16 16:25:56 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Set up sirens for deCONZ component."""
|
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
|
|
gateway.entities[DOMAIN] = set()
|
|
|
|
|
|
|
|
@callback
|
2022-05-11 11:30:16 +00:00
|
|
|
def async_add_siren(_: EventType, siren_id: str) -> None:
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Add siren from deCONZ."""
|
2022-05-11 11:30:16 +00:00
|
|
|
siren = gateway.api.lights.sirens[siren_id]
|
|
|
|
async_add_entities([DeconzSiren(siren, gateway)])
|
2021-09-18 19:59:04 +00:00
|
|
|
|
2022-05-25 03:48:09 +00:00
|
|
|
gateway.register_platform_add_device_callback(
|
|
|
|
async_add_siren,
|
|
|
|
gateway.api.lights.sirens,
|
2021-09-18 19:59:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-01 17:18:29 +00:00
|
|
|
class DeconzSiren(DeconzDevice[Siren], SirenEntity):
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Representation of a deCONZ siren."""
|
|
|
|
|
|
|
|
TYPE = DOMAIN
|
2022-04-08 07:13:12 +00:00
|
|
|
_attr_supported_features = (
|
|
|
|
SirenEntityFeature.TURN_ON
|
|
|
|
| SirenEntityFeature.TURN_OFF
|
|
|
|
| SirenEntityFeature.DURATION
|
|
|
|
)
|
2021-09-18 19:59:04 +00:00
|
|
|
|
|
|
|
@property
|
2021-11-16 16:25:56 +00:00
|
|
|
def is_on(self) -> bool:
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Return true if siren is on."""
|
2022-04-23 05:27:47 +00:00
|
|
|
return self._device.is_on
|
2021-09-18 19:59:04 +00:00
|
|
|
|
2021-11-16 16:25:56 +00:00
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Turn on siren."""
|
|
|
|
if (duration := kwargs.get(ATTR_DURATION)) is not None:
|
2022-06-21 14:50:44 +00:00
|
|
|
duration *= 10
|
|
|
|
await self.gateway.api.lights.sirens.set_state(
|
|
|
|
id=self._device.resource_id,
|
|
|
|
on=True,
|
|
|
|
duration=duration,
|
|
|
|
)
|
2021-09-18 19:59:04 +00:00
|
|
|
|
2021-11-16 16:25:56 +00:00
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
2021-09-18 19:59:04 +00:00
|
|
|
"""Turn off siren."""
|
2022-06-21 14:50:44 +00:00
|
|
|
await self.gateway.api.lights.sirens.set_state(
|
|
|
|
id=self._device.resource_id,
|
|
|
|
on=False,
|
|
|
|
)
|