Rework payload_dict and realign the command list to match Tuya's API #166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When I started throwing random commands at my thermostat to see what it responded to, I noticed DP_QUERY_NEW was defined as 16 but payload_dict stored it as hex byte 0f (which would be 15). The more I dug into
payload_dict
andgenerate_payload()
the less I liked about how it worked, so I rewrote it ^_^ . Now it functions more like an override - if the command is not explicitly overridden (such as with device22's DP_QUERY) it simply uses the command as passed togenerate_payload()
, and if the json dict key "command" is not defined then it just sends everything ("command" is set to"command": {"gwId": "", "devId": "", "uid": "", "t": ""}
). Technically theAP_CONFIG
andDP_QUERY
entries can be deleted frompayload_dict
completely, but for now I left them.I also noticed the list of commands didn't really make sense. It looked like it was copy-n-pasted from the list of MCU serial commands, however those have nothing to do with the local API / TCP socket commands. So, I used the LAN protocol defines from https://github.com/tuya/tuya-iotos-embeded-sdk-wifi-ble-bk7231n/blob/master/sdk/include/lan_protocol.h and removed the invalid ones. I also added the "official" names to the comments and did some text aligning.
There are also 2 unrelated 1-liners I threw in: socket.send() is now socket.sendall(), and a copy-n-paste error in the IR Remote example was corrected.