From: Benjamin Braatz Date: Wed, 29 Sep 2021 02:45:36 +0000 (+0200) Subject: Message filter instead of states. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=e98f09a56240a2551a1de32428f5f81ed668f636;p=graphit%2Fcontrolpi-graph.git Message filter instead of states. --- diff --git a/controlpi_plugins/graph.py b/controlpi_plugins/graph.py index 99e5a1c..66da632 100644 --- a/controlpi_plugins/graph.py +++ b/controlpi_plugins/graph.py @@ -18,8 +18,8 @@ class Graph(BasePlugin): {'url': {'type': 'string'}, 'crt': {'type': 'string'}, 'name': {'type': 'string'}, - 'states': {'type': 'array', - 'items': {'type': 'string'}}}, + 'filter': {'type': 'array', + 'items': {'type': 'object'}}}, 'required': ['url', 'crt', 'name', 'states']} def process_conf(self) -> None: @@ -38,10 +38,9 @@ class Graph(BasePlugin): receives: List[MessageTemplate] = [] receives.append(MessageTemplate({'target': {'const': self.name}, 'command': {'const': 'sync'}})) - self._states: Dict[str, Any] = {} - for state in self.conf['states']: - receives.append(MessageTemplate({'sender': {'const': state}})) - self._states[state] = None + for template in self.conf['filter']: + receives.append(template) + self._messages: List[Message] = [] self.bus.register(self.name, 'Graph', sends, receives, self._receive) @@ -53,20 +52,12 @@ class Graph(BasePlugin): await self._call('verknuepfe', [comessage_guid, self._coroot_guid]) await self._call('setze', [comessage_guid, 'comessage_json', - json.dumps(self._states)]) + json.dumps(self._messages)]) + self._messages = [] await self._call('setze', [comessage_guid, 'comessage_ready', True]) - if 'state' in message: - sender = None - if message['sender'] in self.conf['states']: - sender = message['sender'] - elif ('original sender' in message and - message['original sender'] in self.conf['states']): - sender = message['original sender'] - if (isinstance(sender, str) - and (isinstance(message['state'], str) - or not isinstance(self._states[sender], str))): - self._states[sender] = message['state'] + else: + self._messages.append(message) async def _call(self, method, params): (reader, writer) = await asyncio.open_connection(self._host,