forked from google/makerspace-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqa.py
More file actions
79 lines (63 loc) · 2.1 KB
/
Copy pathqa.py
File metadata and controls
79 lines (63 loc) · 2.1 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
#!/usr/bin/python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Example to test all the buttons.
"""
from __future__ import print_function
import sys
import time
from authbox.api import BaseDispatcher
from authbox.config import Config
from authbox.timer import Timer
DEVNULL = open('/dev/null', 'r+')
class Dispatcher(BaseDispatcher):
def __init__(self, config):
super(Dispatcher, self).__init__(config)
for i in range(1, 6+1):
self.load_config_object('j%d' % i, on_down=self.on_button_down)
self.load_config_object('buzzer')
self.load_config_object('relays')
# This may be a MultiProxy, which makes this easier.
self.relays.on()
self.relay_value = True
# Run fans for 10 seconds on startup
self.relay_timer = Timer(self.event_queue, 'relay_timer', self.toggle_relays)
self.relay_toggle_interval = 10
self.relay_timer.set(self.relay_toggle_interval)
self.threads.extend([self.relay_timer])
def on_button_down(self, source):
print("Button down", source)
self.buzzer.beep()
source.on()
time.sleep(0.3)
source.off()
def toggle_relays(self, source):
print("Toggle relay", self.relay_value)
if self.relay_value:
self.relays.off()
self.relay_value = False
else:
self.relays.on()
self.relay_value = True
self.relay_timer.set(self.relay_toggle_interval)
def main(args):
if not args:
config_filename = 'qa.ini'
else:
config_filename = args[0]
config = Config(config_filename)
Dispatcher(config).run_loop()
if __name__ == '__main__':
main(sys.argv[1:])