-
Notifications
You must be signed in to change notification settings - Fork 0
/
hue.py
59 lines (43 loc) · 1.13 KB
/
hue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import flash
import json
import requests
import ssl
#
# testConnection
#
def testConnection(ip):
try:
response = requests.get("http://" + ip + "/api/test/config")
js = json.loads(response.content)
if (js["name"] == "Philips hue"):
return True;
except Exception as e:
return False;
#
# createUser
#
def createUser(ip):
try:
response = requests.post("http://" + ip + "/api", json={"devicetype": "my_hue_app#Riverdi IoT Display"})
js = json.loads(response.content)
return js[0]["success"]["username"];
except Exception as e:
return None;
#
# turnLight
#
def turnLight(ip,user,num,state):
try:
addr = "http://" + ip + "/api/" + user + "/lights/" + num + "/state"
requests.put(addr, json={"on":state})
except Exception as e:
return None;
#
# changeColor
#
def changeColor(ip,user,num,state, sat, bri, hue):
try:
addr = "http://" + ip + "/api/" + user + "/lights/" + num + "/state"
requests.put(addr, json={"on":state, "sat":sat, "bri":bri, "hue":hue})
except Exception as e:
return None;