From 8320853399b06c52e41bd3591c27b065ba9a8f02 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 25 Jan 2022 07:47:40 +0100 Subject: [PATCH] Minor fixes - onewire is not hardcoded to busmaster 1 - try to catch exception while sending data to WS and WS has closed connection --- cbpi/__init__.py | 3 +-- cbpi/extension/onewire/__init__.py | 2 +- cbpi/websocket.py | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index a4d1e04..f1ec938 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,2 +1 @@ -__version__ = "4.0.1.3" - +__version__ = "4.0.1.4" diff --git a/cbpi/extension/onewire/__init__.py b/cbpi/extension/onewire/__init__.py index 6d1e604..0191354 100644 --- a/cbpi/extension/onewire/__init__.py +++ b/cbpi/extension/onewire/__init__.py @@ -41,7 +41,7 @@ class ReadThread (threading.Thread): try: if self.sensor_name is None: return - with open('/sys/bus/w1/devices/w1_bus_master1/%s/w1_slave' % self.sensor_name, 'r') as content_file: + with open('/sys/bus/w1/devices/%s/w1_slave' % self.sensor_name, 'r') as content_file: content = content_file.read() if (content.split('\n')[0].split(' ')[11] == "YES"): temp = float(content.split("=")[-1]) / 1000 # temp in Celcius diff --git a/cbpi/websocket.py b/cbpi/websocket.py index 253567a..fa6bc5c 100644 --- a/cbpi/websocket.py +++ b/cbpi/websocket.py @@ -32,7 +32,11 @@ class CBPiWebSocket: self.logger.debug("broadcast to ws clients. Data: %s" % data) for ws in self._clients: async def send_data(ws, data): - await ws.send_json(data=data, dumps=json_dumps) + try: + await ws.send_json(data=data, dumps=json_dumps) + except Exception as e: + self.logger.error("Error with client %s: %s" % (ws, str(e))) + self.cbpi.app.loop.create_task(send_data(ws, data)) async def websocket_handler(self, request): @@ -85,4 +89,4 @@ class CBPiWebSocket: self.logger.info("Web Socket Close") return ws - \ No newline at end of file +