Add new services for set/refresh Z-Wave device values (#16638)

* Add services for getting and setting indicator values for Z-Wave

* Add service to manually refresh Z-Wave node value by value_id

* Remove refresh_indicator service

* Coerce to int

* Add generic set_node_value service

* Remove set_indicator service
This commit is contained in:
Blake Blackshear authored and Paulus Schoutsen committed 2018-09-27 12:34:42 +02:00
1 parent ad79dc673d
commit 2cc6263092
5 files changed
+103 -1

No files matched your search

@@ -84,6 +84,17 @@ SET_CONFIG_PARAMETER_SCHEMA = vol.Schema({
vol.Optional(const.ATTR_CONFIG_SIZE, default=2): vol.Coerce(int)
})
SET_NODE_VALUE_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_VALUE_ID): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_VALUE): vol.Coerce(int)
})
REFRESH_NODE_VALUE_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_VALUE_ID): vol.Coerce(int)
})
SET_POLL_INTENSITY_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_VALUE_ID): vol.Coerce(int),
@@ -492,6 +503,23 @@ async def async_setup(hass, config):
"with selection %s", param, node_id,
selection)
def refresh_node_value(service):
"""Refresh the specified value from a node."""
node_id = service.data.get(const.ATTR_NODE_ID)
value_id = service.data.get(const.ATTR_VALUE_ID)
node = network.nodes[node_id]
node.values[value_id].refresh()
_LOGGER.info("Node %s value %s refreshed", node_id, value_id)
def set_node_value(service):
"""Set the specified value on a node."""
node_id = service.data.get(const.ATTR_NODE_ID)
value_id = service.data.get(const.ATTR_VALUE_ID)
value = service.data.get(const.ATTR_CONFIG_VALUE)
node = network.nodes[node_id]
node.values[value_id].data = value
_LOGGER.info("Node %s value %s set to %s", node_id, value_id, value)
def print_config_parameter(service):
"""Print a config parameter from a node."""
node_id = service.data.get(const.ATTR_NODE_ID)
@@ -662,6 +690,12 @@ async def async_setup(hass, config):
hass.services.register(DOMAIN, const.SERVICE_SET_CONFIG_PARAMETER,
set_config_parameter,
schema=SET_CONFIG_PARAMETER_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_SET_NODE_VALUE,
set_node_value,
schema=SET_NODE_VALUE_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_REFRESH_NODE_VALUE,
refresh_node_value,
schema=REFRESH_NODE_VALUE_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_PRINT_CONFIG_PARAMETER,
print_config_parameter,
schema=PRINT_CONFIG_PARAMETER_SCHEMA)
+2
View File
@@ -39,6 +39,8 @@ SERVICE_SOFT_RESET = "soft_reset"
SERVICE_TEST_NODE = "test_node"
SERVICE_TEST_NETWORK = "test_network"
SERVICE_SET_CONFIG_PARAMETER = "set_config_parameter"
SERVICE_SET_NODE_VALUE = "set_node_value"
SERVICE_REFRESH_NODE_VALUE = "refresh_node_value"
SERVICE_PRINT_CONFIG_PARAMETER = "print_config_parameter"
SERVICE_PRINT_NODE = "print_node"
SERVICE_REMOVE_FAILED_NODE = "remove_failed_node"
@@ -211,7 +211,8 @@ DISCOVERY_SCHEMAS = [
const.COMMAND_CLASS_SENSOR_MULTILEVEL,
const.COMMAND_CLASS_METER,
const.COMMAND_CLASS_ALARM,
const.COMMAND_CLASS_SENSOR_ALARM],
const.COMMAND_CLASS_SENSOR_ALARM,
const.COMMAND_CLASS_INDICATOR],
const.DISC_GENRE: const.GENRE_USER,
}})},
{const.DISC_COMPONENT: 'switch',
@@ -69,6 +69,24 @@ set_config_parameter:
size:
description: (Optional) Set the size of the parameter value. Only needed if no parameters are available.
set_node_value:
description: Set the value for a given value_id on a Z-Wave device.
fields:
node_id:
description: Node id of the device to set the value on (integer).
value_id:
description: Value id of the value to set (integer).
value:
description: Value to set (integer).
refresh_node_value:
description: Refresh the value for a given value_id on a Z-Wave device.
fields:
node_id:
description: Node id of the device to refresh value from (integer).
value_id:
description: Value id of the value to refresh.
set_poll_intensity:
description: Set the polling interval to a nodes value
fields: