-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Fixed a few parsing issues: #150
Conversation
zero-padding is actually the return code from the device where 0 = success Added _returnCode, _crc to MessageParser (reordered to match order in memory) (crc is not actually checked here, but it could be!) More restrictive length checks, taking into account _returnCode and _crc _commandByte is a uint32 Fill _leftOver with, well, leftovers Reordered parse logic to match order in memory (this also allows us to extract more data in case of a suffix mismatch) suffix indexed relative to _payloadSize, relevant in the case of leftovers (which happens when two messages are sent in one) These changes were made with the best attempt to adhere to the existing coding style I would personally make parse and encode both static functions We could check the crc value for data integrity If _leftOver is populated, better try decoding that too A more drastic overhaul can be found: https://github.com/kueblc/mocktuyacloud/blob/master/lib/lan-frame.js But no attempt has been made to maintain the previous coding style This adaptation was made to integrate seamlessly into the existing tuyapi project
The Travis failure is due to a bug in the stub device implementation. Since a return code is only present in a message from the device to the client, the same parsing and encoding logic shouldn't be used in both device and client. |
I can add logic to accommodate the bug but it would be better to address the bug instead. |
Thanks for the contributions @kueblc. To answer your questions from the other PRs, the only reason they're not static functions is the contributor who originally wrote them decided to put them in classes. I'm totally ok with making them static functions; make any changes you think necessary. Is it possible to make a new PR with all your changes in a single place? Just makes it easier for me to see what's changed. |
Sure, I can combine changes into a single PR if you'd prefer. The practice of isolating changes to individual branches is so that the project maintainer can independently evaluate the impact and decide to pick and choose which changes to merge. For instance, this PR, while code correct, is failing checks. It might be that you want to hold off on merge this piece until a PR is made for tuyapi/stub. Each of these PRs were coded to be independently and cleanly merged. If you're onboard with the direction I'm going, I'll gladly merge these together and keep it going. I wanted to see what, if any, of my additions fit your vision for the project before I invested much. Moving forward, perhaps we can create a I've got a number of breaking and non-breaking changes in mind, and of course I'll be putting forth non-breaking changes first. I reference MockTuyaCloud as it encompasses a lot of the changes I wanted to make, but it does so in a breaking fashion and with my own coding style, so that's why I'm now trying to backport these changes in a non-breaking way. If you have any thoughts on approach, please let me know and I'd be happy to make any coming changes with that in mind. I've so far remained fairly conservative in changes but like I said before, see MockTuyaCloud for an idea of my coding style and direction. |
Got it, thanks for the detailed response. It was a little difficult to see that each PR could be merged separately at first glance, but now I see each PR is based on a different branch. If it's ok with you, I'll close all of your currently open PRs and then you can make a single PR with all changes to the cipher and parsing functions when you're ready. I'm aware tuyapi/stub is far from perfect; I've been running into some issues over the last few days. Still working on it. (While running tests and working with TuyAPI, it appears it may possible to overwrite data sent from the socket. It may be necessary to queue As far as breaking changes go, I think the current interface (although not perfect) is pretty good. Breaking the cipher and parsing functions/classes is fine, but I'd prefer to keep the user-facing interface largely the same; unless you have a really cool idea for X feature. Also, just as a heads up: I'm doing a hackathon this weekend; so I'll be unavailable until late Monday/Tuesday. |
Sure go ahead and close and I'll put these together in a new one. Would you like to merge the Another reason to push and pull often is to keep all contributors up to date on what's changing to minimize merge conflicts. If no one else is working on these parts right now, I'd like to do a bit more liberal clean up. I can maintain code style and stick to non-breaking changes. I'd be happy to help debug tuyapi/stub next if you'd like any help. I created something like that, a fake device, but for testing the cloud functions. I don't think you should be losing packets, or maybe something just needs to be flushed. As breaking changes go, the only thing that bugs me is the interface for So instead of I haven't had any issues setting multiple dp values at once, and in many cases I'm finding I need to, such as in the use case of power strips and RGBW light bulbs. It's much easier, and cleaner IMHO, to turn the bulb on at half brightness with It also avoids any possible delay between these adjustments taking place. You can go directly from off to any color, brightness or scene, or any combination between them. You can also use this to easily make a nice little interface for a given device There's a lot more that could be said here, just trying to give you an impression and see what you think. No worries if you don't get to this right away, open source is powered by volunteered time and we appreciate every minute of it! Good luck at your Hackathon! |
I went ahead and merged the AFAIK, you and I are the only people actively working on this. Feel free to make a separate PR for each major change or a single gigantic PR, whatever you prefer. I see what you mean with |
Hey @codetheweb, hope the hackathon went well!
I was hesitant to put all revisions in a single branch/PR, in case you disagree with any of the changes I wanted to make it easy to pick and choose. Also concerned about project stability, could you create a My thought is that we'll collaborate in the If it's too much to break the changes down into individual branches/PRs, I propose the policy of merging those individual feature branches locally into
How about a new method, to the effect of We could also play with other layers of abstraction, namely a very thin wrapper that translates fields to dp values a la schema, ie Another thought, since we're receiving updates in real time from the device, we can maintain our own Some things to think about. I'll focus on non-breaking revisions for now and we can talk more about API as we move forward. It'll be more clear if I can show some examples of what I'm talking about. |
Thanks, the event was quite a bit of fun.
Good idea, just created one. Didn't feel the need before as I generally published a new version soon after committing to
I'm fine with breaking up changes/PRs into granular parts (it seems logical after you explained it); not sure if it makes sense to have a different branch for each contributor if contributors can just fork this and make changes on their forked version.
I was actually thinking about including something similar in v4.0, but couldn't figure out an elegant way to let the user decide if they want to fire a |
I haven't been to one in a while (not as accessible once you're out of school) but for sure I had fun. Anything interesting projects to share? Tuya hacking? 😛
Awesome, I'll make PRs to this branch moving forward, thanks!
Sounds good.
Maybe a logical separation between |
It's not that interesting or complex, but a friend and I made this. It's a webapp for party games that require players to "buzz in". First person that joins a room is the host, everyone who joins after is a player. Real time communications done with Socket.IO. Anyways, adding an update function sounds good. Also, didn't mention it above but I like your idea of an automatic schema for |
zero-padding is actually the return code from the device where 0 = success
Added _returnCode, _crc to MessageParser
(reordered to match order in memory)
(crc is not actually checked here, but it could be!)
More restrictive length checks, taking into account _returnCode and _crc
_commandByte is a uint32
Fill _leftOver with, well, leftovers
Reordered parse logic to match order in memory
(this also allows us to extract more data in case of a suffix mismatch)
suffix indexed relative to _payloadSize, relevant in the case of leftovers
(which happens when two messages are sent in one)
These changes were made with the best attempt to adhere to the existing coding style
I would personally make parse and encode both static functions
We could check the crc value for data integrity
If _leftOver is populated, better try decoding that too
A more drastic overhaul can be found:
https://github.com/kueblc/mocktuyacloud/blob/master/lib/lan-frame.js
But no attempt has been made to maintain the previous coding style
This adaptation was made to integrate seamlessly into the existing tuyapi project