Improve connection handling, especially continue instead of pass. v0.3.1
authorBenjamin Braatz <bb@bbraatz.eu>
Tue, 25 Jul 2023 09:31:44 +0000 (11:31 +0200)
committerBenjamin Braatz <bb@bbraatz.eu>
Tue, 25 Jul 2023 10:59:23 +0000 (12:59 +0200)
controlpi_plugins/wsclient.py
setup.py

index a6919cbbe6d485b40cca58209b7a2732123a6902..9ace98fc88e0185fb21feed9a9210333fa39b7c1 100644 (file)
@@ -164,6 +164,8 @@ class WSClient(BasePlugin):
                                      {'const': 'unregistered'}}))
         sends.append(MessageTemplate({'event':
                                      {'const': 'connection opened'}}))
+        sends.append(MessageTemplate({'event':
+                                     {'const': 'connection configured'}}))
         sends.append(MessageTemplate({'event':
                                      {'const': 'connection closed'}}))
         self._down_filter = []
@@ -195,6 +197,9 @@ class WSClient(BasePlugin):
         """Connect to wsserver and process messages from it."""
         async for websocket in connect(self.conf['url'],
                                        ping_interval=1, ping_timeout=5):
+            await self.bus.send(Message(self.name,
+                                        {'event':
+                                         'connection opened'}))
             try:
                 conf_command: Dict[str, Any] = \
                         {'command': 'configure websocket', 'target': ''}
@@ -212,15 +217,15 @@ class WSClient(BasePlugin):
                 await websocket.send(json_command)
                 await self.bus.send(Message(self.name,
                                             {'event':
-                                             'connection opened'}))
+                                             'connection configured'}))
                 self._websocket = websocket
                 try:
                     async for json_message in websocket:
                         assert isinstance(json_message, str)
                         await self._send(json_message)
                 except ConnectionClosed:
-                    pass
-                self._websocket = None
+                    self._websocket = None
+                    continue
                 await self.bus.send(Message(self.name,
                                             {'event':
                                              'connection closed'}))
index b794633b0a7fe9bee35b6a9638431b9f6ecf056f..5638952cf053ee391d76ac9eb0c747562c217d88 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as readme_file:
 
 setuptools.setup(
     name="controlpi-wsclient",
-    version="0.3.0",
+    version="0.3.1",
     author="Graph-IT GmbH",
     author_email="info@graph-it.com",
     description="ControlPi Plugin for Websocket Clients",