From 40e5839d7ade92b0e89e265a8be12fb8fef41178 Mon Sep 17 00:00:00 2001 From: sydspost <45944257+sydspost@users.noreply.github.com> Date: Mon, 25 Oct 2021 21:31:21 +0200 Subject: [PATCH] Update plugin.py Added threadhandling to onStart. Added a .decode('utf-8') to all sock.recv command, translating the content from bytes to a utf-8 string. --- plugin.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugin.py b/plugin.py index a1c7e9a..80c85e0 100644 --- a/plugin.py +++ b/plugin.py @@ -90,6 +90,9 @@ class BasePlugin: if (deviceFound == False): Domoticz.Device(Name=hostName, DeviceID=hostName, Unit=len(Devices)+1, Type=241, Subtype=8, Switchtype=7, Image=0).Create() + # Create/Start update thread + self.updateThread = threading.Thread(name="WiZUpdateThread", target=BasePlugin.handleThread, args=(self,)) + self.updateThread.start() def onStop(self): Domoticz.Debug("onStop called") @@ -132,7 +135,7 @@ class BasePlugin: try: sock.sendto(mJSON, (host, port)) - received = sock.recv(1024) + received = sock.recv(1024).decode('utf-8') finally: sock.close() @@ -146,7 +149,7 @@ class BasePlugin: try: sock.sendto(mJSON, (host, port)) - received = sock.recv(1024) + received = sock.recv(1024).decode('utf-8') finally: sock.close() @@ -166,7 +169,7 @@ class BasePlugin: try: sock.sendto(mJSON, (host, port)) - received = sock.recv(1024) + received = sock.recv(1024).decode('utf-8') finally: sock.close() @@ -182,7 +185,7 @@ class BasePlugin: try: sock.sendto(mJSON, (host, port)) - received = sock.recv(1024) + received = sock.recv(1024).decode('utf-8') finally: sock.close() @@ -206,7 +209,7 @@ class BasePlugin: # If it hasn't been at least 1 minute (corrected for ~2s runtime) since last update, skip it if time.time() - self.last_update < 58: return - self.startup = False + # Create/Start update thread self.updateThread = threading.Thread(name="WiZUpdateThread", target=BasePlugin.handleThread, args=(self,)) self.updateThread.start() @@ -250,7 +253,7 @@ class BasePlugin: try: sock.sendto(mJSON, (host, port)) - received = sock.recv(1024) + received = sock.recv(1024).decode('utf-8') finally: sock.close()