I'm testing an app to let users know when to plug and unplug their laptop to get the most life out of their laptop battery. As well as this I'm trying to replicate the tooltip from the Windows power meter.
It's fairly successful so far with a couple of differences.
- The Windows time remaining notification, e.g. "X hr XX min (XX%) remaining", doesn't show up until after around a minute.
- The Windows time remaining seems more stable under changing battery loads
These lead me to think that the Windows time remaining algorithm is averaging over the past minute or so but I can't find any documentation of that. Does anyone know exactly what it does so I can reproduce it?
Here's my implementation (in Python but the question is language-agnostic). I'm thinking I'll need to average the most recent x
discharge rates from polling every y
seconds but need to know the values for x
and y
.
t = wmi.WMI(moniker = "//./root/wmi")
batts = t.ExecQuery('Select * from BatteryStatus where Voltage > 0')
time_left = 0
for _i, b in enumerate(batts):
time_left += float(b.RemainingCapacity) / float(b.DischargeRate)
hours = int(time_left)
mins = 60 * (time_left % 1.0)
return '%i hr %i min' % (hours, mins)
wmi
, a Python package which presumably at some level wraps those functions. I'm following the implementation from this answer. – Guidebook