-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplash_trigger.py
More file actions
46 lines (37 loc) · 1.51 KB
/
Copy pathsplash_trigger.py
File metadata and controls
46 lines (37 loc) · 1.51 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
import time
import json
class SplashTrigger:
def __init__(self, interval=None):
if interval is None:
# Читаем из конфига если не передан явно
try:
with open("config.json") as f:
cfg = json.load(f)
self.interval = cfg.get("inputs", {}).get("ina226", {}).get("splash_interval_sec", 30)
except Exception:
self.interval = 30
else:
self.interval = interval
self.last_splash_time = time.monotonic()
self.last_reason = ""
def tick(self, is_idle: bool, ina_available: bool = True) -> bool:
"""
Если ina_available=False — таймер не считается, всегда False.
"""
if not ina_available:
return False
if not is_idle:
return False # не сбрасывать таймер, просто не срабатывать
now = time.monotonic()
if now - self.last_splash_time >= self.interval:
self.last_splash_time = now
self.last_reason = "TIMER"
return True
return False
def reset_timer(self):
"""Сброс таймера при входе в screensaver"""
self.last_splash_time = time.monotonic()
def fire_event(self, reason: str) -> bool:
self.last_reason = reason
self.last_splash_time = time.monotonic()
return True