steveredden / homebridge-kasa-lightstrip

A homebridge plugin for controlling Kasa Light Strips :zap:
MIT License
2 stars 1 forks source link

python-kasa 0.4.1 output breaks homebridge-kasa-lightrstrip parsing #8

Open justinmm2 opened 2 years ago

justinmm2 commented 2 years ago

Hi,

I wanted to report this for anyone Googling. In short, homebridge-kasa-lightstrip won't work properly if your version of python-kasa is too new (0.4.1). In summary: python-kasa now wants "--type lightstrip" instead of "--lightstrip". Using the older "--lightstrip" argument will cause the "kasa" binary to print a warning about deprecated arguments; in turn, homebridge-kasa-lightstrip will fail to parse this warning message, thinking it's an HSV string.

I've written to @steveredden because I've got a patch to fix this so close to working..

steveredden commented 2 years ago

Nice find -

The lazy fix: is it possible to just use the old version of that library - does everything work as expected?

pip3 install python-kasa==0.4.0

I have not updated to 0.4.1 of their library, so everything (of course) works fine for me... 🤦‍♂️

Otherwise, the first glance at your diff seems like a fine start, indeed!

justinmm2 commented 2 years ago

I suppose using 0.4.0 probably would work? But I'm not sure how you'd enforce that, unless package.json has some way of installing pip packages?

If you have thoughts on how I can clean up the async issue, let me know! Would hate to see this wither on the vine. I asked on the Homebridge Discord (#plugin-development), but there wasn't any response. Either way, the (unrelated) string parsing bugfixes dramatically cut down on the number of warning messages in my environment. The async thing is a shame; it works 95% of the time for me, but I don't want to open a PR for code that's not 100% - there must be a way to do it, no?

steveredden commented 2 years ago

Total js noob here too. But I would think your exec version parsing best belongs in the initial load of the plugin, line 10:17 area:

https://github.com/steveredden/homebridge-kasa-lightstrip/blob/ca3e78f035074977682275140e8a3b5e79c2fbff/lib/KasaLightstripPlatform.js#L10

This way you’re only retrieving and parsing it once.

[maybe even add a fatal error or at least warning log message if the user HASNT installed the Kasa python package… enhancement]

Then, pass a new param (bool or something) that indicates which exec variant to use:

https://github.com/steveredden/homebridge-kasa-lightstrip/blob/ca3e78f035074977682275140e8a3b5e79c2fbff/lib/KasaLightstripPlatform.js#L27

And

https://github.com/steveredden/homebridge-kasa-lightstrip/blob/ca3e78f035074977682275140e8a3b5e79c2fbff/lib/KasaLightstrip.js#L7 .

JBryant915 commented 2 years ago

I am having this same issue. when the argument is sent with --lightstrip instead of --type lightstrip, or even just leaving that argument out all together, it works. I can turn it on or off with simply "kasa --host 'ipaddress' on" or "kasa --host 'ipaddress' --type lightstrip on. Turning off works the same except, of course, substituting off for on in both cases issuing the command from CLI of my rpi. I did do the pip3 install python-kasa==0.4.0, which would allow the command to run as is from CLI, but not from the plugin, looks like it still tries to use the newer version of Kasa for some reason. Not sure how to uninstall so only 0.4.0 would be the only one there.

Is there any updates as to when this maybe corrected?? Thanks for all the hard work!!

steveredden commented 2 years ago

The newest versions of python-kasa prove to be quite unstable in my testing. VERY frequently getting timeout/connection errors in their protocol.py file.

A known-good version (and the version this was developed against) is 0.4.0.dev3

I recommend everyone pins to that version, using:

sudo pip3 uninstall python-kasa
sudo pip3 install python-kasa==0.4.0.dev3
JBryant915 commented 2 years ago

Thank you, I will try that here in just a few minutes. I will let you know how I fair. I think I have both the latest and 0.4.0 versions installed and didn’t know how to uninstall them so thank you for the info how how to do that!! I actually got the other plug-in to work, but your sounds better with the ability to change the affects so that’s the route I’d like to take!!

Thanks again,

Jody Bryant

Sent from my iPhone

On May 2, 2022, at 4:58 PM, steveredden @.***> wrote:

 The newest versions of python-kasa prove to be quite unstable in my testing. VERY frequently getting timeout/connection errors in their protocol.py file.

A known-good version (and the version this was developed against) is 0.4.0.dev3

I recommend everyone pins to that version, using:

sudo pip3 uninstall python-kasa sudo pip3 install python-kasa==0.4.0.dev3 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

JBryant915 commented 2 years ago

I do believe that did it for me. I'm not at home, but doing this by remote. I just did the basic config so on/off is all I can test at the moment. I verified that much by using the Kasa app to check to see if using the dashboard widget turned it on or off and it did so I couldn't think of a reason it wouldn't work in HK. When I get home, I will add the affects switches and then add it to homekit. I have no doubt it will work. Thanks for all you guys do!!

JBryant915 commented 2 years ago

Well I thought that would do it, but it only mostly did the trick. I got home, changed the config to include aurora, flicker and rainbow affects and saved it. Added it to Homekit and it won't turn the strip on. It acts like it does and shows it at 22 present brightness but doesn't actually turn the strip on. Funny thing is, any of the 3 affects will turn the light on and actually work for the affect that was chosen. The main tile to turn on/off the strip will actually turn the strip off. Just not on. Any ideas there?

I should note that when I try to turn the strip on with the Homekit tile, I can open the Kasa app and it does show that the strip should be on. Which confuses me even more.

EDIT:

Once the strip is on, I can control colors and brightness through Homekit as well, just won't turn it on for some reason, lol