-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightserver.py
executable file
·101 lines (83 loc) · 2.24 KB
/
lightserver.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
import wifileds
import time
from flask import Flask
app = Flask(__name__)
PORT=8899
class ColorTypes:
White=0
Color=1
zoneMap = [ -1, 0, 0, 0, 0, 1, 1, 1, 1, 2 ]
bridgeIps = { 0:'192.168.0.17', 1:'192.168.0.18', 2:'192.168.0.18'}
zoneTypes = { 0: ColorTypes.White, 1: ColorTypes.White, 2: ColorTypes.Color }
def getBridge(id):
return wifileds.limitlessled.connect(bridgeIps[id], 8899)
@app.route('/')
def index():
return 'Light Server'
def hello_world():
return 'OK'
@app.route('/on')
def all_on():
for bridgeId,ip in bridgeIps:
bri=getBridge(bridgeId)
bri.white.all_on()
del bri
return hello_world();
@app.route('/off')
def all_off():
bri=getBridge(0)
bri.white.all_off()
del bri
return hello_world();
'''@app.route('/zone/<int:z>')
def zone(z):
bri=getBridge()
bri.white.zone_on(z)
del bri
return hello_world();
'''
@app.route('/zone/<int:z>/<int:level>')
def zone(z, level):
id = zoneMap[z];
if id == -1:
allzones(level);
else:
bri = getBridge(id)
zNum = (z % 4) or 4;
if zoneTypes[id] == ColorTypes.White:
if level == 0:
bri.white.zone_off(zNum)
elif level == 2:
bri.white.nightlight_zone(zNum)
else:
bri.white.zone_on(zNum)
elif zoneTypes[id] == ColorTypes.Color:
if level == 0:
bri.rgbw.zone_off(zNum)
elif level == 2:
bri.rgbw.set_brightness(2,zNum)
else:
bri.rgbw.zone_on(zNum)
del bri
return hello_world();
def allzones( level ):
for id in bridgeIps:
bri=getBridge(id)
if level == 0:
if zoneTypes[id] == ColorTypes.Color:
bri.rgbw.all_off()
else:
bri.white.all_off()
elif level == 2:
if zoneTypes[id] == ColorTypes.Color:
bri.rgbw.all_off()
else:
bri.white.nightlight_all()
else:
if zoneTypes[id] == ColorTypes.Color:
bri.rgbw.all_on()
else:
bri.white.all_on()
if __name__ == '__main__':
app.run(host='0.0.0.0', port=2000)