Only create comessage instance if coroot instance found.
authorBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 21 May 2025 10:00:06 +0000 (12:00 +0200)
committerBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 21 May 2025 10:00:06 +0000 (12:00 +0200)
controlpi_plugins/graph.py

index 7dbf0955de68422dabed15865ec62cb9c54332fa..f9818bc3cd620ebc07e0fb8d369f08422400e44a 100644 (file)
@@ -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()