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
Refactor and Clean Up #143
Conversation
Will now *always* emit event on data, `get()` will *always* return data. Nice and simple. :)
Pull Request Test Coverage Report for Build 213
💛 - Coveralls |
All I had to do was add disconnect to my script and it seemed to work fine. I didn't have to add any calls to connect. Which means when I call get(), tuyapi connects and gets the state and then runs get a second time. Your toggle function does the same. There didn't seem to be a nice way to change the behaviour because you'll then have to pass options to connect, etc. persistentConnection: false |
Thanks for pointing that out, I thought I left logic in to disable the heartbeat packets if persistent connection was set to false; but I guess not. Probably does makes sense just to remove that option entirely. Right, |
Yep I see how connect works and how if it's already been called and a connection is already open it won't do anything but I in my scripts I don't need to call connect I can skip that and go straight to calling get and set which will call connect anyway. But the way it's written seems like it's designed to run connect and might be an unnecessary step. If I just want to set the state quickly I don't want tuyapi to first get the state before it tries to set it like I wanted. Also when I get a state it gets it and then gets it again. Also I ported over those those feature on my branch I mentioned. So find gets all devices on the network. findDevices finds all the devices and gets their states. So in my script if you do the following, it gets all the devices and their states even without any keys.
|
Yeah, I realize now that the That Todo:
|
@codetheweb Max, I though I should let you know that I had refreshed all my Tuya devices with Sonoff-Tasmota last month, so no longer have the ability to do a regression. ;-( |
@NorthernMan54 alright, good to know. I keep meaning to flash one of my plugs but I'm scared I'll brick it. |
…o return all devices in `.find()`
@unparagoned take a look, see what you think.
Guess I could just make a temporary AP, might try that later today. |
@codetheweb, I'm out of the country for 2 weeks. The earliest I could set multiple devices support is March 2nd. |
@neojski alright, I'll try testing it myself. |
@codetheweb the find function works pretty well. Well it works when I use it properly, I had been trying to use find after running connect. You could get find to call disconnect before running, but I'm not sure if those sorts of things just bulk up the code. I've been playing about with the persistent connection it seems to be working fine. I'm still not sure why
Snippet from the calling code
Multiple devices/IPs |
The idea behind the Do you think I should leave that in, or delete it? |
@codetheweb Do you expect us to read the README....but yeh it makes sense now, leave it in. Ignore me, I've been coming at this from the wrong angle of a synchronous/non-persistence setup. I spent ages looking to see if there was some kind of return or promise with that initial get state without much luck. I always usually just gloss over the asynchronous bit in the readme since it always looked a bit too complicated, but I can now see why it' a much better way of setting things up. I now know how to get that initial get state and fix any issues. Thanks |
Sometimes the synchronous calls are the better way to do it, it just depends on what you're trying to do. I'll merge and publish this as soon as I get around to testing |
Just tested |
Please open a new issue for any bug reports related to the update. |
Done quite a bit of work over the last few days attempting to slim down TuyAPI and make it more readable. It's now much cleaner, although at the cost of potentially breaking older code.
Major Changes
.disconnect()
when they're done..get()
and.set()
will return a Promise while also emitting an event with returned data. Again, I can't think of any downside to doing both at once instead of one or the other - and it greatly simplifies the code as well as function arguments..resolveId()
=>.find()
, as the function can now look for both a missing ID and IP.Those are the major changes, although there's some smaller ones as well with updating documentation, checking function arguments, etc.
As this is a breaking change, it'll be v4 when released.
Testing
With all that said, it could still use testing. Specifically, @neojski could you test finding multiple IPs? My college's network isn't kind to UDP broadcasts.
In general, though, just want to have anyone who is able to do some testing of these changes before I roll them out.
Mentioning a few possible beta testers:
(Fixes #139.)