codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 332 forks source link

add special handling for SET-as-GET requests that return DP_QUERY #616

Closed Apollon77 closed 1 year ago

Apollon77 commented 1 year ago

fixes #617 fixes https://github.com/codetheweb/tuyapi/discussions/613

This is untested currently!

Apollon77 commented 1 year ago

@codetheweb I asked the user that is affected by the issue to check my branch. I tried to make it backward compatible and stumbled over the case that two parallel "set" in general would be an issue because in this case the setResolve variable is overwritten. I added a check and throw an error in that case. This is slightly breaking, but I think the much cleaner way. What do you think?

codetheweb commented 1 year ago

Yeah I think that makes sense.

Will merge once we get confirmation from the user.

Apollon77 commented 1 year ago

@codetheweb I added another case that I stumbled over with a user (the device was just sending the REFRESH response, but did not sent any STATUS package in between, so we never resolved the promise. The usual process is

-> send DP_REFESH -> receive STATUS with data -> receive "empty" DP_REFRESH

But it seems that it also can happen like:

-> send DP_REFESH -> receive "empty" DP_REFRESH

without data. So I now check if the resolver is still there and resolve on DP_REFRESH too with the empty package.

A useris testing this right now...

Apollon77 commented 1 year ago

@codetheweb Verified ... it seems we never really resolved for "refresh" (was only working when falling back to "set") ... we just emitted the data ... veeery interesting

codetheweb commented 1 year ago

Published in v7.5.2.

Also added you as a contributor to this repo

Apollon77 commented 1 year ago

Thank you!