From 5d11e8793ff240439d8bc8f6dbf9981e845fa6ae Mon Sep 17 00:00:00 2001 From: "Jason A. Cox" Date: Thu, 8 Oct 2020 19:59:53 -0700 Subject: [PATCH] Add sw to _DEFAULTS for deviceInfo --- .gitignore | 1 + tuyapower/__init__.py | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8b46621..5d663b9 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,4 @@ test.sh sandbox/ .DS_Store jason.py +tinytuya diff --git a/tuyapower/__init__.py b/tuyapower/__init__.py index 708aa30..458f5ac 100644 --- a/tuyapower/__init__.py +++ b/tuyapower/__init__.py @@ -54,7 +54,7 @@ api_ver = "unknown" name = "tuyapower" -version_tuple = (0, 0, 24) +version_tuple = (0, 0, 25) version = version_string = __version__ = "%d.%d.%d" % version_tuple __author__ = "jasonacox" @@ -68,7 +68,7 @@ RETRY = 5 # default polling response for error condition -_DEFAULTS = (-99, -99, -99) # w, mA, V +_DEFAULTS = (False, -99, -99, -99) # w, mA, V # UDP packet payload decryption - credit to tuya-convert pad = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16) @@ -99,8 +99,9 @@ def deviceInfo(deviceid, ip, key, vers): watchdog = 0 now = datetime.datetime.utcnow() iso_time = now.strftime("%Y-%m-%dT%H:%M:%SZ") + while True: - w, mA, V = _DEFAULTS + sw, w, mA, V = _DEFAULTS try: if(api == "tinytuya"): d = tinytuya.OutletDevice(deviceid, ip, key) @@ -116,7 +117,6 @@ def deviceInfo(deviceid, ip, key, vers): "CANCEL: Received interrupt from user while polling plug %s [%s]." % (deviceid, ip) ) - sw = False return (sw, w, mA, V, "User Interrupt") except: @@ -126,7 +126,6 @@ def deviceInfo(deviceid, ip, key, vers): "TIMEOUT: No response from plug %s [%s] after %s attempts." % (deviceid, ip, RETRY) ) - sw = False return (sw, w, mA, V, "Timeout polling device") try: sleep(2) @@ -135,7 +134,6 @@ def deviceInfo(deviceid, ip, key, vers): "CANCEL: Received interrupt from user while polling plug %s [%s]." % (deviceid, ip) ) - sw = False return (sw, w, mA, V, "User Interrupt") try: @@ -160,7 +158,6 @@ def deviceInfo(deviceid, ip, key, vers): log.info(str(info)) else: log.info("Incomplete response from plug %s [%s]." % (deviceid,ip)) - sw = False key = "Incomplete response" return (sw, w, mA, V, key) @@ -181,7 +178,6 @@ def deviceInfo(deviceid, ip, key, vers): "CANCEL: Received interrupt from user while polling plug %s [%s]." % (deviceid, ip) ) - sw = False return (sw, w, mA, V, "User Interrupt") # (dps) = tuyapower.deviceInfo(id, ip, key, vers)