2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Abode Security System alarm control panels."""
|
2017-08-20 14:55:48 +00:00
|
|
|
import logging
|
|
|
|
|
2019-01-30 21:02:23 +00:00
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ATTRIBUTION,
|
|
|
|
STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_ARMED_HOME,
|
|
|
|
STATE_ALARM_DISARMED,
|
|
|
|
)
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import ATTRIBUTION, DOMAIN as ABODE_DOMAIN, AbodeDevice
|
|
|
|
|
2017-08-20 14:55:48 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ICON = "mdi:security"
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Set up an alarm control panel for an Abode device."""
|
2017-09-18 15:39:41 +00:00
|
|
|
data = hass.data[ABODE_DOMAIN]
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2017-09-18 15:39:41 +00:00
|
|
|
alarm_devices = [AbodeAlarm(data, data.abode.get_alarm(), data.name)]
|
|
|
|
|
|
|
|
data.devices.extend(alarm_devices)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(alarm_devices)
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
|
2019-01-30 21:02:23 +00:00
|
|
|
class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanel):
|
2017-08-20 14:55:48 +00:00
|
|
|
"""An alarm_control_panel implementation for Abode."""
|
|
|
|
|
2017-09-18 15:39:41 +00:00
|
|
|
def __init__(self, data, device, name):
|
2017-08-20 14:55:48 +00:00
|
|
|
"""Initialize the alarm control panel."""
|
2017-09-18 15:39:41 +00:00
|
|
|
super().__init__(data, device)
|
|
|
|
self._name = name
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Return the icon."""
|
2017-08-20 14:55:48 +00:00
|
|
|
return ICON
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
2017-08-29 15:34:19 +00:00
|
|
|
if self._device.is_standby:
|
2017-08-21 20:20:38 +00:00
|
|
|
state = STATE_ALARM_DISARMED
|
2017-08-29 15:34:19 +00:00
|
|
|
elif self._device.is_away:
|
2017-08-21 20:20:38 +00:00
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
2017-08-29 15:34:19 +00:00
|
|
|
elif self._device.is_home:
|
2017-08-21 20:20:38 +00:00
|
|
|
state = STATE_ALARM_ARMED_HOME
|
|
|
|
else:
|
|
|
|
state = None
|
|
|
|
return state
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
def alarm_disarm(self, code=None):
|
|
|
|
"""Send disarm command."""
|
2017-08-21 20:20:38 +00:00
|
|
|
self._device.set_standby()
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
def alarm_arm_home(self, code=None):
|
|
|
|
"""Send arm home command."""
|
2017-08-21 20:20:38 +00:00
|
|
|
self._device.set_home()
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
def alarm_arm_away(self, code=None):
|
|
|
|
"""Send arm away command."""
|
2017-08-21 20:20:38 +00:00
|
|
|
self._device.set_away()
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2017-09-18 15:39:41 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the alarm."""
|
|
|
|
return self._name or super().name
|
|
|
|
|
2017-08-29 15:34:19 +00:00
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes."""
|
|
|
|
return {
|
2019-02-14 21:09:22 +00:00
|
|
|
ATTR_ATTRIBUTION: ATTRIBUTION,
|
2019-07-31 19:25:30 +00:00
|
|
|
"device_id": self._device.device_id,
|
|
|
|
"battery_backup": self._device.battery,
|
|
|
|
"cellular_backup": self._device.is_cellular,
|
2017-08-29 15:34:19 +00:00
|
|
|
}
|