From: Benjamin Braatz Date: Wed, 21 May 2025 10:00:06 +0000 (+0200) Subject: Only create comessage instance if coroot instance found. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=459a9e8c6b60b280b3a5519b1a06423d5f7a67bb;p=graphit%2Fcontrolpi-graph.git Only create comessage instance if coroot instance found. --- diff --git a/controlpi_plugins/graph.py b/controlpi_plugins/graph.py index 7dbf095..f9818bc 100644 --- a/controlpi_plugins/graph.py +++ b/controlpi_plugins/graph.py @@ -47,15 +47,19 @@ class Graph(BasePlugin): await self._open() coroot_guid = await self._call('attributsknoten', ['coroot_name', self.conf['name']]) - comessage_guid = await self._call('erzeuge', ['comessage']) - if coroot_guid and comessage_guid: - await self._call('verknuepfe', [comessage_guid, coroot_guid]) - messages = self._messages - self._messages = [] - await self._call('setze', [comessage_guid, 'comessage_json', - json.dumps(messages)]) - await self._call('setze', [comessage_guid, 'comessage_ready', - True]) + if coroot_guid: + comessage_guid = await self._call('erzeuge', ['comessage']) + if comessage_guid: + await self._call('verknuepfe', [comessage_guid, + coroot_guid]) + messages = self._messages + self._messages = [] + await self._call('setze', [comessage_guid, + 'comessage_json', + json.dumps(messages)]) + await self._call('setze', [comessage_guid, + 'comessage_ready', + True]) await self._close() async def _receive(self, message: Message) -> None: @@ -120,12 +124,16 @@ class Graph(BasePlugin): await self._open() coroot_guid = await self._call('attributsknoten', ['coroot_name', self.conf['name']]) - comessage_guid = await self._call('erzeuge', ['comessage']) - if coroot_guid and comessage_guid: - await self._call('verknuepfe', [comessage_guid, coroot_guid]) - messages = [Message(self.name, {'event': 'connection opened'})] - await self._call('setze', [comessage_guid, 'comessage_json', - json.dumps(messages)]) - await self._call('setze', [comessage_guid, 'comessage_ready', - True]) + if coroot_guid: + comessage_guid = await self._call('erzeuge', ['comessage']) + if comessage_guid: + await self._call('verknuepfe', [comessage_guid, + coroot_guid]) + messages = [Message(self.name, {'event': 'connection opened'})] + await self._call('setze', [comessage_guid, + 'comessage_json', + json.dumps(messages)]) + await self._call('setze', [comessage_guid, + 'comessage_ready', + True]) await self._close()