2015-09-13 05:42:38 +00:00
|
|
|
"""
|
2015-09-13 18:21:02 +00:00
|
|
|
homeassistant.components.alarm_control_panel.verisure
|
2015-09-13 05:42:38 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-09-13 18:21:02 +00:00
|
|
|
Interfaces with Verisure alarm control panel.
|
2015-09-13 05:42:38 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.verisure as verisure
|
2015-09-13 18:21:02 +00:00
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
2015-09-13 05:42:38 +00:00
|
|
|
|
2015-09-13 18:21:02 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
STATE_UNKNOWN,
|
|
|
|
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY)
|
2015-09-13 05:42:38 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
""" Sets up the Verisure platform. """
|
|
|
|
|
|
|
|
if not verisure.MY_PAGES:
|
|
|
|
_LOGGER.error('A connection has not been made to Verisure mypages.')
|
|
|
|
return False
|
|
|
|
|
|
|
|
alarms = []
|
|
|
|
|
|
|
|
alarms.extend([
|
|
|
|
VerisureAlarm(value)
|
|
|
|
for value in verisure.get_alarm_status().values()
|
|
|
|
if verisure.SHOW_ALARM
|
|
|
|
])
|
|
|
|
|
|
|
|
add_devices(alarms)
|
|
|
|
|
|
|
|
|
2015-09-13 18:21:02 +00:00
|
|
|
class VerisureAlarm(alarm.AlarmControlPanel):
|
2015-09-13 05:42:38 +00:00
|
|
|
""" represents a Verisure alarm status within home assistant. """
|
|
|
|
|
|
|
|
def __init__(self, alarm_status):
|
|
|
|
self._id = alarm_status.id
|
|
|
|
self._device = verisure.MY_PAGES.DEVICE_ALARM
|
|
|
|
self._state = STATE_UNKNOWN
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the device. """
|
|
|
|
return 'Alarm {}'.format(self._id)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the device. """
|
2015-09-14 15:33:43 +00:00
|
|
|
return self._state
|
|
|
|
|
2015-09-19 22:22:37 +00:00
|
|
|
@property
|
|
|
|
def code_format(self):
|
2015-09-22 21:40:45 +00:00
|
|
|
""" Four digit code required"""
|
2015-09-25 04:23:04 +00:00
|
|
|
return '^\\d{4}$'
|
2015-09-19 22:22:37 +00:00
|
|
|
|
2015-09-14 15:33:43 +00:00
|
|
|
def update(self):
|
|
|
|
''' update alarm status '''
|
|
|
|
verisure.update()
|
2015-09-14 17:42:36 +00:00
|
|
|
|
2015-09-13 05:42:38 +00:00
|
|
|
if verisure.STATUS[self._device][self._id].status == 'unarmed':
|
|
|
|
self._state = STATE_ALARM_DISARMED
|
|
|
|
elif verisure.STATUS[self._device][self._id].status == 'armedhome':
|
|
|
|
self._state = STATE_ALARM_ARMED_HOME
|
|
|
|
elif verisure.STATUS[self._device][self._id].status == 'armedaway':
|
|
|
|
self._state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif verisure.STATUS[self._device][self._id].status != 'pending':
|
2015-09-13 18:21:02 +00:00
|
|
|
_LOGGER.error(
|
|
|
|
'Unknown alarm state %s',
|
|
|
|
verisure.STATUS[self._device][self._id].status)
|
|
|
|
|
2015-09-19 17:32:37 +00:00
|
|
|
def alarm_disarm(self, code=None):
|
2015-09-13 05:42:38 +00:00
|
|
|
""" Send disarm command. """
|
2015-09-13 18:21:02 +00:00
|
|
|
verisure.MY_PAGES.set_alarm_status(
|
|
|
|
code,
|
|
|
|
verisure.MY_PAGES.ALARM_DISARMED)
|
|
|
|
_LOGGER.warning('disarming')
|
|
|
|
|
2015-09-19 17:32:37 +00:00
|
|
|
def alarm_arm_home(self, code=None):
|
2015-09-13 05:42:38 +00:00
|
|
|
""" Send arm home command. """
|
2015-09-13 18:21:02 +00:00
|
|
|
verisure.MY_PAGES.set_alarm_status(
|
|
|
|
code,
|
|
|
|
verisure.MY_PAGES.ALARM_ARMED_HOME)
|
|
|
|
_LOGGER.warning('arming home')
|
|
|
|
|
2015-09-19 17:32:37 +00:00
|
|
|
def alarm_arm_away(self, code=None):
|
2015-09-13 05:42:38 +00:00
|
|
|
""" Send arm away command. """
|
2015-09-13 18:21:02 +00:00
|
|
|
verisure.MY_PAGES.set_alarm_status(
|
|
|
|
code,
|
|
|
|
verisure.MY_PAGES.ALARM_ARMED_AWAY)
|
|
|
|
_LOGGER.warning('arming away')
|
2015-09-28 23:36:46 +00:00
|
|
|
|
|
|
|
def alarm_trigger(self, code=None):
|
|
|
|
""" Send alarm trigger command. No code needed. """
|
|
|
|
return
|