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.main
rodzic
dc2372679d
commit
40e5839d7a
15
plugin.py
15
plugin.py
|
@ -90,6 +90,9 @@ class BasePlugin:
|
||||||
if (deviceFound == False):
|
if (deviceFound == False):
|
||||||
Domoticz.Device(Name=hostName, DeviceID=hostName, Unit=len(Devices)+1, Type=241, Subtype=8, Switchtype=7, Image=0).Create()
|
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):
|
def onStop(self):
|
||||||
Domoticz.Debug("onStop called")
|
Domoticz.Debug("onStop called")
|
||||||
|
@ -132,7 +135,7 @@ class BasePlugin:
|
||||||
try:
|
try:
|
||||||
sock.sendto(mJSON, (host, port))
|
sock.sendto(mJSON, (host, port))
|
||||||
|
|
||||||
received = sock.recv(1024)
|
received = sock.recv(1024).decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
@ -146,7 +149,7 @@ class BasePlugin:
|
||||||
try:
|
try:
|
||||||
sock.sendto(mJSON, (host, port))
|
sock.sendto(mJSON, (host, port))
|
||||||
|
|
||||||
received = sock.recv(1024)
|
received = sock.recv(1024).decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
@ -166,7 +169,7 @@ class BasePlugin:
|
||||||
try:
|
try:
|
||||||
sock.sendto(mJSON, (host, port))
|
sock.sendto(mJSON, (host, port))
|
||||||
|
|
||||||
received = sock.recv(1024)
|
received = sock.recv(1024).decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
@ -182,7 +185,7 @@ class BasePlugin:
|
||||||
try:
|
try:
|
||||||
sock.sendto(mJSON, (host, port))
|
sock.sendto(mJSON, (host, port))
|
||||||
|
|
||||||
received = sock.recv(1024)
|
received = sock.recv(1024).decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
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 it hasn't been at least 1 minute (corrected for ~2s runtime) since last update, skip it
|
||||||
if time.time() - self.last_update < 58:
|
if time.time() - self.last_update < 58:
|
||||||
return
|
return
|
||||||
self.startup = False
|
|
||||||
# Create/Start update thread
|
# Create/Start update thread
|
||||||
self.updateThread = threading.Thread(name="WiZUpdateThread", target=BasePlugin.handleThread, args=(self,))
|
self.updateThread = threading.Thread(name="WiZUpdateThread", target=BasePlugin.handleThread, args=(self,))
|
||||||
self.updateThread.start()
|
self.updateThread.start()
|
||||||
|
@ -250,7 +253,7 @@ class BasePlugin:
|
||||||
try:
|
try:
|
||||||
sock.sendto(mJSON, (host, port))
|
sock.sendto(mJSON, (host, port))
|
||||||
|
|
||||||
received = sock.recv(1024)
|
received = sock.recv(1024).decode('utf-8')
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue