Streamline example
authorBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 08:09:05 +0000 (09:09 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 08:09:05 +0000 (09:09 +0100)
conf.json
example-client.py

index 1212f9670b800f2788bf7f2c43f408a0a81649dc..740d854fdfaebb00a2c683bca2fa8ef105cd1411 100644 (file)
--- 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",
index ebb5892eabb723c4f7dc57af4ae6c0a4b4edebdc..d87a5a2f2930c6ea36009a9869cf410bd59dc6d8 100644 (file)
@@ -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())