summaryrefslogtreecommitdiffstats
path: root/hyprsunset_qt
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 10:51:11 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 10:51:11 +0200
commit869459e79b296f9e6900f9439b95f817ac836f1f (patch)
treef6e8bb7b0c97e0f085f79be15aec08b83052e45c /hyprsunset_qt
parentebdf809e0723ba3d32794278c72e4cd844cea498 (diff)
downloadhyprsunset-qt-869459e79b296f9e6900f9439b95f817ac836f1f.tar.gz
hyprsunset-qt-869459e79b296f9e6900f9439b95f817ac836f1f.zip
feat: field validation helpers
Add validation functions for config parameters: valid_time() for HH:MM format (0-23:0-59), valid_temperature() for Kelvin range 1000-20000, and valid_gamma() for gamma range 0.0-2.0. These are used by the UI before saving config changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'hyprsunset_qt')
-rw-r--r--hyprsunset_qt/config.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/hyprsunset_qt/config.py b/hyprsunset_qt/config.py
index a718861..8001f29 100644
--- a/hyprsunset_qt/config.py
+++ b/hyprsunset_qt/config.py
@@ -99,3 +99,18 @@ def write_config(profiles: list[Profile], path: Path = CONFIG_PATH) -> None:
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(serialize(profiles))
+
+
+_TIME_RE = re.compile(r"^([01]?\d|2[0-3]):([0-5]\d)$")
+
+
+def valid_time(s: str) -> bool:
+ return bool(_TIME_RE.match(s))
+
+
+def valid_temperature(t: int) -> bool:
+ return 1000 <= t <= 20000
+
+
+def valid_gamma(g: float) -> bool:
+ return 0.0 <= g <= 2.0