battery() fix linux getValue
This commit is contained in:
parent
a8c46c7f5e
commit
8ef123e0e1
@ -114,12 +114,12 @@ module.exports = function (callback) {
|
|||||||
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
|
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
|
||||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||||
result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
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.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', '='), 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));
|
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 * (result.voltage || 1));
|
||||||
if (!result.maxCapacity) {
|
if (!result.maxCapacity) {
|
||||||
result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10) / 1000.0;
|
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', '='), 10) / 1000.0 | result.maxCapacity;
|
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;
|
result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
|
||||||
}
|
}
|
||||||
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
|
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
|
||||||
|
|||||||
@ -103,16 +103,17 @@ function cores() {
|
|||||||
return _cores;
|
return _cores;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValue(lines, property, separator, trimmed) {
|
function getValue(lines, property, separator, trimmed, lineMatch) {
|
||||||
separator = separator || ':';
|
separator = separator || ':';
|
||||||
property = property.toLowerCase();
|
property = property.toLowerCase();
|
||||||
trimmed = trimmed || false;
|
trimmed = trimmed || false;
|
||||||
|
lineMatch = lineMatch || false;
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
let line = lines[i].toLowerCase().replace(/\t/g, '');
|
let line = lines[i].toLowerCase().replace(/\t/g, '');
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
line = line.trim();
|
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);
|
const parts = trimmed ? lines[i].trim().split(separator) : lines[i].split(separator);
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
parts.shift();
|
parts.shift();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user