forked from ianepperson/midnight_museum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (53 loc) · 1.59 KB
/
main.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
from argparse import ArgumentParser
import logging
import quart
# from mqtt import get_mqtt_handler
from lights import get_lights
from effects import get_effects_handler
from setup import Setup
from web_server import app
logging.basicConfig(level=logging.DEBUG)
def create_app():
lights_handler = get_lights(setup)
effects_handler = get_effects_handler(setup, lights_handler)
@app.before_serving
async def startup():
print('Starting lights communication...')
lights_handler.start()
print('Starting effects handler...')
effects_handler.start()
@app.before_request
def load_controls():
quart.g.lights = lights_handler
quart.g.effects = effects_handler
quart.g.setup = setup
@app.before_websocket
def load_ws_controls():
quart.g.lights = lights_handler
quart.g.effects = effects_handler
quart.g.setup = setup
return app
if __name__ == '__main__':
# Initialize parser
parser = ArgumentParser()
parser.add_argument(
'--setup',
metavar='FILENAME',
help='The JSON file to read/store configuration.',
default='setup.json'
)
parser.add_argument(
'--http_server_port',
metavar='PORT',
help='The port the web interface is served on',
type=int,
default=8080
)
# Grab the arguments
args = parser.parse_args()
# Create the setup file
setup = Setup(args.setup)
# Run with it
# go(setup, args.http_server_port)
app_ = create_app()
app_.run(port=args.http_server_port, host='0.0.0.0')