From d70ab95c0e6c28bba2c5ba63a1b811305f418145 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 13 Apr 2017 18:03:30 +0200 Subject: [PATCH 01/12] # 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 --- homeassistant/components/frontend/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 617db06be2cc1b..7a22f902add104 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -179,6 +179,10 @@ def setup(hass, config): register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location') + zwave = config.get('zwave') + if zwave: + register_built_in_panel(hass, 'zwave', 'Z-Wave', 'mdi:nfc') + for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template'): register_built_in_panel(hass, panel) From f9215b9b0a42f8a13dca7e02ea50cc99dcd7c23b Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 13 Apr 2017 18:03:30 +0200 Subject: [PATCH 02/12] Add seperate zwave panel --- homeassistant/components/frontend/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 7a22f902add104..617db06be2cc1b 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -179,10 +179,6 @@ def setup(hass, config): register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location') - zwave = config.get('zwave') - if zwave: - register_built_in_panel(hass, 'zwave', 'Z-Wave', 'mdi:nfc') - for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template'): register_built_in_panel(hass, panel) From 2e57aec7b4202d553e9774247feff9a1df6d06b5 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Tue, 16 May 2017 21:18:16 +0200 Subject: [PATCH 03/12] Modify set_config_parameter to accept setting string values --- homeassistant/components/zwave/__init__.py | 37 ++++++++++------------ tests/components/zwave/test_init.py | 29 +++-------------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index c49983b3178ab0..367575994ea711 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -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): cv.string, + vol.Optional(const.ATTR_CONFIG_SIZE): vol.Any(vol.Coerce(int), cv.string), }) PRINT_CONFIG_PARAMETER_SCHEMA = vol.Schema({ vol.Required(const.ATTR_NODE_ID): vol.Coerce(int), @@ -410,28 +410,23 @@ 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 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) - 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) + if value.index != param: + continue + if value.type in str([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) + break + else: + value.data = int(selection) + _LOGGER.info("Setting config parameter %s on Node %s " + "with selection %s", param, node_id, + selection) + break def print_config_parameter(service): """Print a config parameter from a node.""" diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index 57fd31be28f3a6..dc2b787de8d290 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -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, @@ -911,41 +912,21 @@ 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() - - self.hass.services.call('zwave', 'set_config_parameter', { - const.ATTR_NODE_ID: 14, - const.ATTR_CONFIG_PARAMETER: 12, - const.ATTR_CONFIG_VALUE: 0x01020304, - const.ATTR_CONFIG_SIZE: 4, - }) - self.hass.block_till_done() + assert value.data == 7 - 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][1] == 0x01020304 - assert node.set_config_param.mock_calls[0][1][2] == 4 - node.set_config_param.reset_mock() def test_print_config_parameter(self): """Test zwave print_config_parameter service.""" From b38ca8431b580de028dcedc3033734fb2b55c3bf Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 08:33:00 +0200 Subject: [PATCH 04/12] descriptions --- homeassistant/components/zwave/services.yaml | 218 +++++++++---------- 1 file changed, 108 insertions(+), 110 deletions(-) diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index 166bd4e6f81eeb..3c8284ec2ae375 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -1,110 +1,108 @@ -change_association: - description: Change an association in the Z-Wave network. - fields: - association: - description: Specify add or remove assosication - node_id: - description: Node id of the node to set association for. - target_node_id: - description: Node id of the node to associate to. - group: - description: Group number to set association for. - instance: - description: (Optional) Instance of association. Defaults to 0. - -add_node: - description: Add a new node to the Z-Wave network. Refer to OZW.log for details. - -add_node_secure: - description: Add a new node to the Z-Wave network with secure communications. Node must support this, and network key must be set. Refer to OZW.log for details. - -cancel_command: - description: Cancel a running Z-Wave controller command. Use this to exit add_node, if you wasn't going to use it but activated it. - -heal_network: - description: Start a Z-Wave network heal. This might take a while and will slow down the Z-Wave network greatly while it is being processed. Refer to OZW.log for details. - -remove_node: - description: Remove a node from the Z-Wave network. Refer to OZW.log for details. - -remove_failed_node: - descsription: This command will remove a failed node from the network. The node should be on the controllers failed nodes list, otherwise this command will fail. Refer to OZW.log for details. - fields: - node_id: - description: Node id of the device to remove (integer). - -replace_failed_node: - descsription: Replace a failed node with another. If the node is not in the controller's failed nodes list, or the node responds, this command will fail. Refer to OZW.log for details. - fields: - node_id: - description: Node id of the device to replace (integer). - -set_config_parameter: - description: Set a config parameter to a node on the Z-Wave network. - fields: - node_id: - description: Node id of the device to set config parameter to (integer). - 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. - -print_config_parameter: - description: Prints a Z-Wave node config parameter value to log. - fields: - node_id: - description: Node id of the device to print the parameter from (integer). - parameter: - description: Parameter number to print (integer). - -print_node: - description: Print all information about z-wave node. - fields: - node_id: - description: Node id of the device to print. - -refresh_entity: - description: Refresh zwave entity. - fields: - entity_id: - description: Name of the entity to refresh. - example: 'light.leviton_vrmx11lz_multilevel_scene_switch_level_40' - -refresh_node: - description: Refresh zwave node. - fields: - node_id: - description: ID of the node to refresh. - example: 10 - -set_wakeup: - description: Sets wake-up interval of a node. - fields: - node_id: - description: Node id of the device to set the wake-up interval for. (integer) - value: - description: Value of the interval to set. (integer) - -start_network: - description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is. - -stop_network: - description: Stop the Z-Wave network, all updates into HASS will stop. - -soft_reset: - description: This will reset the controller without removing its data. Use carefully because not all controllers support this. Refer to controllers manual. - -test_network: - description: This will send test to nodes in the Z-Wave network. This will greatly slow down the Z-Wave network while it is being processed. Refer to OZW.log for details. - -rename_node: - description: Set the name(s) of a node. - fields: - node_id: - description: ID of the node to rename. - example: 10 - name: - description: New Name - example: 'kitchen' +change_association: + description: Change an association in the Z-Wave network. + fields: + association: + description: Specify add or remove assosication + node_id: + description: Node id of the node to set association for. + target_node_id: + description: Node id of the node to associate to. + group: + description: Group number to set association for. + instance: + description: (Optional) Instance of association. Defaults to 0. + +add_node: + description: Add a new node to the Z-Wave network. Refer to OZW.log for details. + +add_node_secure: + description: Add a new node to the Z-Wave network with secure communications. Node must support this, and network key must be set. Refer to OZW.log for details. + +cancel_command: + description: Cancel a running Z-Wave controller command. Use this to exit add_node, if you wasn't going to use it but activated it. + +heal_network: + description: Start a Z-Wave network heal. This might take a while and will slow down the Z-Wave network greatly while it is being processed. Refer to OZW.log for details. + +remove_node: + description: Remove a node from the Z-Wave network. Refer to OZW.log for details. + +remove_failed_node: + descsription: This command will remove a failed node from the network. The node should be on the controllers failed nodes list, otherwise this command will fail. Refer to OZW.log for details. + fields: + node_id: + description: Node id of the device to remove (integer). + +replace_failed_node: + descsription: Replace a failed node with another. If the node is not in the controller's failed nodes list, or the node responds, this command will fail. Refer to OZW.log for details. + fields: + node_id: + description: Node id of the device to replace (integer). + +set_config_parameter: + description: Set a config parameter to a node on the Z-Wave network. + fields: + node_id: + description: Node id of the device to set config parameter to (integer). + parameter: + description: Parameter number to set (integer). + value: + description: Value to set on parameter. (String value for list and bool parameters, integer for others). + +print_config_parameter: + description: Prints a Z-Wave node config parameter value to log. + fields: + node_id: + description: Node id of the device to print the parameter from (integer). + parameter: + description: Parameter number to print (integer). + +print_node: + description: Print all information about z-wave node. + fields: + node_id: + description: Node id of the device to print. + +refresh_entity: + description: Refresh zwave entity. + fields: + entity_id: + description: Name of the entity to refresh. + example: 'light.leviton_vrmx11lz_multilevel_scene_switch_level_40' + +refresh_node: + description: Refresh zwave node. + fields: + node_id: + description: ID of the node to refresh. + example: 10 + +set_wakeup: + description: Sets wake-up interval of a node. + fields: + node_id: + description: Node id of the device to set the wake-up interval for. (integer) + value: + description: Value of the interval to set. (integer) + +start_network: + description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is. + +stop_network: + description: Stop the Z-Wave network, all updates into HASS will stop. + +soft_reset: + description: This will reset the controller without removing its data. Use carefully because not all controllers support this. Refer to controllers manual. + +test_network: + description: This will send test to nodes in the Z-Wave network. This will greatly slow down the Z-Wave network while it is being processed. Refer to OZW.log for details. + +rename_node: + description: Set the name(s) of a node. + fields: + node_id: + description: ID of the node to rename. + example: 10 + name: + description: New Name + example: 'kitchen' From aee711e180ae5f89132cf6c38b500cc909868278 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 08:58:20 +0200 Subject: [PATCH 05/12] Tweaks --- homeassistant/components/zwave/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 367575994ea711..3676bbf1a74c97 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -78,8 +78,7 @@ 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): cv.string, - vol.Optional(const.ATTR_CONFIG_SIZE): vol.Any(vol.Coerce(int), cv.string), + vol.Required(const.ATTR_CONFIG_VALUE): vol.Any(vol.Coerce(int), cv.string), }) PRINT_CONFIG_PARAMETER_SCHEMA = vol.Schema({ vol.Required(const.ATTR_NODE_ID): vol.Coerce(int), From 8684e1ca65eff789a26426157507dc55347e6334 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 09:05:29 +0200 Subject: [PATCH 06/12] Tweaks --- homeassistant/components/zwave/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 3676bbf1a74c97..e7ee9fd9cac3eb 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -414,11 +414,11 @@ def set_config_parameter(service): .values()): if value.index != param: continue - if value.type in str([const.TYPE_LIST, const.TYPE_BOOL]): + 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) + selection) break else: value.data = int(selection) From 4813613da31c1fb141b6e9f9e0fe13598044c531 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 09:15:11 +0200 Subject: [PATCH 07/12] Tweaks --- homeassistant/components/zwave/services.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index 3c8284ec2ae375..c067b5e995676e 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -47,7 +47,7 @@ set_config_parameter: parameter: description: Parameter number to set (integer). value: - description: Value to set on parameter. (String value for list and bool parameters, integer for others). + description: Value to set for parameter. (String value for list and bool parameters, integer for others). print_config_parameter: description: Prints a Z-Wave node config parameter value to log. From 089b7e873901d20e77acd20fa79fff7f695c028b Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 09:17:22 +0200 Subject: [PATCH 08/12] Tweaks --- homeassistant/components/zwave/services.yaml | 216 +++++++++---------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index c067b5e995676e..44ec1b3dbc2b2a 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -1,108 +1,108 @@ -change_association: - description: Change an association in the Z-Wave network. - fields: - association: - description: Specify add or remove assosication - node_id: - description: Node id of the node to set association for. - target_node_id: - description: Node id of the node to associate to. - group: - description: Group number to set association for. - instance: - description: (Optional) Instance of association. Defaults to 0. - -add_node: - description: Add a new node to the Z-Wave network. Refer to OZW.log for details. - -add_node_secure: - description: Add a new node to the Z-Wave network with secure communications. Node must support this, and network key must be set. Refer to OZW.log for details. - -cancel_command: - description: Cancel a running Z-Wave controller command. Use this to exit add_node, if you wasn't going to use it but activated it. - -heal_network: - description: Start a Z-Wave network heal. This might take a while and will slow down the Z-Wave network greatly while it is being processed. Refer to OZW.log for details. - -remove_node: - description: Remove a node from the Z-Wave network. Refer to OZW.log for details. - -remove_failed_node: - descsription: This command will remove a failed node from the network. The node should be on the controllers failed nodes list, otherwise this command will fail. Refer to OZW.log for details. - fields: - node_id: - description: Node id of the device to remove (integer). - -replace_failed_node: - descsription: Replace a failed node with another. If the node is not in the controller's failed nodes list, or the node responds, this command will fail. Refer to OZW.log for details. - fields: - node_id: - description: Node id of the device to replace (integer). - -set_config_parameter: - description: Set a config parameter to a node on the Z-Wave network. - fields: - node_id: - description: Node id of the device to set config parameter to (integer). - parameter: - description: Parameter number to set (integer). - value: - description: Value to set for parameter. (String value for list and bool parameters, integer for others). - -print_config_parameter: - description: Prints a Z-Wave node config parameter value to log. - fields: - node_id: - description: Node id of the device to print the parameter from (integer). - parameter: - description: Parameter number to print (integer). - -print_node: - description: Print all information about z-wave node. - fields: - node_id: - description: Node id of the device to print. - -refresh_entity: - description: Refresh zwave entity. - fields: - entity_id: - description: Name of the entity to refresh. - example: 'light.leviton_vrmx11lz_multilevel_scene_switch_level_40' - -refresh_node: - description: Refresh zwave node. - fields: - node_id: - description: ID of the node to refresh. - example: 10 - -set_wakeup: - description: Sets wake-up interval of a node. - fields: - node_id: - description: Node id of the device to set the wake-up interval for. (integer) - value: - description: Value of the interval to set. (integer) - -start_network: - description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is. - -stop_network: - description: Stop the Z-Wave network, all updates into HASS will stop. - -soft_reset: - description: This will reset the controller without removing its data. Use carefully because not all controllers support this. Refer to controllers manual. - -test_network: - description: This will send test to nodes in the Z-Wave network. This will greatly slow down the Z-Wave network while it is being processed. Refer to OZW.log for details. - -rename_node: - description: Set the name(s) of a node. - fields: - node_id: - description: ID of the node to rename. - example: 10 - name: - description: New Name - example: 'kitchen' +change_association: + description: Change an association in the Z-Wave network. + fields: + association: + description: Specify add or remove assosication + node_id: + description: Node id of the node to set association for. + target_node_id: + description: Node id of the node to associate to. + group: + description: Group number to set association for. + instance: + description: (Optional) Instance of association. Defaults to 0. + +add_node: + description: Add a new node to the Z-Wave network. Refer to OZW.log for details. + +add_node_secure: + description: Add a new node to the Z-Wave network with secure communications. Node must support this, and network key must be set. Refer to OZW.log for details. + +cancel_command: + description: Cancel a running Z-Wave controller command. Use this to exit add_node, if you wasn't going to use it but activated it. + +heal_network: + description: Start a Z-Wave network heal. This might take a while and will slow down the Z-Wave network greatly while it is being processed. Refer to OZW.log for details. + +remove_node: + description: Remove a node from the Z-Wave network. Refer to OZW.log for details. + +remove_failed_node: + descsription: This command will remove a failed node from the network. The node should be on the controllers failed nodes list, otherwise this command will fail. Refer to OZW.log for details. + fields: + node_id: + description: Node id of the device to remove (integer). + +replace_failed_node: + descsription: Replace a failed node with another. If the node is not in the controller's failed nodes list, or the node responds, this command will fail. Refer to OZW.log for details. + fields: + node_id: + description: Node id of the device to replace (integer). + +set_config_parameter: + description: Set a config parameter to a node on the Z-Wave network. + fields: + node_id: + description: Node id of the device to set config parameter to (integer). + parameter: + description: Parameter number to set (integer). + value: + description: Value to set for parameter. (String value for list and bool parameters, integer for others). + +print_config_parameter: + description: Prints a Z-Wave node config parameter value to log. + fields: + node_id: + description: Node id of the device to print the parameter from (integer). + parameter: + description: Parameter number to print (integer). + +print_node: + description: Print all information about z-wave node. + fields: + node_id: + description: Node id of the device to print. + +refresh_entity: + description: Refresh zwave entity. + fields: + entity_id: + description: Name of the entity to refresh. + example: 'light.leviton_vrmx11lz_multilevel_scene_switch_level_40' + +refresh_node: + description: Refresh zwave node. + fields: + node_id: + description: ID of the node to refresh. + example: 10 + +set_wakeup: + description: Sets wake-up interval of a node. + fields: + node_id: + description: Node id of the device to set the wake-up interval for. (integer) + value: + description: Value of the interval to set. (integer) + +start_network: + description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is. + +stop_network: + description: Stop the Z-Wave network, all updates into HASS will stop. + +soft_reset: + description: This will reset the controller without removing its data. Use carefully because not all controllers support this. Refer to controllers manual. + +test_network: + description: This will send test to nodes in the Z-Wave network. This will greatly slow down the Z-Wave network while it is being processed. Refer to OZW.log for details. + +rename_node: + description: Set the name(s) of a node. + fields: + node_id: + description: ID of the node to rename. + example: 10 + name: + description: New Name + example: 'kitchen' From 7f4680f8d47a467cde477c85398cbe69fa1fbdab Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 11:05:36 +0200 Subject: [PATCH 09/12] lint --- tests/components/zwave/test_init.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index dc2b787de8d290..ba5e98175e5f7a 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -927,7 +927,6 @@ def test_set_config_parameter(self): assert value.data == 7 - def test_print_config_parameter(self): """Test zwave print_config_parameter service.""" value1 = MockValue( From 75b29badc4d671fd2f577c6ab71aa90cd12410c3 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 13:33:10 +0200 Subject: [PATCH 10/12] Fallback if no config parameteres are available --- homeassistant/components/zwave/__init__.py | 7 +++++++ tests/components/zwave/test_init.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index e7ee9fd9cac3eb..9f71a04a338468 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -79,6 +79,7 @@ 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.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), @@ -409,12 +410,15 @@ 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) + param_set = False for value in ( node.get_values(class_id=const.COMMAND_CLASS_CONFIGURATION) .values()): if value.index != param: continue if value.type in [const.TYPE_LIST, const.TYPE_BOOL]: + param_set = True value.data = selection _LOGGER.info("Setting config list parameter %s on Node %s " "with selection %s", param, node_id, @@ -422,10 +426,13 @@ def set_config_parameter(service): break else: value.data = int(selection) + param_set = True _LOGGER.info("Setting config parameter %s on Node %s " "with selection %s", param, node_id, selection) break + if not param_set: + node.set_config_param(param, selection, size) def print_config_parameter(service): """Print a config parameter from a node.""" diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index ba5e98175e5f7a..17fac86c748455 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -927,6 +927,21 @@ def test_set_config_parameter(self): 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 + }) + 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] == 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() + def test_print_config_parameter(self): """Test zwave print_config_parameter service.""" value1 = MockValue( From 59d6012b6500f24218412e08709ec56e05e39295 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 13:37:00 +0200 Subject: [PATCH 11/12] Update services.yaml --- homeassistant/components/zwave/services.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index 44ec1b3dbc2b2a..feacf8229aa723 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -48,6 +48,8 @@ set_config_parameter: description: Parameter number to set (integer). value: description: Value to set for parameter. (String value for list and bool parameters, integer for others). + size: + 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. From 29f7d25c945428ab72d143a27174270d999e3afc Mon Sep 17 00:00:00 2001 From: turbokongen Date: Thu, 18 May 2017 17:09:56 +0200 Subject: [PATCH 12/12] review changes --- homeassistant/components/zwave/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 9f71a04a338468..30867706a30293 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -411,28 +411,27 @@ def set_config_parameter(service): param = service.data.get(const.ATTR_CONFIG_PARAMETER) selection = service.data.get(const.ATTR_CONFIG_VALUE) size = service.data.get(const.ATTR_CONFIG_SIZE) - param_set = False for value in ( node.get_values(class_id=const.COMMAND_CLASS_CONFIGURATION) .values()): if value.index != param: continue if value.type in [const.TYPE_LIST, const.TYPE_BOOL]: - param_set = True value.data = selection _LOGGER.info("Setting config list parameter %s on Node %s " "with selection %s", param, node_id, selection) - break + return else: value.data = int(selection) - param_set = True _LOGGER.info("Setting config parameter %s on Node %s " "with selection %s", param, node_id, selection) - break - if not param_set: - node.set_config_param(param, selection, size) + 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."""