sbidy / pywizlight

A python connector for WiZ devices
MIT License
456 stars 77 forks source link

Auto-discovery #11

Closed mots closed 4 years ago

mots commented 4 years ago

It'd be great if we would have auto-discovery of bulbs instead of having to type in their IPs - this would also help the home assistant integration by adding a simple config flow.

Good news is, I have a local branch that adds this functionality - expect a PR soon!

sbidy commented 4 years ago

Hey - thanks for contributing! I think it is really difficult to implement a auto discovery because of the limitation of the UDP interface. Furthermore, if the bulb is initiated (WiFi setting etc.) the only way to discover a bulb in the network is a kind of port scanning on all IPs to the UDP port.

How do you implement this? In a ConfigFlow?

mots commented 4 years ago

So I found documentation of the protocol here - apparently you can send a UDP broadcast and all the bulbs will answer :). I currently have a new discovery class in pywizlight that'll return all the wizlights it can find (It works!). I haven't looked into the HA integration yet, but once we have this, it should be trivial to build a ConfigFlow around it

sbidy commented 4 years ago

Ah, a broadcast via UDP... Oh man, that's smart and simple. I was on the unicast path. Made an pull to the repo. I'll try to compine this with the ConfigFlow for the HA core pull. (see #10)

mhpetiwala commented 4 years ago

Hope the existing fixed IP config is also left in place. I have limited broadcast messages in my network for security reasons and hence prefer to have fixed IPs and configs v/s auto discovery mechanism. Also discovery mechanism for some other devices has been a bit flaky (and slow) in the past when HA reboots while the fixed configs are much more reliable and finite.

mots commented 4 years ago

I didn't modify anything relating to the existing config, so you should be good, @mhpetiwala!

@sbidy, I'll create a PR adding this mechanism after work today (I'm in PDT, so it's still working hours).

sbidy commented 4 years ago

Yes, fixed configured IP must work overall. The "auto discover" should be nice to have.

@mots no stress... I'll go to bed in a few minutes :)... CET

mots commented 4 years ago

Schöne Grüße an die Heimat übrigens ;)

mhpetiwala commented 4 years ago

That's comforting

"Yes, fixed configured IP must work overall. The "auto discover" should be nice to have."

much appreciated ;-)

sbidy commented 4 years ago

Integrated into the version 0.3.4 - tested and closed, I'll reverence this into the wiz_light repo because this is only the underlining lib for interact with the bulbs. How the "auto-discover" will be integrated is part of the wiz_light HA integration.