From f0fab284dfeeba31c521116e32093cc2cf0d9910 Mon Sep 17 00:00:00 2001 From: vifo Date: Wed, 22 Nov 2023 11:35:47 +0100 Subject: [PATCH] [FIX] iot: check the URL before lauch the ws client Add a condition that check if the DB is connected to the iot box before the start of the websocket client, before, if no DB was connected the Thread was lauched for nothing closes odoo/odoo#143132 Signed-off-by: Yaroslav Soroko (yaso) --- addons/hw_drivers/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/hw_drivers/main.py b/addons/hw_drivers/main.py index b6c392087a3..34b1ab12d8d 100644 --- a/addons/hw_drivers/main.py +++ b/addons/hw_drivers/main.py @@ -26,7 +26,7 @@ iot_devices = {} class Manager(Thread): - def send_alldevices(self, iot_client): + def send_alldevices(self, iot_client=None): """ This method send IoT Box and devices informations to Odoo database """ @@ -67,7 +67,8 @@ class Manager(Thread): 'Accept': 'text/plain', }, ) - iot_client.iot_channel = json.loads(resp.data).get('result', '') + if iot_client: + iot_client.iot_channel = json.loads(resp.data).get('result', '') except Exception as e: _logger.error('Could not reach configured server') _logger.error('A error encountered : %s ' % e) @@ -104,7 +105,8 @@ class Manager(Thread): _logger.error("Error in %s: %s", str(interface), e) #Setup the websocket connection - iot_client.start() + if helpers.get_odoo_server_url(): + iot_client.start() # Check every 3 secondes if the list of connected devices has changed and send the updated # list to the connected DB. self.previous_iot_devices = []