-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·36 lines (29 loc) · 940 Bytes
/
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
#!/usr/bin/python3
import threading
import asyncio
import sys
import ui
import os
import common as c
from monitor import monitor
from readings import readings
# Get current environment - is it a Raspberry or another PC? Non-Raspberry PCs
# don't understand the Raspberry-specific commands for monitor control.
RASP_ENV = os.getenv('RASP_ENV', '') == '1'
app = ui.get_app()
monitor = monitor(c.routine, RASP_ENV)
readings = readings(monitor, app.get_queue())
def worker():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_task(monitor.update_state()) # turns on/off monitor
loop.create_task(readings.update_state()) # reads data from home-sensors
loop.run_forever()
worker_thread = threading.Thread(target = worker)
worker_thread.daemon = True # ensures cleaner exit on SIGINT
try:
worker_thread.start()
app.mainloop()
except KeyboardInterrupt:
monitor.turn_on()
sys.exit()