Add an actions box showing why each switch changed

This commit is contained in:
Sterling Archer committed 2026-08-12 10:53:34 -07:00
1 parent a28db4d1c9
commit 6c43256088
3 files changed
+338 -8

No files matched your search

+47
View File
@@ -663,6 +663,51 @@ def cmd_status(args):
print("stopped")
def record_manual_event(profile_path, target, desired):
import json
import time
from datetime import datetime
from .profiles import load_yaml as _load
try:
identity = (_load(profile_path).get("identity") or {})
except Exception:
identity = {}
event = {
"epoch": time.time(),
"when": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"state": bool(desired),
"cause": "manual",
"profile": None,
"rule": None,
"condition": None,
"reason": "switched manually from the command line",
"target": identity.get("name") or identity.get("model") or target.host,
"target_channel": target.channel,
"source": None,
"source_serial": None,
"values": {},
}
path = paths.STATE_DIR / "events-manual.json"
try:
paths.STATE_DIR.mkdir(parents=True, exist_ok=True)
history = []
if path.exists():
try:
history = json.loads(path.read_text(encoding="utf-8"))
except Exception:
history = []
if not isinstance(history, list):
history = []
history.append(event)
path.write_text(json.dumps(history[-200:]), encoding="utf-8")
except Exception:
pass
def cmd_switch(args):
from .shelly import ShellyTarget
import aiohttp
@@ -704,6 +749,8 @@ def cmd_switch(args):
except Exception as err:
fail(f"{type(err).__name__}: {err}")
record_manual_event(path, target, desired)
await asyncio.sleep(1.0)
confirmed = await target.get_state(session)
if confirmed is None: