Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
SET_CONFIG_PARAMETER_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
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)
vol.Required(const.ATTR_CONFIG_VALUE): vol.Any(vol.Coerce(int), cv.string),
vol.Optional(const.ATTR_CONFIG_SIZE, default=2): vol.Coerce(int)
})
PRINT_CONFIG_PARAMETER_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
Expand Down Expand Up @@ -410,28 +410,28 @@ def set_config_parameter(service):
node = network.nodes[node_id]
param = service.data.get(const.ATTR_CONFIG_PARAMETER)
selection = service.data.get(const.ATTR_CONFIG_VALUE)
size = service.data.get(const.ATTR_CONFIG_SIZE, 2)
i = 0
size = service.data.get(const.ATTR_CONFIG_SIZE)
for value in (
node.get_values(class_id=const.COMMAND_CLASS_CONFIGURATION)
.values()):
if value.index == param and value.type == const.TYPE_LIST:
_LOGGER.debug("Values for parameter %s: %s", param,
value.data_items)
i = len(value.data_items) - 1
if i == 0:
node.set_config_param(param, selection, size)
else:
if selection > i:
_LOGGER.error("Config parameter selection does not exist! "
"Please check zwcfg_[home_id].xml in "
"your homeassistant config directory. "
"Available selections are 0 to %s", i)
if value.index != param:
continue
if value.type in [const.TYPE_LIST, const.TYPE_BOOL]:
value.data = selection
_LOGGER.info("Setting config list parameter %s on Node %s "
"with selection %s", param, node_id,
selection)
return
else:
value.data = int(selection)
_LOGGER.info("Setting config parameter %s on Node %s "
"with selection %s", param, node_id,
selection)
return
node.set_config_param(param, selection, size)
_LOGGER.info("Setting config parameter %s on Node %s "
"with selection %s and size=%s", param, node_id,
selection, size)
node.set_config_param(param, selection, size)
_LOGGER.info("Setting unknown config parameter %s on Node %s "
"with selection %s", param, node_id,
selection)

def print_config_parameter(service):
"""Print a config parameter from a node."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zwave/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ set_config_parameter:
parameter:
description: Parameter number to set (integer).
value:
description: Value to set on parameter. (integer).
description: Value to set for parameter. (String value for list and bool parameters, integer for others).
size:
description: (Optional) The size of the value. Defaults to 2.
description: (Optional) Set the size of the parameter value. Only needed if no parameters are available.

print_config_parameter:
description: Prints a Z-Wave node config parameter value to log.
Expand Down
21 changes: 8 additions & 13 deletions tests/components/zwave/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def test_set_config_parameter(self):
value = MockValue(
index=12,
command_class=const.COMMAND_CLASS_CONFIGURATION,
type=const.TYPE_BYTE,
)
value_list = MockValue(
index=13,
Expand All @@ -911,38 +912,32 @@ def test_set_config_parameter(self):
self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
const.ATTR_CONFIG_PARAMETER: 13,
const.ATTR_CONFIG_VALUE: 1,
const.ATTR_CONFIG_VALUE: 'item3',
})
self.hass.block_till_done()

assert node.set_config_param.called
assert len(node.set_config_param.mock_calls) == 1
assert node.set_config_param.mock_calls[0][1][0] == 13
assert node.set_config_param.mock_calls[0][1][1] == 1
assert node.set_config_param.mock_calls[0][1][2] == 2
node.set_config_param.reset_mock()
assert value_list.data == 'item3'

self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
const.ATTR_CONFIG_PARAMETER: 13,
const.ATTR_CONFIG_PARAMETER: 12,
const.ATTR_CONFIG_VALUE: 7,
})
self.hass.block_till_done()

assert not node.set_config_param.called
node.set_config_param.reset_mock()
assert value.data == 7

self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
const.ATTR_CONFIG_PARAMETER: 12,
const.ATTR_CONFIG_PARAMETER: 19,
const.ATTR_CONFIG_VALUE: 0x01020304,
const.ATTR_CONFIG_SIZE: 4,
const.ATTR_CONFIG_SIZE: 4
})
self.hass.block_till_done()

assert node.set_config_param.called
assert len(node.set_config_param.mock_calls) == 1
assert node.set_config_param.mock_calls[0][1][0] == 12
assert node.set_config_param.mock_calls[0][1][0] == 19
assert node.set_config_param.mock_calls[0][1][1] == 0x01020304
assert node.set_config_param.mock_calls[0][1][2] == 4
node.set_config_param.reset_mock()
Expand Down