battery: alert on mains<->battery transitions
Pushover notification when the router loses mains (now on battery) and when mains is restored. One alert per real transition; first sample is skipped so a restart while already on battery doesn't false-fire. Independent of the low-charge 25/20/15/10% alerts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b75b5b16c7
commit
52e948654e
+15
-4
@@ -177,15 +177,26 @@ def main():
|
|||||||
on_batt = read_on_battery(cfg)
|
on_batt = read_on_battery(cfg)
|
||||||
cap = read_capacity(cfg)
|
cap = read_capacity(cfg)
|
||||||
|
|
||||||
|
capstr = f"{cap}%" if cap is not None else "unknown charge"
|
||||||
|
|
||||||
|
# Mains <-> battery transition alerts. Skip the very first sample (prev is None)
|
||||||
|
# so a restart while already on battery doesn't fire a spurious "on battery".
|
||||||
|
if on_batt is not None and prev_on_batt is not None and on_batt != prev_on_batt:
|
||||||
|
if on_batt:
|
||||||
|
log(f"mains lost — running on battery at {capstr}", "warn")
|
||||||
|
pushover(cfg, f"⚡ {HOST}: on battery",
|
||||||
|
f"Mains power lost — now running on battery ({capstr}). "
|
||||||
|
f"Low alerts at {cfg['warn_levels']}%, auto-shutdown at {shutdown_level}%.")
|
||||||
|
else:
|
||||||
|
log(f"mains restored at {capstr} — alerts re-armed")
|
||||||
|
pushover(cfg, f"🔌 {HOST}: back on mains",
|
||||||
|
f"Mains power restored ({capstr}). Battery alert sequence re-armed.")
|
||||||
|
|
||||||
if on_batt is False:
|
if on_batt is False:
|
||||||
# On mains: re-arm the whole sequence for the next discharge episode.
|
# On mains: re-arm the whole sequence for the next discharge episode.
|
||||||
if prev_on_batt:
|
|
||||||
log("mains restored — alerts re-armed")
|
|
||||||
last_alerted = None
|
last_alerted = None
|
||||||
shutdown_issued = False
|
shutdown_issued = False
|
||||||
elif on_batt is True and cap is not None:
|
elif on_batt is True and cap is not None:
|
||||||
if prev_on_batt is False:
|
|
||||||
log(f"mains lost — running on battery at {cap}%", "warn")
|
|
||||||
sev = severity(cap, levels)
|
sev = severity(cap, levels)
|
||||||
if sev is not None and (last_alerted is None or sev < last_alerted):
|
if sev is not None and (last_alerted is None or sev < last_alerted):
|
||||||
last_alerted = sev
|
last_alerted = sev
|
||||||
|
|||||||
Reference in New Issue
Block a user