feat(battery): enhance battery guard with thermal runaway protection and openrc service

- Add max_temp thermal protection with 3°C hysteresis to prevent high-temp battery swelling.
- Provide scripts/phone-battery-guard.openrc for automated OpenRC service management.
- Update tests/test_battery_guard.py with thermal throttling tests.
This commit is contained in:
shen
2026-11-08 05:26:21 -08:00
parent 810a467ad3
commit db9d190d7b
3 changed files with 72 additions and 6 deletions
+13
View File
@@ -58,6 +58,19 @@ class BatteryGuardTests(unittest.TestCase):
self.assertEqual((charger / 'charging_enabled').read_text().strip(), '1')
self.assertEqual((charger / 'current_max').read_text().strip(), '1500000')
def test_thermal_protection(self):
policy = guard.BatteryPolicy(low=50, high=65, max_temp=45)
# Low capacity, normal temp (30°C represented as 300 tenths): should charge
self.assertTrue(policy.evaluate(45, temp=300))
# Over-temperature (46°C / 460 tenths): should cut off charging despite low SoC
self.assertFalse(policy.evaluate(45, temp=460))
self.assertTrue(policy.thermal_throttled)
# Cooling slightly (44°C): still paused due to 3°C hysteresis
self.assertFalse(policy.evaluate(45, temp=440))
# Cooled below (max_temp - 3) = 42°C (41°C / 410 tenths): resumes charging
self.assertTrue(policy.evaluate(45, temp=410))
self.assertFalse(policy.thermal_throttled)
if __name__ == '__main__':
unittest.main()