core/homeassistant/components/alarm_control_panel/verisure.py

91 lines
2.8 KiB
Python
Raw Normal View History

2015-09-13 05:42:38 +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
2016-03-07 15:45:21 +00:00
https://home-assistant.io/components/alarm_control_panel.verisure/
2015-09-13 05:42:38 +00:00
"""
import logging
2015-09-13 18:21:02 +00:00
import homeassistant.components.alarm_control_panel as alarm
2016-02-27 20:50:19 +00:00
from homeassistant.components.verisure import HUB as hub
2015-09-13 18:21:02 +00:00
from homeassistant.const import (
2016-02-19 05:27:50 +00:00
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
STATE_UNKNOWN)
2015-09-13 05:42:38 +00:00
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-03-07 15:45:21 +00:00
"""Setup the Verisure platform."""
2015-09-13 05:42:38 +00:00
alarms = []
2016-02-27 20:50:19 +00:00
if int(hub.config.get('alarm', '1')):
hub.update_alarms()
alarms.extend([
VerisureAlarm(value.id)
for value in hub.alarm_status.values()
])
2015-09-13 05:42:38 +00:00
add_devices(alarms)
# pylint: disable=abstract-method
2015-09-13 18:21:02 +00:00
class VerisureAlarm(alarm.AlarmControlPanel):
2016-03-07 19:21:43 +00:00
"""Represent a Verisure alarm status."""
2016-02-27 20:50:19 +00:00
def __init__(self, device_id):
2016-03-07 19:21:43 +00:00
"""Initalize the Verisure alarm panel."""
2016-02-27 20:50:19 +00:00
self._id = device_id
2015-09-13 05:42:38 +00:00
self._state = STATE_UNKNOWN
2016-02-27 20:50:19 +00:00
self._digits = int(hub.config.get('code_digits', '4'))
2015-09-13 05:42:38 +00:00
@property
def name(self):
2016-03-07 19:21:43 +00:00
"""Return the name of the device."""
2015-09-13 05:42:38 +00:00
return 'Alarm {}'.format(self._id)
@property
def state(self):
2016-03-07 19:21:43 +00:00
"""Return the state of the device."""
2015-09-14 15:33:43 +00:00
return self._state
@property
def code_format(self):
2016-03-07 19:21:43 +00:00
"""The code format as regex."""
2016-02-27 20:50:19 +00:00
return '^\\d{%s}$' % self._digits
2015-09-14 15:33:43 +00:00
def update(self):
2016-03-07 15:45:21 +00:00
"""Update alarm status."""
2016-02-27 20:50:19 +00:00
hub.update_alarms()
2015-09-14 17:42:36 +00:00
2016-02-27 20:50:19 +00:00
if hub.alarm_status[self._id].status == 'unarmed':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_DISARMED
2016-02-27 20:50:19 +00:00
elif hub.alarm_status[self._id].status == 'armedhome':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_ARMED_HOME
2016-02-27 20:50:19 +00:00
elif hub.alarm_status[self._id].status == 'armed':
2015-09-13 05:42:38 +00:00
self._state = STATE_ALARM_ARMED_AWAY
2016-02-27 20:50:19 +00:00
elif hub.alarm_status[self._id].status != 'pending':
2015-09-13 18:21:02 +00:00
_LOGGER.error(
'Unknown alarm state %s',
2016-02-27 20:50:19 +00:00
hub.alarm_status[self._id].status)
2015-09-13 18:21:02 +00:00
def alarm_disarm(self, code=None):
2016-03-07 15:45:21 +00:00
"""Send disarm command."""
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.set(code, 'DISARMED')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm disarming')
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.wait_while_pending()
self.update()
2015-09-13 18:21:02 +00:00
def alarm_arm_home(self, code=None):
2016-03-07 15:45:21 +00:00
"""Send arm home command."""
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.set(code, 'ARMED_HOME')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm arming home')
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.wait_while_pending()
self.update()
2015-09-13 18:21:02 +00:00
def alarm_arm_away(self, code=None):
2016-03-07 15:45:21 +00:00
"""Send arm away command."""
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.set(code, 'ARMED_AWAY')
2015-12-25 19:42:03 +00:00
_LOGGER.info('verisure alarm arming away')
2016-02-27 20:50:19 +00:00
hub.my_pages.alarm.wait_while_pending()
self.update()