2017-04-12 05:35:35 -04:00
|
|
|
"""
|
|
|
|
Support for AlarmDecoder-based alarm control panels (Honeywell/DSC).
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/alarm_control_panel.alarmdecoder/
|
|
|
|
"""
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
2017-12-16 15:52:59 -08:00
|
|
|
from homeassistant.components.alarmdecoder import (
|
|
|
|
DATA_AD, SIGNAL_PANEL_MESSAGE)
|
2017-04-12 05:35:35 -04:00
|
|
|
from homeassistant.const import (
|
|
|
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
|
2017-12-16 15:52:59 -08:00
|
|
|
STATE_ALARM_TRIGGERED)
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['alarmdecoder']
|
|
|
|
|
|
|
|
|
2017-12-16 15:52:59 -08:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Set up for AlarmDecoder alarm panels."""
|
2017-12-16 15:52:59 -08:00
|
|
|
add_devices([AlarmDecoderAlarmPanel()])
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
|
|
|
"""Representation of an AlarmDecoder-based alarm panel."""
|
|
|
|
|
2017-12-16 15:52:59 -08:00
|
|
|
def __init__(self):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Initialize the alarm panel."""
|
|
|
|
self._display = ""
|
2017-12-16 15:52:59 -08:00
|
|
|
self._name = "Alarm Panel"
|
|
|
|
self._state = None
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def async_added_to_hass(self):
|
|
|
|
"""Register callbacks."""
|
2017-12-16 15:52:59 -08:00
|
|
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
|
|
|
SIGNAL_PANEL_MESSAGE, self._message_callback)
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
def _message_callback(self, message):
|
|
|
|
if message.alarm_sounding or message.fire_alarm:
|
|
|
|
if self._state != STATE_ALARM_TRIGGERED:
|
|
|
|
self._state = STATE_ALARM_TRIGGERED
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 05:35:35 -04:00
|
|
|
elif message.armed_away:
|
|
|
|
if self._state != STATE_ALARM_ARMED_AWAY:
|
|
|
|
self._state = STATE_ALARM_ARMED_AWAY
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 05:35:35 -04:00
|
|
|
elif message.armed_home:
|
|
|
|
if self._state != STATE_ALARM_ARMED_HOME:
|
|
|
|
self._state = STATE_ALARM_ARMED_HOME
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 05:35:35 -04:00
|
|
|
else:
|
|
|
|
if self._state != STATE_ALARM_DISARMED:
|
|
|
|
self._state = STATE_ALARM_DISARMED
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the device."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Return the polling state."""
|
2017-04-12 05:35:35 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def code_format(self):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Return the regex for code format or None if no code is required."""
|
2017-04-12 05:35:35 -04:00
|
|
|
return '^\\d{4,6}$'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
|
|
|
return self._state
|
|
|
|
|
2017-12-16 15:52:59 -08:00
|
|
|
def alarm_disarm(self, code=None):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Send disarm command."""
|
|
|
|
if code:
|
2017-04-30 07:04:49 +02:00
|
|
|
_LOGGER.debug("alarm_disarm: sending %s1", str(code))
|
2017-04-12 05:35:35 -04:00
|
|
|
self.hass.data[DATA_AD].send("{!s}1".format(code))
|
|
|
|
|
2017-12-16 15:52:59 -08:00
|
|
|
def alarm_arm_away(self, code=None):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Send arm away command."""
|
|
|
|
if code:
|
2017-04-30 07:04:49 +02:00
|
|
|
_LOGGER.debug("alarm_arm_away: sending %s2", str(code))
|
2017-04-12 05:35:35 -04:00
|
|
|
self.hass.data[DATA_AD].send("{!s}2".format(code))
|
|
|
|
|
2017-12-16 15:52:59 -08:00
|
|
|
def alarm_arm_home(self, code=None):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Send arm home command."""
|
|
|
|
if code:
|
2017-04-30 07:04:49 +02:00
|
|
|
_LOGGER.debug("alarm_arm_home: sending %s3", str(code))
|
2017-04-12 05:35:35 -04:00
|
|
|
self.hass.data[DATA_AD].send("{!s}3".format(code))
|