From b2928a6f21fe4f92ed44a027eb5507e7bcb6c58b Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Fri, 5 Mar 2021 09:09:05 +0100 Subject: [PATCH] Streamline example --- conf.json | 2 +- example-client.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/conf.json b/conf.json index 1212f96..740d854 100644 --- a/conf.json +++ b/conf.json @@ -9,7 +9,7 @@ }, "Off Delay": { "plugin": "Wait", - "seconds": 2.0 + "seconds": 1.0 }, "Delay Start after On": { "plugin": "Alias", diff --git a/example-client.py b/example-client.py index ebb5892..d87a5a2 100644 --- a/example-client.py +++ b/example-client.py @@ -11,7 +11,6 @@ async def test_commands(websocket): message = json.dumps(command) await websocket.send(message) print(f"Sent: {message}") - await asyncio.sleep(0) async def receive_events(websocket): @@ -21,15 +20,27 @@ async def receive_events(websocket): async def main(): async with websockets.connect(f"ws://localhost:8080") as websocket: + print("Sending commands to anonymous websocket.") command_task = asyncio.create_task(test_commands(websocket)) + print("Receiving messages from the websocket.") event_task = asyncio.create_task(receive_events(websocket)) + print("Await command sending task.") await command_task - await asyncio.sleep(3.0) + print("Wait for 0.1 seconds for command messages.") + await asyncio.sleep(0.1) + print("Wait for 1.9 seconds for delayed messages.") + await asyncio.sleep(1.9) async with websockets.connect(f"ws://localhost:8080/Example-Client") as websocket: + print("Sending commands to websocket 'Example-Client'.") command_task = asyncio.create_task(test_commands(websocket)) + print("Receiving messages from the websocket.") event_task = asyncio.create_task(receive_events(websocket)) + print("Await command sending task.") await command_task - await asyncio.sleep(3.0) + print("Wait for 0.1 seconds for command messages.") + await asyncio.sleep(0.1) + print("Wait for 1.9 seconds for delayed messages.") + await asyncio.sleep(1.9) if __name__ == '__main__': asyncio.run(main()) -- 2.34.1