-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
device.status() gives sometimes a weird reply #565
Comments
That's correct, especially if you are just monitoring for status changes. The device will not always send back the full DPS payload so you need to expect that you may not get every DPS every time. You need to add error handling to your python script to handle that. The code snip you sent doesn't seem to be the full code ( |
This is the complete code
|
Possibly try something like this: from datetime import datetime
import tinytuya
ct = datetime.now()
print("Current time = ", ct.strftime("%H %M"))
ch = int(ct.strftime("%H"))
cm = ct.strftime("%M")
chh = int(ct.strftime("%H")) + float(ct.strftime("%M")) / 60.0
print("Current hour = ", chh)
for dev in devices:
print("\nTesting ", dev[0], " Day time = ", dev[4], " Night time = ", dev[5])
tobe = False
if (chh > dev[5]) or (chh < dev[4]):
tobe = True
try:
d = tinytuya.Device(dev[1], dev[2], dev[3])
d.set_socketRetryLimit(2) # set retry count limit [default 5]
d.set_socketTimeout(2) # set connection timeout in seconds [default 5]
d.set_sendWait(1)
d.set_dpsUsed({"1": None})
d.set_version(3.4)
data = d.status()
print(data)
# Check if 'dps' exists and contains the required key
if 'dps' in data and dev[6] in data['dps']:
asis = data['dps'][dev[6]]
print("To be = ", tobe, " As is =", asis)
if asis != tobe:
print("Switching ", dev[0])
d.set_value(dev[6], tobe)
else:
print(f"DPS data missing or key {dev[6]} not found for device {dev[0]}")
except Exception as e:
print(f"Error connecting to {dev[0]}: {e}")
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
calling d.status() returns sometimes some weird answer (protocol 3.4)
my code:
The text was updated successfully, but these errors were encountered: