From 5c9963e459f7455b26d9d542d4a8afcaae408cd4 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Tue, 21 Sep 2021 20:56:35 +0200 Subject: [PATCH] Only add templates once if present multiple times. --- controlpi_plugins/statemachine.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/controlpi_plugins/statemachine.py b/controlpi_plugins/statemachine.py index 089cc79..05b6025 100644 --- a/controlpi_plugins/statemachine.py +++ b/controlpi_plugins/statemachine.py @@ -1,9 +1,3 @@ -"""Provide state machine plugin. - -… - -TODO: documentation, doctests -""" from controlpi import BasePlugin, Message, MessageTemplate @@ -95,10 +89,14 @@ class StateMachine(BasePlugin): for state in self.conf['states']: commands = self.conf['states'][state]['commands'] for command in commands: - sends.append(MessageTemplate.from_message(command)) + template = MessageTemplate.from_message(command) + if template not in sends: + sends.append(template) transitions = self.conf['states'][state]['transitions'] for transition in transitions: - receives.append(MessageTemplate(transition['trigger'])) + template = MessageTemplate(transition['trigger']) + if template not in receives: + receives.append(template) self.bus.register(self.name, 'StateMachine', sends, receives, self._receive) -- 2.34.1