feat(battery): implement emergency safe shutdown when battery <= 5% discharging
Offline project checks / check (push) Canceled after 0s

- Add should_shutdown() check in BatteryPolicy and trigger_shutdown() in phone-battery-guard.py.
- Auto sync filesystems and invoke safe poweroff if SoC drops to 5% while on battery/discharging.
- Do not power off if external charger is actively connected and charging.
- Update openrc service command args with --shutdown-at 5.
- Add unit tests for emergency shutdown, discharging detection, and threshold validation.
This commit is contained in:
shen
2026-11-08 05:32:04 -08:00
parent db9d190d7b
commit 23989f4a18
3 changed files with 119 additions and 7 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
#!/sbin/openrc-run
description="Platina battery health and anti-swelling daemon (maintains 50-65% SoC)"
description="Platina battery health and emergency shutdown daemon (50-65% SoC, auto-poweroff <= 5%)"
command="/usr/local/sbin/platina-battery-guard"
command_user="root:root"
command_args="--low ${low:-50} --high ${high:-65} --max-temp ${max_temp:-45} --interval ${interval:-60}"
command_args="--low ${low:-50} --high ${high:-65} --max-temp ${max_temp:-45} --shutdown-at ${shutdown_at:-5} --interval ${interval:-60}"
command_background="yes"
pidfile="/run/platina-battery-guard.pid"
output_log="/var/log/platina-battery-guard.log"