Home Assistant Unofficial Reference 2024.12.1
siren.py
Go to the documentation of this file.
1 """Support for Overkiz sirens."""
2 
3 from typing import Any
4 
5 from pyoverkiz.enums import OverkizState
6 from pyoverkiz.enums.command import OverkizCommand, OverkizCommandParam
7 
9  ATTR_DURATION,
10  SirenEntity,
11  SirenEntityFeature,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.const import Platform
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 
18 from . import HomeAssistantOverkizData
19 from .const import DOMAIN
20 from .entity import OverkizEntity
21 
22 
24  hass: HomeAssistant,
25  entry: ConfigEntry,
26  async_add_entities: AddEntitiesCallback,
27 ) -> None:
28  """Set up the Overkiz sirens from a config entry."""
29  data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
30 
32  OverkizSiren(device.device_url, data.coordinator)
33  for device in data.platforms[Platform.SIREN]
34  )
35 
36 
38  """Representation an Overkiz Siren."""
39 
40  _attr_supported_features = (
41  SirenEntityFeature.TURN_OFF
42  | SirenEntityFeature.TURN_ON
43  | SirenEntityFeature.DURATION
44  )
45 
46  @property
47  def is_on(self) -> bool:
48  """Get whether the siren is in on state."""
49  return (
50  self.executorexecutor.select_state(OverkizState.CORE_ON_OFF)
51  == OverkizCommandParam.ON
52  )
53 
54  async def async_turn_on(self, **kwargs: Any) -> None:
55  """Send the on command."""
56  if kwargs.get(ATTR_DURATION):
57  duration = kwargs[ATTR_DURATION]
58  else:
59  duration = 2 * 60 # 2 minutes
60 
61  duration_in_ms = duration * 1000
62 
63  await self.executorexecutor.async_execute_command(
64  # https://www.tahomalink.com/enduser-mobile-web/steer-html5-client/vendor/somfy/io/siren/const.js
65  OverkizCommand.RING_WITH_SINGLE_SIMPLE_SEQUENCE,
66  duration_in_ms, # duration
67  75, # 90 seconds bip, 30 seconds silence
68  2, # repeat 3 times
69  OverkizCommandParam.MEMORIZED_VOLUME,
70  )
71 
72  async def async_turn_off(self, **kwargs: Any) -> None:
73  """Send the off command."""
74  await self.executorexecutor.async_execute_command(OverkizCommand.OFF)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: siren.py:27