Skip to content

Commit 921a18e

Browse files
authored
Handle wait for result concerns (#744)
* Handle wait for result concerns * fix test * Add coverage * fix tests
1 parent fd4d999 commit 921a18e

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

test/model/test_node.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,15 +2199,17 @@ async def test_manually_idle_notification_value(
21992199
await node.async_manually_idle_notification_value(f"{node.node_id}-112-0-255")
22002200

22012201

2202-
async def test_set_date_and_time(multisensor_6: node_pkg.Node, uuid4, mock_command):
2203-
"""Test node.set_date_and_time command."""
2202+
async def test_set_date_and_time_no_wait(
2203+
multisensor_6: node_pkg.Node, uuid4, mock_command
2204+
):
2205+
"""Test node.set_date_and_time command without waiting."""
22042206
node = multisensor_6
22052207
ack_commands = mock_command(
22062208
{"command": "node.set_date_and_time", "nodeId": node.node_id},
22072209
{"success": True},
22082210
)
22092211

2210-
assert await node.async_set_date_and_time(datetime(2020, 1, 1, 12, 0, 0))
2212+
assert await node.async_set_date_and_time(datetime(2020, 1, 1, 12, 0, 0)) is None
22112213

22122214
assert len(ack_commands) == 1
22132215
assert ack_commands[0] == {
@@ -2217,9 +2219,26 @@ async def test_set_date_and_time(multisensor_6: node_pkg.Node, uuid4, mock_comma
22172219
"messageId": uuid4,
22182220
}
22192221

2220-
# Raise ValueError if the value is not for the right CommandClass
2221-
with pytest.raises(ValueError):
2222-
await node.async_manually_idle_notification_value(f"{node.node_id}-112-0-255")
2222+
2223+
async def test_set_date_and_time(
2224+
climate_radio_thermostat_ct100_plus: node_pkg.Node, uuid4, mock_command
2225+
):
2226+
"""Test node.set_date_and_time command while waiting for response."""
2227+
node = climate_radio_thermostat_ct100_plus
2228+
ack_commands = mock_command(
2229+
{"command": "node.set_date_and_time", "nodeId": node.node_id},
2230+
{"success": True},
2231+
)
2232+
2233+
assert await node.async_set_date_and_time(datetime(2020, 1, 1, 12, 0, 0))
2234+
2235+
assert len(ack_commands) == 1
2236+
assert ack_commands[0] == {
2237+
"command": "node.set_date_and_time",
2238+
"nodeId": node.node_id,
2239+
"date": "2020-01-01T12:00:00",
2240+
"messageId": uuid4,
2241+
}
22232242

22242243

22252244
async def test_get_date_and_time(multisensor_6: node_pkg.Node, uuid4, mock_command):

zwave_js_server/model/node/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ async def async_get_firmware_update_capabilities_cached(
621621

622622
async def async_abort_firmware_update(self) -> None:
623623
"""Send abortFirmwareUpdate command to Node."""
624-
await self.async_send_command("abort_firmware_update", wait_for_result=True)
624+
await self.async_send_command("abort_firmware_update", wait_for_result=False)
625625

626626
async def async_poll_value(self, val: Value | str) -> None:
627627
"""Send pollValue command to Node for given value (or value_id)."""
@@ -855,7 +855,9 @@ async def async_manually_idle_notification_value(self, val: Value | str) -> None
855855
wait_for_result=False,
856856
)
857857

858-
async def async_set_date_and_time(self, datetime_: datetime | None = None) -> bool:
858+
async def async_set_date_and_time(
859+
self, datetime_: datetime | None = None, wait_for_result: bool | None = None
860+
) -> bool | None:
859861
"""Send setDateAndTime command to Node."""
860862
args = {}
861863
if datetime_:
@@ -864,10 +866,11 @@ async def async_set_date_and_time(self, datetime_: datetime | None = None) -> bo
864866
"set_date_and_time",
865867
**args,
866868
require_schema=28,
867-
wait_for_result=True,
869+
wait_for_result=wait_for_result,
868870
)
869-
assert data
870-
return cast(bool, data["success"])
871+
if data:
872+
return cast(bool, data["success"])
873+
return None
871874

872875
async def async_get_date_and_time(self) -> DateAndTime:
873876
"""Send getDateAndTime command to Node."""
@@ -894,7 +897,7 @@ async def async_abort_health_check(self) -> None:
894897
await self.async_send_command(
895898
"abort_health_check",
896899
require_schema=31,
897-
wait_for_result=True,
900+
wait_for_result=False,
898901
)
899902

900903
async def async_set_default_volume(

0 commit comments

Comments
 (0)