This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (52 loc) · 1.75 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
try: from typing import List
except: pass
from lib.pot import Pot
from lib.device import Device
from env import TEST_ENV
TICK_RATE_IN_S = 2
class AutoGarden:
def __init__(self) -> None:
try:
print("-> Starting AutoGarden")
self.device = Device(TICK_RATE_IN_S)
self.pots = self.setup_pots()
self.loop()
except Exception as e:
self.device.handle_system_error(str(e))
def loop(self) -> None:
try:
while True:
for pot in self.pots:
pot.update()
# Only run the loop once in tests
if TEST_ENV == True: break
self.device.sleep(TICK_RATE_IN_S)
except KeyboardInterrupt:
print("-> Stopping AutoGarden")
for pot in self.pots:
pot.device_io.cleanup()
def setup_pots(self) -> List[Pot]:
pots = []
pots_collection = self.device.pb.get_pots()
if len(pots_collection) == 0:
raise Exception("No pots to irrigate")
for pot in pots_collection:
pots.append(
Pot(
self.device,
pot["id"],
pot["name"],
pot["moisture_low"],
pot["moisture_high"],
pot["moisture_sensor_dry"],
pot["moisture_sensor_wet"],
pot["moisture_sensor_pin"],
pot["pump_max_attempts"],
pot["pump_duration_in_s"],
pot["pump_frequency_in_s"],
pot["pump_relay_pin"],
)
)
return pots
if __name__ == "__main__":
auto_garden = AutoGarden()