core/homeassistant/components/abode/alarm_control_panel.py

77 lines
2.3 KiB
Python
Raw Normal View History

"""Support for Abode Security System alarm control panels."""
2022-01-10 14:54:09 +00:00
from __future__ import annotations
2024-03-12 17:38:57 +00:00
from jaraco.abode.devices.alarm import Alarm
2022-01-10 14:54:09 +00:00
2024-03-12 17:38:57 +00:00
from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
2019-07-31 19:25:30 +00:00
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_DISARMED,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AbodeSystem
from .const import DOMAIN
from .entity import AbodeDevice
async def async_setup_entry(
2022-01-10 14:54:09 +00:00
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up Abode alarm control panel device."""
2022-01-10 14:54:09 +00:00
data: AbodeSystem = hass.data[DOMAIN]
async_add_entities(
[AbodeAlarm(data, await hass.async_add_executor_job(data.abode.get_alarm))]
)
2024-03-12 17:38:57 +00:00
class AbodeAlarm(AbodeDevice, AlarmControlPanelEntity):
"""An alarm_control_panel implementation for Abode."""
_attr_name = None
_attr_code_arm_required = False
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)
2024-03-12 17:38:57 +00:00
_device: Alarm
@property
2022-01-10 14:54:09 +00:00
def state(self) -> str | None:
"""Return the state of the device."""
if self._device.is_standby:
2022-01-10 14:54:09 +00:00
return STATE_ALARM_DISARMED
if self._device.is_away:
return STATE_ALARM_ARMED_AWAY
if self._device.is_home:
return STATE_ALARM_ARMED_HOME
return None
2022-01-10 14:54:09 +00:00
def alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
self._device.set_standby()
2022-01-10 14:54:09 +00:00
def alarm_arm_home(self, code: str | None = None) -> None:
"""Send arm home command."""
self._device.set_home()
2022-01-10 14:54:09 +00:00
def alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command."""
self._device.set_away()
@property
2022-01-10 14:54:09 +00:00
def extra_state_attributes(self) -> dict[str, str]:
"""Return the state attributes."""
return {
2023-08-03 07:10:31 +00:00
"device_id": self._device.id,
2019-07-31 19:25:30 +00:00
"battery_backup": self._device.battery,
"cellular_backup": self._device.is_cellular,
}