-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (70 loc) · 2.46 KB
/
main.py
File metadata and controls
77 lines (70 loc) · 2.46 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
"""Entry point for running the hydroponics system."""
from __future__ import annotations
import logging
import os
from hydroponics.app.runner import run_configured_system
from hydroponics.config.registry import validate_startup_configuration
from hydroponics.storage.runtime_mode_store import (
check_hardware_runtime_support,
read_runtime_mode_state,
write_runtime_mode_state,
)
from hydroponics.support.errors import ControlError, build_error_message
from hydroponics.support.runtime import ShutdownSignal
def main() -> None:
"""
Summary:
Launch the hydroponics system using the configured mode.
Inputs:
None.
Outputs:
None. Runs the configured system until interrupted.
Side effects:
Installs signal handlers and starts long running control loops.
Error handling:
ControlError: If the configured system fails to start.
Ties to other methods:
Called when running the repository entry point script.
Why this exists:
Centralized entry point keeps runtime behavior consistent.
"""
try:
validate_startup_configuration()
target_mode = read_runtime_mode_state().target_mode
if target_mode == "hardware":
supported, reason = check_hardware_runtime_support()
if not supported:
os.environ["HYDROPONICS_SIM"] = "1"
detail = reason or "Hardware mode is unavailable on this host."
logging.warning(
build_error_message(
"main",
"main",
f"Requested hardware mode is not supported: {detail}",
hint="Falling back to simulator mode.",
)
)
try:
write_runtime_mode_state(target_mode="simulator")
except Exception:
pass
else:
os.environ.pop("HYDROPONICS_SIM", None)
else:
os.environ["HYDROPONICS_SIM"] = "1"
shutdown = ShutdownSignal()
shutdown.install()
try:
run_configured_system(shutdown=shutdown)
finally:
shutdown.restore()
except Exception as exc:
raise ControlError(
build_error_message(
"main",
"main",
f"Failed to run configured system: {exc}",
)
) from exc
if __name__ == "__main__":
main()