battery() timeremaining optimization (linux)

This commit is contained in:
Sebastian Hildebrandt
2018-11-21 22:59:40 +01:00
parent fc63865f33
commit 8dad45b5fa
3 changed files with 5 additions and 0 deletions
+3
View File
@@ -70,6 +70,7 @@ module.exports = function (callback) {
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10);
const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10);
result.percent = parseInt('0' + percent, 10);
if (result.maxcapacity && result.currentcapacity) {
@@ -83,6 +84,8 @@ module.exports = function (callback) {
}
if (energy && power) {
result.timeremaining = Math.floor(energy / power * 60);
} else if (current && result.currentcapacity) {
result.timeremaining = Math.floor(result.currentcapacity / current * 60);
}
result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');