From 5c4529d044463083bad73cdbf9d17d8cb2b29afa Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Tue, 20 Mar 2018 14:04:24 +0100 Subject: [PATCH] Bugfix: Zwave set_config_parameter failed when config list contained int (#13301) * Cast list and bool options to STR * Add button options to STR * Add TYPE_BUTTON to value types * Adjust comparison * Remove Logging * Remove Empty line * Update tests * Update tests * Mistake --- homeassistant/components/zwave/__init__.py | 13 +++++++-- homeassistant/components/zwave/const.py | 1 + tests/components/zwave/test_init.py | 34 +++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 43aa996c799..a85160e8bde 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -442,9 +442,16 @@ def setup(hass, config): 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, + value.data = str(selection) + _LOGGER.info("Setting config parameter %s on Node %s " + "with list/bool selection %s", param, node_id, + str(selection)) + return + if value.type == const.TYPE_BUTTON: + network.manager.pressButton(value.value_id) + network.manager.releaseButton(value.value_id) + _LOGGER.info("Setting config parameter %s on Node %s " + "with button selection %s", param, node_id, selection) return value.data = int(selection) diff --git a/homeassistant/components/zwave/const.py b/homeassistant/components/zwave/const.py index bb4b33300e5..8e1a22047c1 100644 --- a/homeassistant/components/zwave/const.py +++ b/homeassistant/components/zwave/const.py @@ -327,6 +327,7 @@ TYPE_DECIMAL = "Decimal" TYPE_INT = "Int" TYPE_LIST = "List" TYPE_STRING = "String" +TYPE_BUTTON = "Button" DISC_COMMAND_CLASS = "command_class" DISC_COMPONENT = "component" diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index 30c9d3ba489..bb073459b48 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -995,8 +995,21 @@ class TestZWaveServices(unittest.TestCase): type=const.TYPE_LIST, data_items=['item1', 'item2', 'item3'], ) + value_list_int = MockValue( + index=15, + command_class=const.COMMAND_CLASS_CONFIGURATION, + type=const.TYPE_LIST, + data_items=['1', '2', '3'], + ) + value_button = MockValue( + index=14, + command_class=const.COMMAND_CLASS_CONFIGURATION, + type=const.TYPE_BUTTON, + ) node = MockNode(node_id=14) - node.get_values.return_value = {12: value, 13: value_list} + node.get_values.return_value = {12: value, 13: value_list, + 14: value_button, + 15: value_list_int} self.zwave_network.nodes = {14: node} self.hass.services.call('zwave', 'set_config_parameter', { @@ -1008,6 +1021,15 @@ class TestZWaveServices(unittest.TestCase): assert value_list.data == 'item3' + self.hass.services.call('zwave', 'set_config_parameter', { + const.ATTR_NODE_ID: 14, + const.ATTR_CONFIG_PARAMETER: 15, + const.ATTR_CONFIG_VALUE: 3, + }) + self.hass.block_till_done() + + assert value_list_int.data == '3' + self.hass.services.call('zwave', 'set_config_parameter', { const.ATTR_NODE_ID: 14, const.ATTR_CONFIG_PARAMETER: 12, @@ -1017,6 +1039,16 @@ class TestZWaveServices(unittest.TestCase): assert value.data == 7 + self.hass.services.call('zwave', 'set_config_parameter', { + const.ATTR_NODE_ID: 14, + const.ATTR_CONFIG_PARAMETER: 14, + const.ATTR_CONFIG_VALUE: True, + }) + self.hass.block_till_done() + + assert self.zwave_network.manager.pressButton.called + assert self.zwave_network.manager.releaseButton.called + self.hass.services.call('zwave', 'set_config_parameter', { const.ATTR_NODE_ID: 14, const.ATTR_CONFIG_PARAMETER: 19,