From b79e6ce27a117ce8c7579cc7b51229c7379ee9d2 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Sun, 7 Mar 2021 03:23:04 +0100 Subject: [PATCH] Use GenericWait in example config and client --- conf.json | 29 ++++++++++++++++++++++------- example-client.py | 14 +++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/conf.json b/conf.json index 10b4afc..e635851 100644 --- 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", diff --git a/example-client.py b/example-client.py index 367666e..bd4b8e7 100644 --- a/example-client.py +++ b/example-client.py @@ -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()) -- 2.34.1