Home Assistant Unofficial Reference 2024.12.1
siren.py
Go to the documentation of this file.
1 """Representation of a sirenBinary."""
2 
3 from typing import Any
4 
5 from homeassistant.components.siren import SirenEntity, SirenEntityFeature
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant, callback
8 from homeassistant.helpers.dispatcher import async_dispatcher_connect
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 
11 from .const import DOMAIN, ZWaveMePlatform
12 from .entity import ZWaveMeEntity
13 
14 DEVICE_NAME = ZWaveMePlatform.SIREN
15 
16 
18  hass: HomeAssistant,
19  config_entry: ConfigEntry,
20  async_add_entities: AddEntitiesCallback,
21 ) -> None:
22  """Set up the siren platform."""
23 
24  @callback
25  def add_new_device(new_device):
26  controller = hass.data[DOMAIN][config_entry.entry_id]
27  siren = ZWaveMeSiren(controller, new_device)
28 
30  [
31  siren,
32  ]
33  )
34 
35  config_entry.async_on_unload(
37  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
38  )
39  )
40 
41 
43  """Representation of a ZWaveMe siren."""
44 
45  def __init__(self, controller, device):
46  """Initialize the device."""
47  super().__init__(controller, device)
48  self._attr_supported_features_attr_supported_features = (
49  SirenEntityFeature.TURN_ON | SirenEntityFeature.TURN_OFF
50  )
51 
52  @property
53  def is_on(self) -> bool:
54  """Return the state of the siren."""
55  return self.devicedevice.level == "on"
56 
57  def turn_on(self, **kwargs: Any) -> None:
58  """Turn the entity on."""
59  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "on")
60 
61  def turn_off(self, **kwargs: Any) -> None:
62  """Turn the entity off."""
63  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "off")
def __init__(self, controller, device)
Definition: siren.py:45
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: siren.py:21
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103