Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
6f6d86c7
Commit
6f6d86c7
authored
6 years ago
by
digiblur
Committed by
Martin Hjelmare
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add relay addr & chan config to alarmdecoder zones (#15242)
Add relay addr & chan config to alarmdecoder zones
parent
d1b16e28
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/alarmdecoder.py
+14
-1
14 additions, 1 deletion
homeassistant/components/alarmdecoder.py
homeassistant/components/binary_sensor/alarmdecoder.py
+21
-3
21 additions, 3 deletions
homeassistant/components/binary_sensor/alarmdecoder.py
with
35 additions
and
4 deletions
homeassistant/components/alarmdecoder.py
+
14
−
1
View file @
6f6d86c7
...
...
@@ -34,6 +34,8 @@ CONF_ZONE_NAME = 'name'
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
'
...
...
@@ -53,6 +55,7 @@ SIGNAL_PANEL_DISARM = 'alarmdecoder.panel_disarm'
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
'
,
...
...
@@ -71,7 +74,11 @@ ZONE_SCHEMA = vol.Schema({
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
.
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
({
DOMAIN
:
vol
.
Schema
({
...
...
@@ -153,6 +160,11 @@ def setup(hass, config):
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
)
...
...
@@ -171,6 +183,7 @@ def setup(hass, config):
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
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/binary_sensor/alarmdecoder.py
+
21
−
3
View file @
6f6d86c7
...
...
@@ -11,7 +11,8 @@ from homeassistant.components.binary_sensor import BinarySensorDevice
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
'
]
...
...
@@ -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
)
...
...
@@ -49,7 +52,8 @@ 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
):
"""
Initialize the binary_sensor.
"""
self
.
_zone_number
=
zone_number
self
.
_zone_type
=
zone_type
...
...
@@ -57,6 +61,8 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
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
):
...
...
@@ -70,6 +76,9 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
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.
"""
...
...
@@ -122,3 +131,12 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
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
):
_LOGGER
.
debug
(
"
Relay %d:%d value:%d
"
,
message
.
address
,
message
.
channel
,
message
.
value
)
self
.
_state
=
message
.
value
self
.
schedule_update_ha_state
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment