Add GenericWait plugin
authorBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 00:34:06 +0000 (01:34 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 00:39:45 +0000 (01:39 +0100)
controlpi-plugins/util.py

index c51e81ea85d4406a2428d9e754a31b5e6dfc6e13..d59b33313b04bb95c0cc375063640cece62e7d64 100644 (file)
@@ -54,6 +54,19 @@ class Wait(BasePlugin):
         super()._process_conf(conf)
 
 
+class GenericWait(BasePlugin):
+    async def _wait(self, message: Message) -> None:
+        await asyncio.sleep(message['seconds'])
+        await self._bus.send({'sender': self._name, 'id': message['id']})
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        receives = [{'target': self._name, 'command': 'wait',
+                     'seconds': float, 'id': str}]
+        sends = [{'id': str}]
+        self._bus.register(self._name, sends, receives, self._wait)
+        super()._process_conf(conf)
+
+
 class Alias(BasePlugin):
     async def _alias(self, message: Message) -> None:
         alias_message = {}