Home Assistant Unofficial Reference 2024.12.1
alarm_control_panel.py
Go to the documentation of this file.
1 """Support for Freebox alarms."""
2 
3 from typing import Any
4 
6  AlarmControlPanelEntity,
7  AlarmControlPanelEntityFeature,
8  AlarmControlPanelState,
9 )
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from .const import DOMAIN, FreeboxHomeCategory
15 from .entity import FreeboxHomeEntity
16 from .router import FreeboxRouter
17 
18 FREEBOX_TO_STATUS = {
19  "alarm1_arming": AlarmControlPanelState.ARMING,
20  "alarm2_arming": AlarmControlPanelState.ARMING,
21  "alarm1_armed": AlarmControlPanelState.ARMED_AWAY,
22  "alarm2_armed": AlarmControlPanelState.ARMED_HOME,
23  "alarm1_alert_timer": AlarmControlPanelState.TRIGGERED,
24  "alarm2_alert_timer": AlarmControlPanelState.TRIGGERED,
25  "alert": AlarmControlPanelState.TRIGGERED,
26  "idle": AlarmControlPanelState.DISARMED,
27 }
28 
29 
31  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
32 ) -> None:
33  """Set up alarm panel."""
34  router: FreeboxRouter = hass.data[DOMAIN][entry.unique_id]
35 
37  (
38  FreeboxAlarm(hass, router, node)
39  for node in router.home_devices.values()
40  if node["category"] == FreeboxHomeCategory.ALARM
41  ),
42  True,
43  )
44 
45 
47  """Representation of a Freebox alarm."""
48 
49  _attr_code_arm_required = False
50 
51  def __init__(
52  self, hass: HomeAssistant, router: FreeboxRouter, node: dict[str, Any]
53  ) -> None:
54  """Initialize an alarm."""
55  super().__init__(hass, router, node)
56 
57  # Commands
58  self._command_trigger_command_trigger = self.get_command_idget_command_id(
59  node["type"]["endpoints"], "slot", "trigger"
60  )
61  self._command_arm_away_command_arm_away = self.get_command_idget_command_id(
62  node["type"]["endpoints"], "slot", "alarm1"
63  )
64  self._command_arm_home_command_arm_home = self.get_command_idget_command_id(
65  node["type"]["endpoints"], "slot", "alarm2"
66  )
67  self._command_disarm_command_disarm = self.get_command_idget_command_id(
68  node["type"]["endpoints"], "slot", "off"
69  )
70  self._command_state_command_state = self.get_command_idget_command_id(
71  node["type"]["endpoints"], "signal", "state"
72  )
73 
74  self._attr_supported_features_attr_supported_features = (
75  AlarmControlPanelEntityFeature.ARM_AWAY
76  | (AlarmControlPanelEntityFeature.ARM_HOME if self._command_arm_home_command_arm_home else 0)
77  | AlarmControlPanelEntityFeature.TRIGGER
78  )
79 
80  async def async_alarm_disarm(self, code: str | None = None) -> None:
81  """Send disarm command."""
82  await self.set_home_endpoint_valueset_home_endpoint_value(self._command_disarm_command_disarm)
83 
84  async def async_alarm_arm_away(self, code: str | None = None) -> None:
85  """Send arm away command."""
86  await self.set_home_endpoint_valueset_home_endpoint_value(self._command_arm_away_command_arm_away)
87 
88  async def async_alarm_arm_home(self, code: str | None = None) -> None:
89  """Send arm home command."""
90  await self.set_home_endpoint_valueset_home_endpoint_value(self._command_arm_home_command_arm_home)
91 
92  async def async_alarm_trigger(self, code: str | None = None) -> None:
93  """Send alarm trigger command."""
94  await self.set_home_endpoint_valueset_home_endpoint_value(self._command_trigger_command_trigger)
95 
96  async def async_update(self) -> None:
97  """Update state."""
98  state: str | None = await self.get_home_endpoint_valueget_home_endpoint_value(self._command_state_command_state)
99  if state:
100  self._attr_alarm_state_attr_alarm_state = FREEBOX_TO_STATUS.get(state)
101  else:
102  self._attr_alarm_state_attr_alarm_state = None
None __init__(self, HomeAssistant hass, FreeboxRouter router, dict[str, Any] node)
Any|None get_home_endpoint_value(self, Any command_id)
Definition: entity.py:95
int|None get_command_id(self, nodes, str ep_type, str name)
Definition: entity.py:104
bool set_home_endpoint_value(self, int|None command_id, bool|None value=None)
Definition: entity.py:84
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)