-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·76 lines (59 loc) · 1.88 KB
/
main.py
File metadata and controls
executable file
·76 lines (59 loc) · 1.88 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0111
import scheduler
import time
import config_handler
import tank_control
import moisture_check
import record_data
import sensor_control
import buzzer_control
import error_control
import email_spreadsheet
def check_for_stop(schedule, config, start_time):
if config['run_duration'] is not None:
if time.time() > start_time + config['run_duration']:
schedule.stop_scheduler()
return time.time() + 5
def main():
schedule = scheduler.Scheduler()
config = config_handler.ConfigHandler()
sensors = sensor_control.Sensor()
buzzer = buzzer_control.Buzzer(config)
error_handler = error_control.ErrorControl(buzzer, sensors, config, schedule)
tank = tank_control.TankControl(config, error_handler=error_handler)
moisture = moisture_check.MoistureCheck(
config, sensors, tank, error_handler)
recorder = record_data.RecordData(config, sensors)
email_spread = email_spreadsheet.Email_Spreadsheet(config, schedule)
schedule.register_task('config_reload', config.run,
(), 0)
schedule.register_task(
'stop',
check_for_stop,
(schedule,
config,
time.time()))
schedule.add_to_schedule('stop', 0) # 86400)
schedule.register_task(
'update_leds', tank.run, (), 0)
schedule.register_task(
'check_for_errors',
error_handler.run,
(), 0)
schedule.register_task(
'check_moisture_level',
moisture.run,
(), 0)
schedule.register_task(
'update_csv', recorder.run, (), 0)
schedule.register_task(
'email_spreadsheet',
email_spread.send_email_every_week,
("data.csv", ),
time.time() + 5)
# all tasks need to be before run scheduler
schedule.run_scheduler()
if __name__ == '__main__':
main()