mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add relay addr & chan config to alarmdecoder zones (#15242)
Add relay addr & chan config to alarmdecoder zones
This commit is contained in:
parent
d1b16e287c
commit
6f6d86c700
@ -34,6 +34,8 @@ CONF_ZONE_NAME = 'name'
|
|||||||
CONF_ZONE_TYPE = 'type'
|
CONF_ZONE_TYPE = 'type'
|
||||||
CONF_ZONE_RFID = 'rfid'
|
CONF_ZONE_RFID = 'rfid'
|
||||||
CONF_ZONES = 'zones'
|
CONF_ZONES = 'zones'
|
||||||
|
CONF_RELAY_ADDR = 'relayaddr'
|
||||||
|
CONF_RELAY_CHAN = 'relaychan'
|
||||||
|
|
||||||
DEFAULT_DEVICE_TYPE = 'socket'
|
DEFAULT_DEVICE_TYPE = 'socket'
|
||||||
DEFAULT_DEVICE_HOST = 'localhost'
|
DEFAULT_DEVICE_HOST = 'localhost'
|
||||||
@ -53,6 +55,7 @@ SIGNAL_PANEL_DISARM = 'alarmdecoder.panel_disarm'
|
|||||||
SIGNAL_ZONE_FAULT = 'alarmdecoder.zone_fault'
|
SIGNAL_ZONE_FAULT = 'alarmdecoder.zone_fault'
|
||||||
SIGNAL_ZONE_RESTORE = 'alarmdecoder.zone_restore'
|
SIGNAL_ZONE_RESTORE = 'alarmdecoder.zone_restore'
|
||||||
SIGNAL_RFX_MESSAGE = 'alarmdecoder.rfx_message'
|
SIGNAL_RFX_MESSAGE = 'alarmdecoder.rfx_message'
|
||||||
|
SIGNAL_REL_MESSAGE = 'alarmdecoder.rel_message'
|
||||||
|
|
||||||
DEVICE_SOCKET_SCHEMA = vol.Schema({
|
DEVICE_SOCKET_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_DEVICE_TYPE): 'socket',
|
vol.Required(CONF_DEVICE_TYPE): 'socket',
|
||||||
@ -71,7 +74,11 @@ ZONE_SCHEMA = vol.Schema({
|
|||||||
vol.Required(CONF_ZONE_NAME): cv.string,
|
vol.Required(CONF_ZONE_NAME): cv.string,
|
||||||
vol.Optional(CONF_ZONE_TYPE,
|
vol.Optional(CONF_ZONE_TYPE,
|
||||||
default=DEFAULT_ZONE_TYPE): vol.Any(DEVICE_CLASSES_SCHEMA),
|
default=DEFAULT_ZONE_TYPE): vol.Any(DEVICE_CLASSES_SCHEMA),
|
||||||
vol.Optional(CONF_ZONE_RFID): cv.string})
|
vol.Optional(CONF_ZONE_RFID): cv.string,
|
||||||
|
vol.Inclusive(CONF_RELAY_ADDR, 'relaylocation',
|
||||||
|
'Relay address and channel must exist together'): cv.byte,
|
||||||
|
vol.Inclusive(CONF_RELAY_CHAN, 'relaylocation',
|
||||||
|
'Relay address and channel must exist together'): cv.byte})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
@ -153,6 +160,11 @@ def setup(hass, config):
|
|||||||
hass.helpers.dispatcher.dispatcher_send(
|
hass.helpers.dispatcher.dispatcher_send(
|
||||||
SIGNAL_ZONE_RESTORE, zone)
|
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
|
controller = False
|
||||||
if device_type == 'socket':
|
if device_type == 'socket':
|
||||||
host = device.get(CONF_DEVICE_HOST)
|
host = device.get(CONF_DEVICE_HOST)
|
||||||
@ -171,6 +183,7 @@ def setup(hass, config):
|
|||||||
controller.on_zone_fault += zone_fault_callback
|
controller.on_zone_fault += zone_fault_callback
|
||||||
controller.on_zone_restore += zone_restore_callback
|
controller.on_zone_restore += zone_restore_callback
|
||||||
controller.on_close += handle_closed_connection
|
controller.on_close += handle_closed_connection
|
||||||
|
controller.on_relay_changed += handle_rel_message
|
||||||
|
|
||||||
hass.data[DATA_AD] = controller
|
hass.data[DATA_AD] = controller
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ from homeassistant.components.binary_sensor import BinarySensorDevice
|
|||||||
from homeassistant.components.alarmdecoder import (
|
from homeassistant.components.alarmdecoder import (
|
||||||
ZONE_SCHEMA, CONF_ZONES, CONF_ZONE_NAME, CONF_ZONE_TYPE,
|
ZONE_SCHEMA, CONF_ZONES, CONF_ZONE_NAME, CONF_ZONE_TYPE,
|
||||||
CONF_ZONE_RFID, SIGNAL_ZONE_FAULT, SIGNAL_ZONE_RESTORE,
|
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']
|
DEPENDENCIES = ['alarmdecoder']
|
||||||
|
|
||||||
@ -37,8 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
zone_type = device_config_data[CONF_ZONE_TYPE]
|
zone_type = device_config_data[CONF_ZONE_TYPE]
|
||||||
zone_name = device_config_data[CONF_ZONE_NAME]
|
zone_name = device_config_data[CONF_ZONE_NAME]
|
||||||
zone_rfid = device_config_data.get(CONF_ZONE_RFID)
|
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(
|
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)
|
devices.append(device)
|
||||||
|
|
||||||
add_devices(devices)
|
add_devices(devices)
|
||||||
@ -49,7 +52,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
class AlarmDecoderBinarySensor(BinarySensorDevice):
|
class AlarmDecoderBinarySensor(BinarySensorDevice):
|
||||||
"""Representation of an AlarmDecoder binary sensor."""
|
"""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):
|
||||||
"""Initialize the binary_sensor."""
|
"""Initialize the binary_sensor."""
|
||||||
self._zone_number = zone_number
|
self._zone_number = zone_number
|
||||||
self._zone_type = zone_type
|
self._zone_type = zone_type
|
||||||
@ -57,6 +61,8 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
|
|||||||
self._name = zone_name
|
self._name = zone_name
|
||||||
self._rfid = zone_rfid
|
self._rfid = zone_rfid
|
||||||
self._rfstate = None
|
self._rfstate = None
|
||||||
|
self._relay_addr = relay_addr
|
||||||
|
self._relay_chan = relay_chan
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_added_to_hass(self):
|
def async_added_to_hass(self):
|
||||||
@ -70,6 +76,9 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
|
|||||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||||
SIGNAL_RFX_MESSAGE, self._rfx_message_callback)
|
SIGNAL_RFX_MESSAGE, self._rfx_message_callback)
|
||||||
|
|
||||||
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||||
|
SIGNAL_REL_MESSAGE, self._rel_message_callback)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the entity."""
|
"""Return the name of the entity."""
|
||||||
@ -122,3 +131,12 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
|
|||||||
if self._rfid and message and message.serial_number == self._rfid:
|
if self._rfid and message and message.serial_number == self._rfid:
|
||||||
self._rfstate = message.value
|
self._rfstate = message.value
|
||||||
self.schedule_update_ha_state()
|
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):
|
||||||
|
_LOGGER.debug("Relay %d:%d value:%d", message.address,
|
||||||
|
message.channel, message.value)
|
||||||
|
self._state = message.value
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user