From c1ee9504652e30e99425848c2016de0c385279b9 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Tue, 2 Mar 2021 17:16:04 +0100 Subject: [PATCH] Add Alias plugin with example in conf.json --- conf.json | 11 ++++++++++- controlpi/plugins/util.py | 17 ++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/conf.json b/conf.json index 55c13e0..077a332 100644 --- 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" } ] }, diff --git a/controlpi/plugins/util.py b/controlpi/plugins/util.py index 7d3b511..ad84814 100644 --- a/controlpi/plugins/util.py +++ b/controlpi/plugins/util.py @@ -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) -- 2.34.1