Implement battery calibration support
Batteries estimate their capacity. This estimation may need to be calibrated occasionally, so ensure that the battery is showing the correct charge level and how much charge it can hold.
In principle, this works by fully discharging the battery and charging it again. Some laptop firmware have features to force a battery to discharge (charge_behaviour
sysfs attribute). This can be set to force-discharge
which will automatically turn off and the battery charges again. A simple calibration run can be implemented by:
- Set start/end charge thresholds to 0/100 (we want to fully charge and start charging at the default value)
- Wait for battery to not charge anymore in case it does
- Set
charge_behaviour
toforce-discharge
- Wait for battery to start charging (it'll be almost empty at that point)
- Wait for battery to be stop charging (it'll be full at that point)
- Set start/end charge threshold to original value
I suppose it may be worth storing the date when we last did a calibration run in some metadata.
Also, we need a method to start calibration. Beyond that, we need may need to report some calibration state information separately from the battery state that we report anyway.
To discuss:
- API to start calibration (new DBus interface?)
- Battery state to report during calibration
- Calibration state to report