Home Assistant Unofficial Reference 2024.12.1
alarm_control_panel.py
Go to the documentation of this file.
1 """Support for HomematicIP Cloud alarm control panel."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homematicip.functionalHomes import SecurityAndAlarmHome
8 
10  AlarmControlPanelEntity,
11  AlarmControlPanelEntityFeature,
12  AlarmControlPanelState,
13 )
14 from homeassistant.config_entries import ConfigEntry
15 from homeassistant.core import HomeAssistant, callback
16 from homeassistant.helpers.device_registry import DeviceInfo
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from .const import DOMAIN
20 from .hap import AsyncHome, HomematicipHAP
21 
22 _LOGGER = logging.getLogger(__name__)
23 
24 CONST_ALARM_CONTROL_PANEL_NAME = "HmIP Alarm Control Panel"
25 
26 
28  hass: HomeAssistant,
29  config_entry: ConfigEntry,
30  async_add_entities: AddEntitiesCallback,
31 ) -> None:
32  """Set up the HomematicIP alrm control panel from a config entry."""
33  hap = hass.data[DOMAIN][config_entry.unique_id]
35 
36 
38  """Representation of the HomematicIP alarm control panel."""
39 
40  _attr_should_poll = False
41  _attr_supported_features = (
42  AlarmControlPanelEntityFeature.ARM_HOME
43  | AlarmControlPanelEntityFeature.ARM_AWAY
44  )
45  _attr_code_arm_required = False
46 
47  def __init__(self, hap: HomematicipHAP) -> None:
48  """Initialize the alarm control panel."""
49  self._home: AsyncHome = hap.home
50 
51  @property
52  def device_info(self) -> DeviceInfo:
53  """Return device specific attributes."""
54  return DeviceInfo(
55  identifiers={(DOMAIN, f"ACP {self._home.id}")},
56  manufacturer="eQ-3",
57  model=CONST_ALARM_CONTROL_PANEL_NAME,
58  name=self.namenamename,
59  via_device=(DOMAIN, self._home.id),
60  )
61 
62  @property
63  def alarm_state(self) -> AlarmControlPanelState:
64  """Return the state of the alarm control panel."""
65  # check for triggered alarm
66  if self._security_and_alarm_security_and_alarm.alarmActive:
67  return AlarmControlPanelState.TRIGGERED
68 
69  activation_state = self._home.get_security_zones_activation()
70  # check arm_away
71  if activation_state == (True, True):
72  return AlarmControlPanelState.ARMED_AWAY
73  # check arm_home
74  if activation_state == (False, True):
75  return AlarmControlPanelState.ARMED_HOME
76 
77  return AlarmControlPanelState.DISARMED
78 
79  @property
80  def _security_and_alarm(self) -> SecurityAndAlarmHome:
81  return self._home.get_functionalHome(SecurityAndAlarmHome)
82 
83  async def async_alarm_disarm(self, code: str | None = None) -> None:
84  """Send disarm command."""
85  await self._home.set_security_zones_activation(False, False)
86 
87  async def async_alarm_arm_home(self, code: str | None = None) -> None:
88  """Send arm home command."""
89  await self._home.set_security_zones_activation(False, True)
90 
91  async def async_alarm_arm_away(self, code: str | None = None) -> None:
92  """Send arm away command."""
93  await self._home.set_security_zones_activation(True, True)
94 
95  async def async_added_to_hass(self) -> None:
96  """Register callbacks."""
97  self._home.on_update(self._async_device_changed_async_device_changed)
98 
99  @callback
100  def _async_device_changed(self, *args, **kwargs) -> None:
101  """Handle entity state changes."""
102  # Don't update disabled entities
103  if self.enabledenabled:
104  _LOGGER.debug("Event %s (%s)", self.namenamename, CONST_ALARM_CONTROL_PANEL_NAME)
105  self.async_write_ha_stateasync_write_ha_state()
106  else:
107  _LOGGER.debug(
108  (
109  "Device Changed Event for %s (Alarm Control Panel) not fired."
110  " Entity is disabled"
111  ),
112  self.namenamename,
113  )
114 
115  @property
116  def name(self) -> str:
117  """Return the name of the generic entity."""
118  name = CONST_ALARM_CONTROL_PANEL_NAME
119  if self._home.name:
120  name = f"{self._home.name} {name}"
121  return name
122 
123  @property
124  def available(self) -> bool:
125  """Return if alarm control panel is available."""
126  return self._home.connected
127 
128  @property
129  def unique_id(self) -> str:
130  """Return a unique ID."""
131  return f"{self.__class__.__name__}_{self._home.id}"
str|UndefinedType|None name(self)
Definition: entity.py:738
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)