Skip to content

Commit 18b9d8e

Browse files
authored
Wait for node command completion when node is dead (#1250)
* Wait for node command completion when node is dead * Add test to ensure we no longer wait when node goes dead * fix lint
1 parent 4d67440 commit 18b9d8e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

test/model/test_node.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,25 @@ async def async_send_command(
407407
assert task_2.done()
408408
assert task_2.result() is None
409409

410+
# mark node as alive
411+
event = Event(type="alive")
412+
node.handle_alive(event)
413+
task = asyncio.create_task(node.async_send_command("mock_cmd"))
414+
task_2 = asyncio.create_task(node.endpoints[0].async_send_command("mock_cmd"))
415+
await asyncio.sleep(0.01)
416+
# we are waiting for the response
417+
assert not task.done()
418+
assert not task_2.done()
419+
# node is marked dead
420+
event = Event(type="dead")
421+
node.handle_dead(event)
422+
await asyncio.sleep(0.01)
423+
# we are no longer waiting for the response
424+
assert task.done()
425+
assert task.result() is None
426+
assert task_2.done()
427+
assert task_2.result() is None
428+
410429

411430
async def test_poll_value(multisensor_6, uuid4, mock_command):
412431
"""Test poll value."""

zwave_js_server/model/node/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,7 @@ async def async_send_command(
503503
if wait_for_result:
504504
result = await self.client.async_send_command(message, **kwargs)
505505
return result
506-
if wait_for_result is None and self.status not in (
507-
NodeStatus.ASLEEP,
508-
NodeStatus.DEAD,
509-
):
506+
if wait_for_result is None and self.status not in (NodeStatus.ASLEEP,):
510507
result_task = asyncio.create_task(
511508
self.client.async_send_command(message, **kwargs)
512509
)

0 commit comments

Comments
 (0)