From 5119dcd9f136f3bb30ecc86805ae3ecdc14ab701 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Mon, 13 May 2024 09:02:06 +0200 Subject: [PATCH] Version 0.3.5: Catch connection drop in sending --- controlpi_plugins/wsclient.py | 9 +++++++-- setup.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/controlpi_plugins/wsclient.py b/controlpi_plugins/wsclient.py index cc88145..70acba6 100644 --- a/controlpi_plugins/wsclient.py +++ b/controlpi_plugins/wsclient.py @@ -182,7 +182,11 @@ class WSClient(BasePlugin): self._client, self.name) if translated_message is not None: json_message = json.dumps(translated_message) - await self._websocket.send(json_message) + try: + await self._websocket.send(json_message) + except Exception as e: + print(f"WSClient '{self.name}':" + f" Exception in websocket send: {e}") async def run(self) -> None: """Connect to wsserver and process messages from it.""" @@ -236,7 +240,8 @@ class WSClient(BasePlugin): assert isinstance(json_message, str) await self._send(json_message) except Exception as e: - print(f"WSClient '{self.name}': Exception in connection: {e}") + print(f"WSClient '{self.name}':" + f" Exception in websocket receive loop: {e}") self._websocket = None print(f"WSClient '{self.name}': Connection closed" f" to {self.conf['url']}.") diff --git a/setup.py b/setup.py index 9ef7c68..ff95fa6 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.4", + version="0.3.5", author="Graph-IT GmbH", author_email="info@graph-it.com", description="ControlPi Plugin for Websocket Clients", -- 2.34.1