View Single Post
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#619
small variation.
shows remaining charging time if charger connected
shows average remaining usage time ( (idle+talk) / 2) if charger disconnected
using current psm mode to detect remaining time (powersave or not)

Code:
#!/usr/bin/python

import QmSystem

batt = QmSystem.QmBattery()

if batt.getChargingState()==1:
        time = batt.getRemainingChargingTime()
else:
        mode = QmSystem.QmBattery.NormalMode if QmSystem.QmDeviceMode().getPSMState() == 0 else QmSystem.QmBattery.PowersaveMode
        time = batt.getRemainingIdleTime(mode)
        time += batt.getRemainingTalkTime(mode)
        time = time/2
hours,mod = divmod(time,3600)
mins,secs = divmod(mod,60)

result = []
if hours == 1:
    result.append('%d hour' % hours)
elif hours > 0:
    result.append('%d hours' % hours)
if mins == 1:
    result.append('%d minute' % mins)
elif mins > 0 or not result:
    result.append('%d minutes' % mins)
print ' '.join(result)
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following User Says Thank You to coderus For This Useful Post: