kw123 / Hue-Lights-Indigo-plugin

Philips Hue control from Indigo
MIT License
7 stars 11 forks source link

Use pybonjour to discover hue hubs #13

Open indigo-jay opened 2 years ago

indigo-jay commented 2 years ago

Whether you create separate hue hubs or leave the hub configuration in the plugin config dialog, you should discover hue hubs using bonjour to create the list of available hubs on the network (rather than requiring users to enter an IP address, which BTW can change). This is the information that you get from a bonjour discovery:

_hue._tcp. (Philips hue protocol) - 2 items
    Philips Hue - 282E06
        Main-hue-bridge.local.
        XXX.XXX.XXX.XXX:443
        [IP6ADDRESSHERE]:443
        bridgeid=BRIDGEIDHERE
        modelid=BSB002
    Philips Hue - 84561E
        Testing-bridge.local.
        XXX.XXX.XXX.XXX:443
        [IP6ADDRESSHERE]:443
        bridgeid= BRIDGEIDHERE
        modelid=BSB002

So you have the unique identifier for the bridge, the IP address (which I've obscured above) as well as the local DNS for it, the name (by parsing out the local DNS and substituting spaces for dashes, i.e. "Testing Bridge"), etc. You can use this information to present to the user when trying to add a new bridge. You can also use this information at start up to make the connection to the bridge - users never have to worry about IP address issues.

For instance, you could show 2 lists in the plugin config dialog, one showing available but unpaired bridges, and the other with paired bridges (and some kind of identifier on them if they can't be found on the network).

The Airfoil Pro plugin uses pybonjour so that's a good place to see an example.