From eac1f029e584fa46e09b8e61cfed8fed3380396f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 4 Mar 2020 17:40:58 -0800 Subject: [PATCH] Allow string values on zwave.set_node_value (#31061) * Allow string values on zwave.set_node_value This allows for: * Accessing longer value_ids. In some cases, value ids in z-wave nodes are very large (17 digits in my case). Passing them as int does not seem to work well (python probably truncates the number), but passing them as string works fine * Changing color values, which are represented as hex string reformat test * update services.yaml with string set_node_value --- homeassistant/components/zwave/__init__.py | 4 ++-- homeassistant/components/zwave/services.yaml | 4 ++-- tests/components/zwave/test_init.py | 25 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index ba7e26ee58c0..1491c10777ff 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -126,8 +126,8 @@ SET_CONFIG_PARAMETER_SCHEMA = vol.Schema( SET_NODE_VALUE_SCHEMA = vol.Schema( { vol.Required(const.ATTR_NODE_ID): vol.Coerce(int), - vol.Required(const.ATTR_VALUE_ID): vol.Coerce(int), - vol.Required(const.ATTR_CONFIG_VALUE): vol.Coerce(int), + vol.Required(const.ATTR_VALUE_ID): vol.Any(vol.Coerce(int), cv.string), + vol.Required(const.ATTR_CONFIG_VALUE): vol.Any(vol.Coerce(int), cv.string), } ) diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index 9d3d2b0cadf4..d908941fb925 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -75,9 +75,9 @@ set_node_value: node_id: description: Node id of the device to set the value on (integer). value_id: - description: Value id of the value to set (integer). + description: Value id of the value to set (integer or string). value: - description: Value to set (integer). + description: Value to set (integer or string). refresh_node_value: description: Refresh the value for a given value_id on a Z-Wave device. diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index a8f72d2105cf..4d358bde770c 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -1797,6 +1797,31 @@ class TestZWaveServices(unittest.TestCase): assert self.zwave_network.nodes[14].values[12].data == 2 + def test_set_node_value_with_long_id_and_text_value(self): + """Test zwave set_node_value service.""" + value = MockValue( + index=87512398541236578, + command_class=const.COMMAND_CLASS_SWITCH_COLOR, + data="#ff0000", + ) + node = MockNode(node_id=14, command_classes=[const.COMMAND_CLASS_SWITCH_COLOR]) + node.values = {87512398541236578: value} + node.get_values.return_value = node.values + self.zwave_network.nodes = {14: node} + + self.hass.services.call( + "zwave", + "set_node_value", + { + const.ATTR_NODE_ID: 14, + const.ATTR_VALUE_ID: "87512398541236578", + const.ATTR_CONFIG_VALUE: "#00ff00", + }, + ) + self.hass.block_till_done() + + assert self.zwave_network.nodes[14].values[87512398541236578].data == "#00ff00" + def test_refresh_node_value(self): """Test zwave refresh_node_value service.""" node = MockNode(