11"""Test node utility functions."""
22import pytest
33
4- from zwave_js_server .const import CommandClass
5- from zwave_js_server .exceptions import InvalidNewValue , NotFoundError , ValueTypeError
4+ from zwave_js_server .const import CommandClass , CommandStatus
5+ from zwave_js_server .exceptions import (
6+ InvalidNewValue ,
7+ NotFoundError ,
8+ SetValueFailed ,
9+ ValueTypeError ,
10+ )
611from zwave_js_server .model .node import Node
712from zwave_js_server .model .value import ConfigurationValue
813from zwave_js_server .util .node import (
@@ -47,7 +52,9 @@ async def test_configuration_parameter_values(
4752 {"success" : True },
4853 )
4954
50- await async_set_config_parameter (node_2 , 190 , 8 , 255 )
55+ zwave_value , cmd_status = await async_set_config_parameter (node_2 , 190 , 8 , 255 )
56+ assert isinstance (zwave_value , ConfigurationValue )
57+ assert cmd_status == CommandStatus .ACCEPTED
5158
5259 value = node_2 .values ["31-112-0-8-255" ]
5360 assert len (ack_commands_2 ) == 1
@@ -59,7 +66,9 @@ async def test_configuration_parameter_values(
5966 "messageId" : uuid4 ,
6067 }
6168
62- await async_set_config_parameter (node_2 , "Blue" , 8 , 255 )
69+ zwave_value , cmd_status = await async_set_config_parameter (node_2 , "Blue" , 8 , 255 )
70+ assert isinstance (zwave_value , ConfigurationValue )
71+ assert cmd_status == CommandStatus .ACCEPTED
6372
6473 value = node_2 .values ["31-112-0-8-255" ]
6574 assert len (ack_commands_2 ) == 2
@@ -92,9 +101,11 @@ async def test_configuration_parameter_values(
92101 await async_set_config_parameter (node , 1 , 1 , property_key = 1 )
93102
94103 # Test setting a configuration parameter by state label and property name
95- await async_set_config_parameter (
104+ zwave_value , cmd_status = await async_set_config_parameter (
96105 node , "2.0\u00b0 F" , "Temperature Reporting Threshold"
97106 )
107+ assert isinstance (zwave_value , ConfigurationValue )
108+ assert cmd_status == CommandStatus .ACCEPTED
98109
99110 value = node .values ["13-112-0-1" ]
100111 assert len (ack_commands ) == 3
@@ -114,7 +125,8 @@ async def test_bulk_set_partial_config_parameters(multisensor_6, uuid4, mock_com
114125 {"command" : "node.set_value" , "nodeId" : node .node_id },
115126 {"success" : True },
116127 )
117- await async_bulk_set_partial_config_parameters (node , 101 , 241 )
128+ cmd_status = await async_bulk_set_partial_config_parameters (node , 101 , 241 )
129+ assert cmd_status == CommandStatus .QUEUED
118130 assert len (ack_commands ) == 1
119131 assert ack_commands [0 ] == {
120132 "command" : "node.set_value" ,
@@ -127,9 +139,10 @@ async def test_bulk_set_partial_config_parameters(multisensor_6, uuid4, mock_com
127139 "messageId" : uuid4 ,
128140 }
129141
130- await async_bulk_set_partial_config_parameters (
142+ cmd_status = await async_bulk_set_partial_config_parameters (
131143 node , 101 , {128 : 1 , 64 : 1 , 32 : 1 , 16 : 1 , 1 : 1 }
132144 )
145+ assert cmd_status == CommandStatus .QUEUED
133146 assert len (ack_commands ) == 2
134147 assert ack_commands [1 ] == {
135148 "command" : "node.set_value" ,
@@ -143,9 +156,10 @@ async def test_bulk_set_partial_config_parameters(multisensor_6, uuid4, mock_com
143156 }
144157
145158 # Only set some values so we use cached values for the rest
146- await async_bulk_set_partial_config_parameters (
159+ cmd_status = await async_bulk_set_partial_config_parameters (
147160 node , 101 , {64 : 1 , 32 : 1 , 16 : 1 , 1 : 1 }
148161 )
162+ assert cmd_status == CommandStatus .QUEUED
149163 assert len (ack_commands ) == 3
150164 assert ack_commands [2 ] == {
151165 "command" : "node.set_value" ,
@@ -171,3 +185,44 @@ async def test_bulk_set_partial_config_parameters(multisensor_6, uuid4, mock_com
171185 # Try to bulkset a property that isn't broken into partials
172186 with pytest .raises (ValueTypeError ):
173187 await async_bulk_set_partial_config_parameters (node , 252 , 1 )
188+
189+
190+ async def test_failures (multisensor_6 , mock_command ):
191+ """Test setting config parameter failures."""
192+ node : Node = multisensor_6
193+ # We need the node to be alive so we wait for a response
194+ node .handle_alive (node )
195+
196+ mock_command (
197+ {"command" : "node.set_value" , "nodeId" : node .node_id },
198+ {"success" : False },
199+ )
200+
201+ with pytest .raises (SetValueFailed ):
202+ await async_bulk_set_partial_config_parameters (
203+ node , 101 , {64 : 1 , 32 : 1 , 16 : 1 , 1 : 1 }
204+ )
205+
206+ with pytest .raises (SetValueFailed ):
207+ await async_set_config_parameter (node , 1 , 101 , 64 )
208+
209+
210+ async def test_returned_values (multisensor_6 , mock_command ):
211+ """Test returned values from setting config parameters."""
212+ node : Node = multisensor_6
213+ # We need the node to be alive so we wait for a response
214+ node .handle_alive (node )
215+
216+ mock_command (
217+ {"command" : "node.set_value" , "nodeId" : node .node_id },
218+ {"success" : True },
219+ )
220+
221+ cmd_status = await async_bulk_set_partial_config_parameters (
222+ node , 101 , {64 : 1 , 32 : 1 , 16 : 1 , 1 : 1 }
223+ )
224+ assert cmd_status == CommandStatus .ACCEPTED
225+
226+ zwave_value , cmd_status = await async_set_config_parameter (node , 1 , 101 , 64 )
227+ assert isinstance (zwave_value , ConfigurationValue )
228+ assert cmd_status == CommandStatus .ACCEPTED
0 commit comments