battery() fix linux getValue

This commit is contained in:
Sebastian Hildebrandt 2021-09-13 10:57:22 +02:00
parent a8c46c7f5e
commit 8ef123e0e1
2 changed files with 7 additions and 6 deletions

View File

@ -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', '=');

View File

@ -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();