Add Alias plugin with example in conf.json
authorBenjamin Braatz <bb@bbraatz.eu>
Tue, 2 Mar 2021 16:16:04 +0000 (17:16 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Tue, 2 Mar 2021 16:16:04 +0000 (17:16 +0100)
conf.json
controlpi/plugins/util.py

index 55c13e0eaa42f04d5735070067b17417f637be83..077a332e510c64bd9ec9ddeba26867a7613b9300 100644 (file)
--- a/conf.json
+++ b/conf.json
@@ -1,4 +1,14 @@
 {
+    "TriggerWait2": {
+        "plugin": "Alias",
+        "from": { "sender": "Wait1", "event": "finished" },
+        "to": { "target": "Wait2", "command": "wait" }
+    },
+    "TriggerWait1": {
+        "plugin": "Alias",
+        "from": { "sender": "Wait2", "event": "finished" },
+        "to": { "target": "Wait1", "command": "wait" }
+    },
     "Wait1": {
         "plugin": "Wait",
         "seconds": 1.0
@@ -12,7 +22,6 @@
         "messages": [
             { "event": "started" },
             { "target": "Wait1", "command": "wait" },
-            { "target": "Wait2", "command": "wait" },
             { "event": "stopped" }
         ]
     },
index 7d3b51149577e73e9df8041064ee56f330954930..ad8481402b40eaa1d10623670240cf0ac1b044d6 100644 (file)
@@ -1,7 +1,7 @@
 """Provide utility plugins for all kinds of systems.
 
-TODO: documentation, doctests, check configurations
-TODO: Keyboard, State, AndState, OrState
+TODO: documentation, doctests, check configurations during _process_conf
+TODO: State, AndState, OrState?
 """
 import asyncio
 
@@ -55,13 +55,16 @@ class Wait(BasePlugin):
 
 
 class Alias(BasePlugin):
-    async def _alias(self, message):
-        alias_message = {"name": self._name}
+    async def _alias(self, message: Message) -> None:
+        alias_message = {}
+        alias_message['sender'] = self._name
+        alias_message.update(self._to)
         for key in message:
-            if key not in self._aliasfor:
+            if key != 'sender' and key not in self._from:
                 alias_message[key] = message[key]
         await self._bus.send(alias_message)
 
     def _process_conf(self, conf):
-        self._aliasfor = conf['aliasfor']
-        self._bus.register(conf['aliasfor'], self._alias)
+        self._from = conf['from']
+        self._to = conf['to']
+        self._bus.register(self._name, [self._to], [self._from], self._alias)