Use GenericWait in example config and client
authorBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 02:23:04 +0000 (03:23 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 02:23:04 +0000 (03:23 +0100)
conf.json
example-client.py

index 10b4afcd831c4568c3c66d3956f53b83a181d80c..e63585135b5c38250f133388e2c7435f051d4088 100644 (file)
--- a/conf.json
+++ b/conf.json
@@ -7,19 +7,34 @@
     "Example State": {
         "plugin": "State"
     },
-    "Off Delay": {
-        "plugin": "Wait",
-        "seconds": 1.0
+    "Waiter": {
+        "plugin": "GenericWait"
     },
     "Delay Start after On": {
         "plugin": "Alias",
-        "from": { "sender": "Example State", "event": "changed", "state": true },
-        "to": { "target": "Off Delay", "command": "wait" }
+        "from": {
+            "sender": "Example State",
+            "event": "changed",
+            "state": true
+        },
+        "to": {
+            "target": "Waiter",
+            "command": "wait",
+            "seconds": 5.0,
+            "id": "off delay"
+        }
     },
     "State Off after Delay": {
         "plugin": "Alias",
-        "from": { "sender": "Off Delay", "event": "finished" },
-        "to": { "target": "Example State", "command": "set state", "new state": false }
+        "from": {
+            "sender": "Waiter",
+            "id": "off delay"
+        },
+        "to": {
+            "target": "Example State",
+            "command": "set state",
+            "new state": false
+        }
     },
     "Debug Logger": {
         "plugin": "Log",
index 367666e0186581bcbfe01ec631ed4d708a699968..bd4b8e754e9f229d6701c6faaa7aab692da15723 100644 (file)
@@ -6,9 +6,9 @@ import websockets
 
 async def test_commands(websocket):
     commands = [{'target': 'Example State',
-                 'command': 'set state', 'new state': True},
-                {'target': 'Example State', 'command':
-                 'get state'}]
+                 'command': 'get state'},
+                {'target': 'Example State',
+                 'command': 'set state', 'new state': True}]
     for command in commands:
         message = json.dumps(command)
         await websocket.send(message)
@@ -30,8 +30,8 @@ async def main():
         await command_task
         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)
+        print("Wait for 6.9 seconds for delayed messages.")
+        await asyncio.sleep(6.9)
     async with websockets.connect(f"ws://localhost:8080/Example-Client")\
             as websocket:
         print("Sending commands to websocket 'Example-Client'.")
@@ -42,8 +42,8 @@ async def main():
         await command_task
         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)
+        print("Wait for 6.9 seconds for delayed messages.")
+        await asyncio.sleep(6.9)
 
 if __name__ == '__main__':
     asyncio.run(main())