mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Add Chime status and control to Alarm Decoder component (#11271)
* Enable more alarm decoder attributes, including chime status and ready status * Expose chime service in the alarm decoder component * Fix line length linting issue * Fix spacing lint issue * Update PR based on reviewer requests * Update based on linting catches * Fix descriptions include from async to sync
This commit is contained in:
parent
b280a791a6
commit
a44181fd35
@ -6,24 +6,46 @@ https://home-assistant.io/components/alarm_control_panel.alarmdecoder/
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
import homeassistant.components.alarm_control_panel as alarm
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.config import load_yaml_config_file
|
||||||
from homeassistant.components.alarmdecoder import (
|
from homeassistant.components.alarmdecoder import (
|
||||||
DATA_AD, SIGNAL_PANEL_MESSAGE)
|
DATA_AD, SIGNAL_PANEL_MESSAGE)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
|
ATTR_CODE, STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
|
||||||
STATE_ALARM_TRIGGERED)
|
STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['alarmdecoder']
|
DEPENDENCIES = ['alarmdecoder']
|
||||||
|
|
||||||
|
SERVICE_ALARM_TOGGLE_CHIME = 'alarmdecoder_alarm_toggle_chime'
|
||||||
|
ALARM_TOGGLE_CHIME_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(ATTR_CODE): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up for AlarmDecoder alarm panels."""
|
"""Set up for AlarmDecoder alarm panels."""
|
||||||
add_devices([AlarmDecoderAlarmPanel()])
|
device = AlarmDecoderAlarmPanel()
|
||||||
|
add_devices([device])
|
||||||
|
|
||||||
return True
|
def alarm_toggle_chime_handler(service):
|
||||||
|
"""Register toggle chime handler."""
|
||||||
|
code = service.data.get(ATTR_CODE)
|
||||||
|
device.alarm_toggle_chime(code)
|
||||||
|
|
||||||
|
descriptions = load_yaml_config_file(
|
||||||
|
path.join(path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
|
hass.services.register(
|
||||||
|
alarm.DOMAIN, SERVICE_ALARM_TOGGLE_CHIME, alarm_toggle_chime_handler,
|
||||||
|
descriptions.get(SERVICE_ALARM_TOGGLE_CHIME),
|
||||||
|
schema=ALARM_TOGGLE_CHIME_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
||||||
@ -34,6 +56,15 @@ class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
|||||||
self._display = ""
|
self._display = ""
|
||||||
self._name = "Alarm Panel"
|
self._name = "Alarm Panel"
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._ac_power = None
|
||||||
|
self._backlight_on = None
|
||||||
|
self._battery_low = None
|
||||||
|
self._check_zone = None
|
||||||
|
self._chime = None
|
||||||
|
self._entry_delay_off = None
|
||||||
|
self._programming_mode = None
|
||||||
|
self._ready = None
|
||||||
|
self._zone_bypassed = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_added_to_hass(self):
|
def async_added_to_hass(self):
|
||||||
@ -43,20 +74,24 @@ class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def _message_callback(self, message):
|
def _message_callback(self, message):
|
||||||
if message.alarm_sounding or message.fire_alarm:
|
if message.alarm_sounding or message.fire_alarm:
|
||||||
if self._state != STATE_ALARM_TRIGGERED:
|
|
||||||
self._state = STATE_ALARM_TRIGGERED
|
self._state = STATE_ALARM_TRIGGERED
|
||||||
self.schedule_update_ha_state()
|
|
||||||
elif message.armed_away:
|
elif message.armed_away:
|
||||||
if self._state != STATE_ALARM_ARMED_AWAY:
|
|
||||||
self._state = STATE_ALARM_ARMED_AWAY
|
self._state = STATE_ALARM_ARMED_AWAY
|
||||||
self.schedule_update_ha_state()
|
|
||||||
elif message.armed_home:
|
elif message.armed_home:
|
||||||
if self._state != STATE_ALARM_ARMED_HOME:
|
|
||||||
self._state = STATE_ALARM_ARMED_HOME
|
self._state = STATE_ALARM_ARMED_HOME
|
||||||
self.schedule_update_ha_state()
|
|
||||||
else:
|
else:
|
||||||
if self._state != STATE_ALARM_DISARMED:
|
|
||||||
self._state = STATE_ALARM_DISARMED
|
self._state = STATE_ALARM_DISARMED
|
||||||
|
|
||||||
|
self._ac_power = message.ac_power
|
||||||
|
self._backlight_on = message.backlight_on
|
||||||
|
self._battery_low = message.battery_low
|
||||||
|
self._check_zone = message.check_zone
|
||||||
|
self._chime = message.chime_on
|
||||||
|
self._entry_delay_off = message.entry_delay_off
|
||||||
|
self._programming_mode = message.programming_mode
|
||||||
|
self._ready = message.ready
|
||||||
|
self._zone_bypassed = message.zone_bypassed
|
||||||
|
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -79,20 +114,37 @@ class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
|
|||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
return {
|
||||||
|
'ac_power': self._ac_power,
|
||||||
|
'backlight_on': self._backlight_on,
|
||||||
|
'battery_low': self._battery_low,
|
||||||
|
'check_zone': self._check_zone,
|
||||||
|
'chime': self._chime,
|
||||||
|
'entry_delay_off': self._entry_delay_off,
|
||||||
|
'programming_mode': self._programming_mode,
|
||||||
|
'ready': self._ready,
|
||||||
|
'zone_bypassed': self._zone_bypassed
|
||||||
|
}
|
||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
if code:
|
if code:
|
||||||
_LOGGER.debug("alarm_disarm: sending %s1", str(code))
|
|
||||||
self.hass.data[DATA_AD].send("{!s}1".format(code))
|
self.hass.data[DATA_AD].send("{!s}1".format(code))
|
||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
def alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
if code:
|
if code:
|
||||||
_LOGGER.debug("alarm_arm_away: sending %s2", str(code))
|
|
||||||
self.hass.data[DATA_AD].send("{!s}2".format(code))
|
self.hass.data[DATA_AD].send("{!s}2".format(code))
|
||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
def alarm_arm_home(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
if code:
|
if code:
|
||||||
_LOGGER.debug("alarm_arm_home: sending %s3", str(code))
|
|
||||||
self.hass.data[DATA_AD].send("{!s}3".format(code))
|
self.hass.data[DATA_AD].send("{!s}3".format(code))
|
||||||
|
|
||||||
|
def alarm_toggle_chime(self, code=None):
|
||||||
|
"""Send toggle chime command."""
|
||||||
|
if code:
|
||||||
|
self.hass.data[DATA_AD].send("{!s}9".format(code))
|
||||||
|
@ -59,3 +59,13 @@ envisalink_alarm_keypress:
|
|||||||
keypress:
|
keypress:
|
||||||
description: 'String to send to the alarm panel (1-6 characters).'
|
description: 'String to send to the alarm panel (1-6 characters).'
|
||||||
example: '*71'
|
example: '*71'
|
||||||
|
|
||||||
|
alarmdecoder_alarm_toggle_chime:
|
||||||
|
description: Send the alarm the toggle chime command.
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Name of the alarm control panel to trigger.
|
||||||
|
example: 'alarm_control_panel.downstairs'
|
||||||
|
code:
|
||||||
|
description: A required code to toggle the alarm control panel chime with.
|
||||||
|
example: 1234
|
||||||
|
Loading…
x
Reference in New Issue
Block a user