Final tweaks for Zwave panel (#7652)

* # This is a combination of 3 commits.
# The first commit's message is:
Add seperate zwave panel

# The 2nd commit message will be skipped:

#	unused import

# The 3rd commit message will be skipped:

#	Use get for config

* Add seperate zwave panel

* Modify set_config_parameter to accept setting string values

* descriptions

* Tweaks

* Tweaks

* Tweaks

* Tweaks

* lint

* Fallback if no config parameteres are available

* Update services.yaml

* review changes
This commit is contained in:
John Arild Berentsen 2017-05-19 02:39:31 +02:00 committed by Paulus Schoutsen
parent e479324db9
commit 88ffe39945
3 changed files with 36 additions and 41 deletions

View File

@ -78,8 +78,8 @@ RENAME_NODE_SCHEMA = vol.Schema({
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),
@ -410,28 +410,28 @@ def setup(hass, config):
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
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)
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 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."""

View File

@ -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.

View File

@ -897,6 +897,7 @@ class TestZWaveServices(unittest.TestCase):
value = MockValue(
index=12,
command_class=const.COMMAND_CLASS_CONFIGURATION,
type=const.TYPE_BYTE,
)
value_list = MockValue(
index=13,
@ -911,38 +912,32 @@ class TestZWaveServices(unittest.TestCase):
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()
self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
const.ATTR_CONFIG_PARAMETER: 13,
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_list.data == 'item3'
self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
const.ATTR_CONFIG_PARAMETER: 12,
const.ATTR_CONFIG_VALUE: 7,
})
self.hass.block_till_done()
assert value.data == 7
self.hass.services.call('zwave', 'set_config_parameter', {
const.ATTR_NODE_ID: 14,
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()