From: Benjamin Braatz Date: Sun, 7 Mar 2021 00:34:06 +0000 (+0100) Subject: Add GenericWait plugin X-Git-Tag: v0.3.0~68 X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=a6ee9963673c39c5001dbd24c2d7f623a7497c2a;p=graphit%2Fcontrolpi.git Add GenericWait plugin --- diff --git a/controlpi-plugins/util.py b/controlpi-plugins/util.py index c51e81e..d59b333 100644 --- a/controlpi-plugins/util.py +++ b/controlpi-plugins/util.py @@ -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 = {}