Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion homeassistant/components/alarmdecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
CONF_ZONE_TYPE = 'type'
CONF_ZONE_RFID = 'rfid'
CONF_ZONES = 'zones'
CONF_RELAY_ADDR = 'relayaddr'
CONF_RELAY_CHAN = 'relaychan'

DEFAULT_DEVICE_TYPE = 'socket'
DEFAULT_DEVICE_HOST = 'localhost'
Expand All @@ -53,6 +55,7 @@
SIGNAL_ZONE_FAULT = 'alarmdecoder.zone_fault'
SIGNAL_ZONE_RESTORE = 'alarmdecoder.zone_restore'
SIGNAL_RFX_MESSAGE = 'alarmdecoder.rfx_message'
SIGNAL_REL_MESSAGE = 'alarmdecoder.rel_message'

DEVICE_SOCKET_SCHEMA = vol.Schema({
vol.Required(CONF_DEVICE_TYPE): 'socket',
Expand All @@ -71,7 +74,9 @@
vol.Required(CONF_ZONE_NAME): cv.string,
vol.Optional(CONF_ZONE_TYPE,
default=DEFAULT_ZONE_TYPE): vol.Any(DEVICE_CLASSES_SCHEMA),
vol.Optional(CONF_ZONE_RFID): cv.string})
vol.Optional(CONF_ZONE_RFID): cv.string,
vol.Optional(CONF_RELAY_ADDR): cv.byte,
vol.Optional(CONF_RELAY_CHAN): cv.byte})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required for the relay address to be effective? If so, mark both items with vol.Inclusive.


CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
Expand Down Expand Up @@ -153,6 +158,11 @@ def zone_restore_callback(sender, zone):
hass.helpers.dispatcher.dispatcher_send(
SIGNAL_ZONE_RESTORE, zone)

def handle_rel_message(sender, message):
"""Handle Relay message from AlarmDecoder."""
hass.helpers.dispatcher.dispatcher_send(
SIGNAL_REL_MESSAGE, message)

controller = False
if device_type == 'socket':
host = device.get(CONF_DEVICE_HOST)
Expand All @@ -171,6 +181,7 @@ def zone_restore_callback(sender, zone):
controller.on_zone_fault += zone_fault_callback
controller.on_zone_restore += zone_restore_callback
controller.on_close += handle_closed_connection
controller.on_relay_changed += handle_rel_message

hass.data[DATA_AD] = controller

Expand Down
20 changes: 17 additions & 3 deletions homeassistant/components/binary_sensor/alarmdecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from homeassistant.components.alarmdecoder import (
ZONE_SCHEMA, CONF_ZONES, CONF_ZONE_NAME, CONF_ZONE_TYPE,
CONF_ZONE_RFID, SIGNAL_ZONE_FAULT, SIGNAL_ZONE_RESTORE,
SIGNAL_RFX_MESSAGE)
SIGNAL_RFX_MESSAGE, SIGNAL_REL_MESSAGE, CONF_RELAY_ADDR,
CONF_RELAY_CHAN)

DEPENDENCIES = ['alarmdecoder']

Expand All @@ -37,8 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
zone_type = device_config_data[CONF_ZONE_TYPE]
zone_name = device_config_data[CONF_ZONE_NAME]
zone_rfid = device_config_data.get(CONF_ZONE_RFID)
relay_addr = device_config_data.get(CONF_RELAY_ADDR)
relay_chan = device_config_data.get(CONF_RELAY_CHAN)
device = AlarmDecoderBinarySensor(
zone_num, zone_name, zone_type, zone_rfid)
zone_num, zone_name, zone_type, zone_rfid, relay_addr, relay_chan)
devices.append(device)

add_devices(devices)
Expand All @@ -49,14 +52,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class AlarmDecoderBinarySensor(BinarySensorDevice):
"""Representation of an AlarmDecoder binary sensor."""

def __init__(self, zone_number, zone_name, zone_type, zone_rfid):
def __init__(self, zone_number, zone_name, zone_type, zone_rfid, relay_addr, relay_chan):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (93 > 79 characters)

"""Initialize the binary_sensor."""
self._zone_number = zone_number
self._zone_type = zone_type
self._state = None
self._name = zone_name
self._rfid = zone_rfid
self._rfstate = None
self._relay_addr = relay_addr
self._relay_chan = relay_chan

@asyncio.coroutine
def async_added_to_hass(self):
Expand All @@ -70,6 +75,9 @@ def async_added_to_hass(self):
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_RFX_MESSAGE, self._rfx_message_callback)

self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_REL_MESSAGE, self._rel_message_callback)

@property
def name(self):
"""Return the name of the entity."""
Expand Down Expand Up @@ -122,3 +130,9 @@ def _rfx_message_callback(self, message):
if self._rfid and message and message.serial_number == self._rfid:
self._rfstate = message.value
self.schedule_update_ha_state()

def _rel_message_callback(self, message):
"""Update Relay state."""
if self._relay_addr == message.address and self._relay_chan == message.channel:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

self._state = message.value
self.schedule_update_ha_state()