2017-08-20 10:55:48 -04:00
|
|
|
"""
|
|
|
|
This component provides HA alarm_control_panel support for Abode System.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/alarm_control_panel.abode/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.abode import (DATA_ABODE, DEFAULT_NAME)
|
2017-08-21 16:20:38 -04:00
|
|
|
from homeassistant.const import (STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED)
|
2017-08-20 10:55:48 -04:00
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
|
|
|
|
|
|
|
DEPENDENCIES = ['abode']
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
ICON = 'mdi:security'
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
"""Set up a sensor for an Abode device."""
|
|
|
|
data = hass.data.get(DATA_ABODE)
|
|
|
|
|
|
|
|
add_devices([AbodeAlarm(hass, data, data.abode.get_alarm())])
|
|
|
|
|
|
|
|
|
|
|
|
class AbodeAlarm(alarm.AlarmControlPanel):
|
|
|
|
"""An alarm_control_panel implementation for Abode."""
|
|
|
|
|
|
|
|
def __init__(self, hass, data, device):
|
|
|
|
"""Initialize the alarm control panel."""
|
|
|
|
super(AbodeAlarm, self).__init__()
|
|
|
|
self._device = device
|
|
|
|
self._name = "{0}".format(DEFAULT_NAME)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""Return the polling state."""
|
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return icon."""
|
|
|
|
return ICON
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
2017-08-21 16:20:38 -04:00
|
|
|
if self._device.mode == "standby":
|
|
|
|
state = STATE_ALARM_DISARMED
|
|
|
|
elif self._device.mode == "away":
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif self._device.mode == "home":
|
|
|
|
state = STATE_ALARM_ARMED_HOME
|
|
|
|
else:
|
|
|
|
state = None
|
|
|
|
return state
|
2017-08-20 10:55:48 -04:00
|
|
|
|
|
|
|
def alarm_disarm(self, code=None):
|
|
|
|
"""Send disarm command."""
|
2017-08-21 16:20:38 -04:00
|
|
|
self._device.set_standby()
|
2017-08-20 10:55:48 -04:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def alarm_arm_home(self, code=None):
|
|
|
|
"""Send arm home command."""
|
2017-08-21 16:20:38 -04:00
|
|
|
self._device.set_home()
|
2017-08-20 10:55:48 -04:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def alarm_arm_away(self, code=None):
|
|
|
|
"""Send arm away command."""
|
2017-08-21 16:20:38 -04:00
|
|
|
self._device.set_away()
|
2017-08-20 10:55:48 -04:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the device state."""
|
|
|
|
self._device.refresh()
|