From 5ad0b35d08dd03a9dbdfa94c6d0f39c2a0a7d021 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Tue, 25 Jul 2023 11:31:44 +0200 Subject: [PATCH] Improve connection handling, especially continue instead of pass. --- controlpi_plugins/wsclient.py | 11 ++++++++--- setup.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/controlpi_plugins/wsclient.py b/controlpi_plugins/wsclient.py index a6919cb..9ace98f 100644 --- a/controlpi_plugins/wsclient.py +++ b/controlpi_plugins/wsclient.py @@ -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'})) diff --git a/setup.py b/setup.py index b794633..5638952 100644 --- 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", -- 2.34.1