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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user