From: Benjamin Braatz Date: Tue, 21 Sep 2021 18:56:35 +0000 (+0200) Subject: Only add templates once if present multiple times. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=5c9963e459f7455b26d9d542d4a8afcaae408cd4;p=graphit%2Fcontrolpi-statemachine.git Only add templates once if present multiple times. --- 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)