Home Assistant Unofficial Reference 2024.12.1
alarm_control_panel.py
Go to the documentation of this file.
1 """Support for Lupusec System alarm control panels."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 
7 import lupupy
8 
10  AlarmControlPanelEntity,
11  AlarmControlPanelEntityFeature,
12  AlarmControlPanelState,
13 )
14 from homeassistant.config_entries import ConfigEntry
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.device_registry import DeviceInfo
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from . import DOMAIN
20 from .entity import LupusecDevice
21 
22 SCAN_INTERVAL = timedelta(seconds=2)
23 
24 
26  hass: HomeAssistant,
27  config_entry: ConfigEntry,
28  async_add_entities: AddEntitiesCallback,
29 ) -> None:
30  """Set up an alarm control panel for a Lupusec device."""
31  data = hass.data[DOMAIN][config_entry.entry_id]
32 
33  alarm = await hass.async_add_executor_job(data.get_alarm)
34 
35  async_add_entities([LupusecAlarm(data, alarm, config_entry.entry_id)])
36 
37 
39  """An alarm_control_panel implementation for Lupusec."""
40 
41  _attr_name = None
42  _attr_supported_features = (
43  AlarmControlPanelEntityFeature.ARM_HOME
44  | AlarmControlPanelEntityFeature.ARM_AWAY
45  )
46  _attr_code_arm_required = False
47 
48  def __init__(
49  self, data: lupupy.Lupusec, device: lupupy.devices.LupusecAlarm, entry_id: str
50  ) -> None:
51  """Initialize the LupusecAlarm class."""
52  super().__init__(device)
53  self._attr_unique_id_attr_unique_id_attr_unique_id = entry_id
54  self._attr_device_info_attr_device_info = DeviceInfo(
55  identifiers={(DOMAIN, entry_id)},
56  name=device.name,
57  manufacturer="Lupus Electronics",
58  model=f"Lupusec-XT{data.model}",
59  )
60 
61  @property
62  def alarm_state(self) -> AlarmControlPanelState | None:
63  """Return the state of the device."""
64  if self._device_device.is_standby:
65  state = AlarmControlPanelState.DISARMED
66  elif self._device_device.is_away:
67  state = AlarmControlPanelState.ARMED_AWAY
68  elif self._device_device.is_home:
69  state = AlarmControlPanelState.ARMED_HOME
70  elif self._device_device.is_alarm_triggered:
71  state = AlarmControlPanelState.TRIGGERED
72  else:
73  state = None
74  return state
75 
76  def alarm_arm_away(self, code: str | None = None) -> None:
77  """Send arm away command."""
78  self._device_device.set_away()
79 
80  def alarm_disarm(self, code: str | None = None) -> None:
81  """Send disarm command."""
82  self._device_device.set_standby()
83 
84  def alarm_arm_home(self, code: str | None = None) -> None:
85  """Send arm home command."""
86  self._device_device.set_home()
None __init__(self, lupupy.Lupusec data, lupupy.devices.LupusecAlarm device, str entry_id)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)