diff --git a/lib/battery.js b/lib/battery.js index a0aa83f..22627ec 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -114,12 +114,12 @@ module.exports = function (callback) { result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0; result.capacityUnit = result.voltage ? 'mWh' : 'mAh'; result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10); - result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10) / 1000.0 * (result.voltage || 1)); - result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 * (result.voltage || 1)); + result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0 * (result.voltage || 1)); + result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '=', true, true), 10) / 1000.0 * (result.voltage || 1)); result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 * (result.voltage || 1)); if (!result.maxCapacity) { - result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10) / 1000.0; - result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '='), 10) / 1000.0 | result.maxCapacity; + result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '=', true, true), 10) / 1000.0; + result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', true, true, '='), 10) / 1000.0 | result.maxCapacity; result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0; } const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '='); diff --git a/lib/util.js b/lib/util.js index 32936f3..3c48ef7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -103,16 +103,17 @@ function cores() { return _cores; } -function getValue(lines, property, separator, trimmed) { +function getValue(lines, property, separator, trimmed, lineMatch) { separator = separator || ':'; property = property.toLowerCase(); trimmed = trimmed || false; + lineMatch = lineMatch || false; for (let i = 0; i < lines.length; i++) { let line = lines[i].toLowerCase().replace(/\t/g, ''); if (trimmed) { line = line.trim(); } - if (line.startsWith(property)) { + if (line.startsWith(property) && (lineMatch ? (line.match(property + separator)) : true)) { const parts = trimmed ? lines[i].trim().split(separator) : lines[i].split(separator); if (parts.length >= 2) { parts.shift();