studioimaginaire / phue

A Python library for the Philips Hue system
Other
1.52k stars 267 forks source link

Automated IP discovery #156

Closed henryruhs closed 2 years ago

henryruhs commented 5 years ago

Hello,

I stumbled upon this awesome project. What about providing automated IP discovery?

from phue import Bridge, discover_ip

ip = discover_ip()
bridge = Bridge(ip)

Method discover_ip() looks like that:

def discover_ip():
    response = requests.get('https://discovery.meethue.com')

    # process response

    if response and response.status_code == 200:
        data = response.json()

        if 'internalipaddress' in data[0]:
            return data[0]['internalipaddress']
    return None

Best regards

PeanutButterPhil commented 3 years ago

Hey There

In this line:

response = requests.get('https://discovery.meethue.com')

The link appears to be broken or incompatible for me to scrape from. When I visit on my machine that's used to run this HUE server for my home, it simply returns an empty list, thought It's currently connected to my bridge. This is a feature I want too, and it looks like a fail-proof way would be to use a N-UPnP protocol.

The result would return a list of stuff including this:

{ "id":"001788fffe16c18f", "internalipaddress":"192.168.2.20", "macaddress":"00:17:88:16:c1:8f", "name":"Philips Hue" }

Then, all we'd have to do is search and filter name to start with %ph and end in $Hue encase not all bridges are named with the same caps. Or compare the name to "Philips Hue" literally and once there is a match check the IP and throw it in a variable to call the connect() function with.

I see the potential to increase the customer experience when running this library so I will see what I can come up with.

henryruhs commented 3 years ago

In the meanwhile I wrote an independent discovery to get around networks that have a strong firewall.

https://github.com/redaxmedia/chroma-feedback/blob/master/chroma_feedback/consumer/philips_hue/core.py#L56-L72