ZWave: Add association service (#3894)
* Add association service * Refactor service * Requested changes * Grammar in pydocstyle
This commit is contained in:
parent
2612c6d6b8
commit
8b2edc1514
3 changed files with 52 additions and 0 deletions
|
@ -132,6 +132,13 @@ SET_CONFIG_PARAMETER_SCHEMA = vol.Schema({
|
|||
vol.Required(const.ATTR_CONFIG_VALUE): vol.Coerce(int),
|
||||
vol.Optional(const.ATTR_CONFIG_SIZE): vol.Coerce(int)
|
||||
})
|
||||
CHANGE_ASSOCIATION_SCHEMA = vol.Schema({
|
||||
vol.Required(const.ATTR_ASSOCIATION): cv.string,
|
||||
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
|
||||
vol.Required(const.ATTR_TARGET_NODE_ID): vol.Coerce(int),
|
||||
vol.Required(const.ATTR_GROUP): vol.Coerce(int),
|
||||
vol.Optional(const.ATTR_INSTANCE, default=0x00): vol.Coerce(int)
|
||||
})
|
||||
|
||||
CUSTOMIZE_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_POLLING_INTENSITY):
|
||||
|
@ -240,6 +247,7 @@ def setup(hass, config):
|
|||
from pydispatch import dispatcher
|
||||
from openzwave.option import ZWaveOption
|
||||
from openzwave.network import ZWaveNetwork
|
||||
from openzwave.group import ZWaveGroup
|
||||
|
||||
default_zwave_config_path = os.path.join(os.path.dirname(
|
||||
libopenzwave.__file__), 'config')
|
||||
|
@ -445,6 +453,26 @@ def setup(hass, config):
|
|||
_LOGGER.info("Setting config parameter %s on Node %s "
|
||||
"with value %s and size=%s", param, node_id, value, size)
|
||||
|
||||
def change_association(service):
|
||||
"""Change an association in the zwave network."""
|
||||
association_type = service.data.get(const.ATTR_ASSOCIATION)
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
target_node_id = service.data.get(const.ATTR_TARGET_NODE_ID)
|
||||
group = service.data.get(const.ATTR_GROUP)
|
||||
instance = service.data.get(const.ATTR_INSTANCE)
|
||||
|
||||
node = ZWaveGroup(group, NETWORK, node_id)
|
||||
if association_type == 'add':
|
||||
node.add_association(target_node_id, instance)
|
||||
_LOGGER.info("Adding association for node:%s in group:%s "
|
||||
"target node:%s, instance=%s", node_id, group,
|
||||
target_node_id, instance)
|
||||
if association_type == 'remove':
|
||||
node.remove_association(target_node_id, instance)
|
||||
_LOGGER.info("Removing association for node:%s in group:%s "
|
||||
"target node:%s, instance=%s", node_id, group,
|
||||
target_node_id, instance)
|
||||
|
||||
def start_zwave(_service_or_event):
|
||||
"""Startup Z-Wave network."""
|
||||
_LOGGER.info("Starting ZWave network.")
|
||||
|
@ -510,6 +538,11 @@ def setup(hass, config):
|
|||
descriptions[
|
||||
const.SERVICE_SET_CONFIG_PARAMETER],
|
||||
schema=SET_CONFIG_PARAMETER_SCHEMA)
|
||||
hass.services.register(DOMAIN, const.SERVICE_CHANGE_ASSOCIATION,
|
||||
change_association,
|
||||
descriptions[
|
||||
const.SERVICE_CHANGE_ASSOCIATION],
|
||||
schema=CHANGE_ASSOCIATION_SCHEMA)
|
||||
|
||||
# Setup autoheal
|
||||
if autoheal:
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
"""Z-Wave Constants."""
|
||||
|
||||
ATTR_NODE_ID = "node_id"
|
||||
ATTR_TARGET_NODE_ID = "target_node_id"
|
||||
ATTR_ASSOCIATION = "association"
|
||||
ATTR_INSTANCE = "instance"
|
||||
ATTR_GROUP = "group"
|
||||
ATTR_VALUE_ID = "value_id"
|
||||
ATTR_OBJECT_ID = "object_id"
|
||||
ATTR_NAME = "name"
|
||||
|
@ -11,6 +15,7 @@ ATTR_CONFIG_SIZE = "size"
|
|||
ATTR_CONFIG_VALUE = "value"
|
||||
NETWORK_READY_WAIT_SECS = 30
|
||||
|
||||
SERVICE_CHANGE_ASSOCIATION = "change_association"
|
||||
SERVICE_ADD_NODE = "add_node"
|
||||
SERVICE_ADD_NODE_SECURE = "add_node_secure"
|
||||
SERVICE_REMOVE_NODE = "remove_node"
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
change_association:
|
||||
description: Change an association in the Z-Wave network.
|
||||
fields:
|
||||
association:
|
||||
description: Specify add or remove assosication
|
||||
node_id:
|
||||
description: Node id of the node to set association for.
|
||||
target_node_id:
|
||||
description: Node id of the node to associate to.
|
||||
group:
|
||||
description: Group number to set association for.
|
||||
instance:
|
||||
description: (Optional) Instance of association. Defaults to 0.
|
||||
|
||||
add_node:
|
||||
description: Add a new node to the Z-Wave network. Refer to OZW.log for details.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue