core/homeassistant/components/alarm_control_panel/verisure.py

97 lines
3.0 KiB
Python
Raw Normal View History

2015-09-13 05:42:38 +00:00
"""
2015-09-13 18:21:02 +00:00
homeassistant.components.alarm_control_panel.verisure
2015-10-02 11:42:06 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015-09-13 18:21:02 +00:00
Interfaces with Verisure alarm control panel.
2015-11-09 12:12:18 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/verisure/
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)
2015-12-25 19:16:51 +00:00
for value in verisure.ALARM_STATUS.values()
2015-09-13 05:42:38 +00:00
if verisure.SHOW_ALARM
])
add_devices(alarms)
# pylint: disable=abstract-method
2015-09-13 18:21:02 +00:00
class VerisureAlarm(alarm.AlarmControlPanel):
2015-10-02 11:42:06 +00:00
""" Represents a Verisure alarm status. """
2015-09-13 05:42:38 +00:00
def __init__(self, alarm_status):
self._id = alarm_status.id
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
@property
def code_format(self):
2015-10-02 11:42:06 +00:00
""" Four digit code required. """
2016-01-16 14:12:54 +00:00
return '^\\d{%s}$' % verisure.CODE_DIGITS
2015-09-14 15:33:43 +00:00
def update(self):
2015-10-02 11:42:06 +00:00
""" Update alarm status """
2015-12-25 19:16:51 +00:00
verisure.update_alarm()
2015-09-14 17:42:36 +00:00
2015-12-25 19:16:51 +00:00
if verisure.ALARM_STATUS[self._id].status == 'unarmed':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_DISARMED
2015-12-25 19:16:51 +00:00
elif verisure.ALARM_STATUS[self._id].status == 'armedhome':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_ARMED_HOME
2016-01-08 18:50:49 +00:00
elif verisure.ALARM_STATUS[self._id].status == 'armed':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_ARMED_AWAY
2015-12-25 19:16:51 +00:00
elif verisure.ALARM_STATUS[self._id].status != 'pending':
2015-09-13 18:21:02 +00:00
_LOGGER.error(
'Unknown alarm state %s',
2015-12-25 19:16:51 +00:00
verisure.ALARM_STATUS[self._id].status)
2015-09-13 18:21:02 +00:00
def alarm_disarm(self, code=None):
2015-09-13 05:42:38 +00:00
""" Send disarm command. """
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.set(code, 'DISARMED')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm disarming')
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.wait_while_pending()
verisure.update_alarm()
2015-09-13 18:21:02 +00:00
def alarm_arm_home(self, code=None):
2015-09-13 05:42:38 +00:00
""" Send arm home command. """
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.set(code, 'ARMED_HOME')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm arming home')
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.wait_while_pending()
verisure.update_alarm()
2015-09-13 18:21:02 +00:00
def alarm_arm_away(self, code=None):
2015-09-13 05:42:38 +00:00
""" Send arm away command. """
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.set(code, 'ARMED_AWAY')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm arming away')
2015-12-25 19:16:51 +00:00
verisure.MY_PAGES.alarm.wait_while_pending()
verisure.update_alarm()