- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientExample.py
More file actions
Latest commit
52 lines (45 loc) · 1.39 KB
/
Copy pathclientExample.py
File metadata and controls
52 lines (45 loc) · 1.39 KB
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
importthreading
importtime
light_name="Light"
num_leds=60
state=True
brightness=100
mode="Color"
modes= ["Color", "Rainbow"]
rgb= [255, 50, 255]
defloopClient(diyledclient):
whileTrue:
diyledclient.loop()
time.sleep(1)
defvalueCallback(prop, value):
globalstate
globalbrightness
globalrgb
globalmode
# do your processing/handling in here
if (prop=="power"):
stateString=value# type string
if (stateString=="toggle"):
state=notstate
elif (stateString=="true"):
state=True
elif (stateString=="false"):
state=False
print("Power property changed to: "+str(state))
elif (prop=="brightness"):
brightness=value# type int
print("Brightness property changed to: "+str(brightness))
elif (prop=="color"):
rgb=value# type int array[3]
print("Color property changed to: ["+str(rgb[0]) +", "+str(rgb[1]) +", "+str(rgb[2]) +"]")
elif (prop=="mode"):
mode=value# type string
print("Mode property changed to: "+str(mode))
defstateGetCallback():
returnDeviceProperties(light_name, num_leds, state, brightness, mode, modes, rgb[0], rgb[1], rgb[2])
if__name__=="__main__":
client=DiyLedClient(valueCallback, stateGetCallback)
client.begin()
clientLoop=threading.Thread(target=loopClient, args= (client,))
clientLoop.daemon=True
clientLoop.start()