studioimaginaire / phue

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

Detecting a sonoff in Philips hue emulation mode. #110

Open glennpierce opened 7 years ago

glennpierce commented 7 years ago

Hi I am using Sonoff-Tasmota with Philips hue bridge emulation and I am trying to get one to turn on / off.

I first had to change the get_api to

def get_api(self):
""" Returns the full api dictionary """
    if not self.username:
        return self.request('GET', '/api/')
    return self.request('GET', '/api/' + self.username)

This is because username was None

get_api now simply returns

[{u'success': {u'username': u'e9da25'}}]

The json on my sonoff url http://192.168.1.74/api

is

{"lights":{"1":{"state":{"on":false,"bri":0,"hue":0,"sat":0,"effect":"none","ct":0,"alert":"none","colormode":"hs","reachable":true},"type":"Dimmable light","name":"Sonoff","modelid":"LWB004","manufacturername":"Philips","uniqueid":"5CCF7FE9DA25-1","swversion":"66012040"}},"groups":{},"schedules":{},"config":{"name":"Philips hue","mac":"5C:CF:7F:E9:DA:25","dhcp":true,"ipaddress":"192.168.1.74","netmask":"255.255.255.0","gateway":"192.168.1.254","proxyaddress":"","proxyport":0,"UTC":"2017-05-18T21:45:03","whitelist":{"":{"last use date":"2017-05-18T21:45:03","create date":"2017-05-18T21:45:03","name":"Remote"}},"swversion":"01036659","apiversion":"1.16.0","swupdate":{"updatestate":0,"url":"","text":"","notify": false},"linkbutton":false,"portalservices":false}}

The emulation works with my amazon echo so it is working.

Thanks

glennpierce commented 7 years ago

Fixed this.

In the init function the username set line should be

self.username = username or ''

glennpierce commented 7 years ago

Actually the problem was also the / on the end of the url. The patch is

619c619
<         self.username = username
---
>         self.username = username or ''
647a648,650
> 
>         if address[-1] == '/':
>             address = address[0:-1]