-
Notifications
You must be signed in to change notification settings - Fork 172
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
how can I get if set_value was successfull without recall status. #480
Comments
Hi @Titriel - Can you give an example of your code? I think what you want is something like: import tinytuya
# Connect
d = tinytuya.OutletDevice(id, ip, key, version="3.3")
# Set value of DPS index 25
d.set_value(25, 'xyz')
# Read value
data = d.status()
setting = data['dps']['25']
print(setting) |
@jasonacox Sorry for my terible english, it's not my native language. |
Hi @Titriel - the commands wait for a response by default. You would need to set set_value(index, value, nowait=False) The For your use case, you just need to make sure you get a valid response: response = d.set_value("1",True)
# Should get eomething like: {'devId': 'abcdefg1234567', 'dps': {'1': True}, 't': 1712501649}
if "dps" in response:
print("Updated")
else:
print("Failed") If you are curious, you can see how TinyTuya handles it in the core code here: Lines 1141 to 1280 in 8971b80
|
Thank you very mutch. I check it out. |
Unfortunately TinyTuya doesn't really handle command success/fail well. This is a good candidate for an enhancement. Let's take a step back and look at all the possible command results:
The results for each might be unexpected: Instead of the above, we should probably be checking the retcode and immediately return an ERR_JSON if it's bad. Making sure we get a good retcode for the command we sent would be an additional check but brings up the issue of what to do with async updates received before the command response. For now the only way to make sure we have success is to do something like: d.set_value("1", True, nowait=True)
d.set_retry(False)
resp = d._send_receive(None, decode_response=False)
while resp and resp.cmd != [sent command]:
resp = d._send_receive(None, decode_response=False)
d.set_retry(True)
if resp and resp.retcode == 0:
print('Success!')
else:
print('Failed!') Unfortunately there's no good way of getting the exact command sent as it can be remapped based on the device quirks. Another TinyTuya enhancement could be to return the exact TuyaMessage sent when |
Hi,
I am on creating an universal MQTT- Adapter.
I was able to add your tinytuya class in my Adapter, and it works fine.
Some devices are hard on the border of the range of my WIFI. So it would be helpfull, that calls like set_value, sends back if it was successtull sending data to the device. Or is there a way how I can requst this state ?
Thank You
The text was updated successfully, but these errors were encountered: