-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzenlight.py
More file actions
executable file
·99 lines (82 loc) · 3.07 KB
/
Copy pathzenlight.py
File metadata and controls
executable file
·99 lines (82 loc) · 3.07 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
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
#!/usr/bin/env python
import sys, time, requests, json
from nuimo import NuimoController
from daemon import Daemon
#class zenlight:#(Daemon):
#def run(self):
def main():
# Discover Nuimo Controllers
nuimo = NuimoController('CE:D8:42:A7:9A:78')
#adapter = 'hci0' # Typical bluetooth adapter name
#nuimo_manager = NuimoDiscoveryManager(bluetooth_adapter=adapter, delegate=DiscoveryLogger())
#nuimo_manager.start_discovery()
# Were any Nuimos found?
#if len(nuimo_manager.nuimos) == 0:
# print('No Nuimos detected')
# sys.exit(0)
# Take the first Nuimo found.
#nuimo = nuimo_manager.nuimos[0]
# Set up handling of Nuimo events.
# In this case just log each incoming event.
# NuimoLogger is defined below.
nuimo_event_delegate = NuimoLightController()
nuimo.set_delegate(nuimo_event_delegate)
# Attach to the Nuimo.
nuimo.connect()
# Display an icon for 2 seconds
interval = 2.0
MATRIX_LIGHTBULB = (
" " +
" ... " +
" . . " +
" . . " +
" . . " +
" ... " +
" ... " +
" ... " +
" . ")
nuimo.write_matrix(MATRIX_LIGHTBULB, interval)
# Nuimo events are dispatched in the background
while (True):
time.sleep(1)
nuimo.disconnect()
#if __name__ == "__main__":
# daemon = zenlight('/tmp/zenlight.pid')
# if len(sys.argv) == 2:
# if 'start' == sys.argv[1]:
# daemon.start()
# elif 'stop' == sys.argv[1]:
# daemon.stop()
# elif 'restart' == sys.argv[1]:
# daemon.restart()
# else:
# print "Unknown command"
# sys.exit(2)
# sys.exit(0)
# else:
# print "usage: %s start|stop|restart" % sys.argv[0]
# sys.exit(2)
class NuimoLightController:
def connection_state_changed(self, state, error=None):
print (state)
self.connect()
def received_gesture_event(self, event):
state = requests.get('http://192.168.178.26:8080/api/593401F6D7/groups/3/')
state = state.json()
#print(json.dumps(state))
state_light_on = state["action"]["on"]
state_bri = state["action"]["bri"]
if (event.gesture == 1): # BUTTON_PRESS
if (state_light_on):
on = 'false'
else:
on = 'true'
requests.put('http://192.168.178.26:8080/api/593401F6D7/groups/3/action', data='{"on": '+on+'}')
elif (event.gesture == 3) and (event.value > 0): # ROTATE_RIGHT
if (state_bri <= 255):
resp = requests.put('http://192.168.178.26:8080/api/593401F6D7/groups/3/action', data='{"bri": '+str(state_bri+10)+'}')
elif (event.gesture == 3) and (event.value < 0): #ROTATE_LEFT
resp = requests.put('http://192.168.178.26:8080/api/593401F6D7/groups/3/action', data='{"bri": '+str(state_bri-10)+'}')
#print("received event: name={}, gesture_id={}, value={}".format(event.name, event.gesture ))
if __name__ == '__main__':
main()