Add set_config_parameter service (#3696)

This commit is contained in:
John Arild Berentsen 2016-10-05 07:04:19 +02:00 committed by Paulus Schoutsen
parent 03d6a7c42a
commit 17a8dd3f70
3 changed files with 38 additions and 0 deletions

View File

@ -117,6 +117,12 @@ RENAME_NODE_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Required(const.ATTR_NAME): cv.string,
})
SET_CONFIG_PARAMETER_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Required(const.ATTR_CONFIG_PARAMETER): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_VALUE): vol.Coerce(int),
vol.Optional(const.ATTR_CONFIG_SIZE): vol.Coerce(int)
})
_LOGGER = logging.getLogger(__name__)
@ -399,6 +405,18 @@ def setup(hass, config):
_LOGGER.info(
"Renamed ZWave node %d to %s", node_id, name)
def set_config_parameter(service):
"""Set a config parameter to a node."""
state = hass.states.get(service.data.get(ATTR_ENTITY_ID))
node_id = state.attributes.get(const.ATTR_NODE_ID)
node = NETWORK.nodes[node_id]
param = service.data.get(const.ATTR_CONFIG_PARAMETER)
value = service.data.get(const.ATTR_CONFIG_VALUE)
size = service.data.get(const.ATTR_CONFIG_SIZE, 2)
node.set_config_param(param, value, size)
_LOGGER.info("Setting config parameter %s on Node %s "
"with value %s and size=%s", param, node_id, value, size)
def start_zwave(_service_or_event):
"""Startup Z-Wave network."""
_LOGGER.info("Starting ZWave network.")
@ -459,6 +477,11 @@ def setup(hass, config):
hass.services.register(DOMAIN, const.SERVICE_RENAME_NODE, rename_node,
descriptions[const.SERVICE_RENAME_NODE],
schema=RENAME_NODE_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_SET_CONFIG_PARAMETER,
set_config_parameter,
descriptions[
const.SERVICE_SET_CONFIG_PARAMETER],
schema=SET_CONFIG_PARAMETER_SCHEMA)
# Setup autoheal
if autoheal:

View File

@ -6,6 +6,9 @@ ATTR_OBJECT_ID = "object_id"
ATTR_NAME = "name"
ATTR_SCENE_ID = "scene_id"
ATTR_BASIC_LEVEL = "basic_level"
ATTR_CONFIG_PARAMETER = "parameter"
ATTR_CONFIG_SIZE = "size"
ATTR_CONFIG_VALUE = "value"
NETWORK_READY_WAIT_SECS = 30
SERVICE_ADD_NODE = "add_node"
@ -15,6 +18,7 @@ SERVICE_CANCEL_COMMAND = "cancel_command"
SERVICE_HEAL_NETWORK = "heal_network"
SERVICE_SOFT_RESET = "soft_reset"
SERVICE_TEST_NETWORK = "test_network"
SERVICE_SET_CONFIG_PARAMETER = "set_config_parameter"
SERVICE_STOP_NETWORK = "stop_network"
SERVICE_START_NETWORK = "start_network"
SERVICE_RENAME_NODE = "rename_node"

View File

@ -13,6 +13,17 @@ heal_network:
remove_node:
description: Remove a node from the Z-Wave network. Refer to OZW.log for details.
set_config_parameter:
description: Set a config parameter to a node on the Z-Wave network.
fields:
entity_id:
description: Name of entity to set config parameter to.
parameter:
description: Parameter number to set (integer).
value:
description: Value to set on parameter. (integer).
size:
description: (Optional) The size of the value. Defaults to 2.
start_network:
description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is.