battery() fixed parsing (linux)

This commit is contained in:
Sebastian Hildebrandt
2023-09-20 06:07:17 +02:00
parent f6a0bd3fb2
commit 51a3744217
4 changed files with 10 additions and 1 deletions
+3
View File
@@ -127,6 +127,7 @@ module.exports = function (callback) {
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);
const charge = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10);
result.percent = parseInt('0' + percent, 10);
if (result.maxCapacity && result.currentCapacity) {
@@ -140,6 +141,8 @@ module.exports = function (callback) {
}
if (energy && power) {
result.timeRemaining = Math.floor(energy / power * 60);
} else if (current && charge) {
result.timeRemaining = Math.floor(charge / current * 60);
} else if (current && result.currentCapacity) {
result.timeRemaining = Math.floor(result.currentCapacity / current * 60);
}