Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Add a keypress service for AlarmDecoder (home-assistant#26100)
Browse files Browse the repository at this point in the history
* Add a keypress service for AlarmDecoder (like Envisalink has)

* Feedback

* Import DOMAIN
  • Loading branch information
jkeljo authored and MartinHjelmare committed Sep 1, 2019
1 parent fade2e9 commit 5ba436e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion homeassistant/components/alarmdecoder/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
)
import homeassistant.helpers.config_validation as cv

from . import DATA_AD, SIGNAL_PANEL_MESSAGE
from . import DATA_AD, DOMAIN as DOMAIN_ALARMDECODER, SIGNAL_PANEL_MESSAGE

_LOGGER = logging.getLogger(__name__)

SERVICE_ALARM_TOGGLE_CHIME = "alarmdecoder_alarm_toggle_chime"
ALARM_TOGGLE_CHIME_SCHEMA = vol.Schema({vol.Required(ATTR_CODE): cv.string})

SERVICE_ALARM_KEYPRESS = "alarm_keypress"
ATTR_KEYPRESS = "keypress"
ALARM_KEYPRESS_SCHEMA = vol.Schema({vol.Required(ATTR_KEYPRESS): cv.string})


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up for AlarmDecoder alarm panels."""
Expand All @@ -38,6 +42,18 @@ def alarm_toggle_chime_handler(service):
schema=ALARM_TOGGLE_CHIME_SCHEMA,
)

def alarm_keypress_handler(service):
"""Register keypress handler."""
keypress = service.data[ATTR_KEYPRESS]
device.alarm_keypress(keypress)

hass.services.register(
DOMAIN_ALARMDECODER,
SERVICE_ALARM_KEYPRESS,
alarm_keypress_handler,
schema=ALARM_KEYPRESS_SCHEMA,
)


class AlarmDecoderAlarmPanel(alarm.AlarmControlPanel):
"""Representation of an AlarmDecoder-based alarm panel."""
Expand Down Expand Up @@ -145,3 +161,8 @@ def alarm_toggle_chime(self, code=None):
"""Send toggle chime command."""
if code:
self.hass.data[DATA_AD].send("{!s}9".format(code))

def alarm_keypress(self, keypress):
"""Send custom keypresses."""
if keypress:
self.hass.data[DATA_AD].send(keypress)
9 changes: 9 additions & 0 deletions homeassistant/components/alarmdecoder/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
alarm_keypress:
description: Send custom keypresses to the alarm.
fields:
entity_id:
description: Name of the alarm control panel to trigger.
example: 'alarm_control_panel.downstairs'
keypress:
description: 'String to send to the alarm panel.'
example: '*71'

0 comments on commit 5ba436e

Please sign in to comment.