cockpit: battery/power card; van-battery publishes thresholds in state
New "Battery / Power" card shows mains vs battery, charge % with a severity- colored bar (only bites while on battery), the last alert level, and the configured warn/shutdown thresholds. van-battery now includes warn_levels + shutdown_level in /run/van-battery/state.json so the card stays self-describing instead of hardcoding the numbers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
52e948654e
commit
473a75c729
+4
-2
@@ -150,13 +150,15 @@ def poweroff(cfg):
|
||||
log(f"poweroff failed: {e}", "crit")
|
||||
|
||||
|
||||
def write_state(on_batt, cap, armed):
|
||||
def write_state(on_batt, cap, armed, warn_levels, shutdown_level):
|
||||
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
payload = {
|
||||
"updated": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
||||
"on_battery": on_batt,
|
||||
"capacity": cap,
|
||||
"alerted_below": armed, # lowest level alerted this discharge episode, or null
|
||||
"warn_levels": warn_levels,
|
||||
"shutdown_level": shutdown_level,
|
||||
}
|
||||
tmp = STATE_PATH.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(payload))
|
||||
@@ -216,7 +218,7 @@ def main():
|
||||
|
||||
prev_on_batt = on_batt
|
||||
try:
|
||||
write_state(on_batt, cap, last_alerted)
|
||||
write_state(on_batt, cap, last_alerted, cfg["warn_levels"], shutdown_level)
|
||||
except OSError as e:
|
||||
log(f"state write failed: {e}", "warn")
|
||||
time.sleep(cfg["poll_interval"])
|
||||
|
||||
Reference in New Issue
Block a user