Skip to content

Commit

Permalink
Fixed timeout bug in deviceRaw()
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Oct 9, 2020
1 parent 5d11e87 commit f8f7baa
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions tuyapower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def deviceInfo(deviceid, ip, key, vers):

while True:
sw, w, mA, V = _DEFAULTS
try:
if(api == "tinytuya"):
d = tinytuya.OutletDevice(deviceid, ip, key)
else:
d = pytuya.OutletDevice(deviceid, ip, key)
if(api == "tinytuya"):
d = tinytuya.OutletDevice(deviceid, ip, key)
else:
d = pytuya.OutletDevice(deviceid, ip, key)
if vers == "3.3":
d.set_version(3.3)

if vers == "3.3":
d.set_version(3.3)
try:
data = d.status()

except KeyboardInterrupt:
Expand All @@ -129,6 +129,7 @@ def deviceInfo(deviceid, ip, key, vers):
return (sw, w, mA, V, "Timeout polling device")
try:
sleep(2)
continue
except KeyboardInterrupt:
log.info(
"CANCEL: Received interrupt from user while polling plug %s [%s]."
Expand Down Expand Up @@ -197,14 +198,15 @@ def deviceRaw(deviceid, ip, key, vers):
watchdog = 0
while True:
data = False
try:
if(api == "tinytuya"):
d = tinytuya.OutletDevice(deviceid, ip, key)
else:
d = pytuya.OutletDevice(deviceid, ip, key)
if(api == "tinytuya"):
d = tinytuya.OutletDevice(deviceid, ip, key)
else:
d = pytuya.OutletDevice(deviceid, ip, key)

if vers == "3.3":
d.set_version(3.3)

if vers == "3.3":
d.set_version(3.3)
try:
data = d.status()

except KeyboardInterrupt:
Expand All @@ -220,10 +222,10 @@ def deviceRaw(deviceid, ip, key, vers):
"TIMEOUT: No response from plug %s [%s] after %s attempts."
% (deviceid, ip, RETRY)
)
return ("ERROR: Timeout polling device")
try:
sleep(2)
continue

except KeyboardInterrupt:
log.info(
"CANCEL: Received interrupt from user while polling plug %s [%s]."
Expand Down

0 comments on commit f8f7baa

Please sign in to comment.