fix: windows battery Dell & ThinkPad
This commit is contained in:
parent
d0d55b1059
commit
465b6f8d2a
@ -41,7 +41,7 @@ function parseWinBatteryPart(lines, designCapacity, fullChargeCapacity) {
|
||||
// 9 = "Charging Critical"
|
||||
// 10 = "Undefined"
|
||||
// 11 = "Partially Charged"
|
||||
if (lines.join('').toLowerCase().indexOf('BatteryStatus') >= 0) {
|
||||
if (status >= 0) {
|
||||
const statusValue = status ? parseInt(status) : 0;
|
||||
result.status = statusValue;
|
||||
result.hasBattery = true;
|
||||
@ -50,7 +50,7 @@ function parseWinBatteryPart(lines, designCapacity, fullChargeCapacity) {
|
||||
result.voltage = parseInt(util.getValue(lines, 'DesignVoltage', '=') || 0) / 1000.0;
|
||||
result.capacityUnit = 'mWh';
|
||||
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
|
||||
result.currentCapacity = parseInt(result.maxcapacity * result.percent / 100);
|
||||
result.currentCapacity = parseInt(result.maxCapacity * result.percent / 100);
|
||||
result.isCharging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (!(statusValue === 3) && !(statusValue === 1) && result.percent < 100);
|
||||
result.acConnected = result.ischarging || statusValue === 2;
|
||||
result.model = util.getValue(lines, 'DeviceID', '=');
|
||||
@ -217,14 +217,24 @@ module.exports = function (callback) {
|
||||
workload
|
||||
).then(data => {
|
||||
if (data) {
|
||||
let parts = data.results[0].split(/\n\s*\n/);
|
||||
let parts = data.results[0].split('\r\n')
|
||||
let batteries = [];
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const hasValue = value => /\S/.test(value);
|
||||
if (hasValue(parts[i]) && (!batteries.length || !hasValue(parts[i - 1]))) {
|
||||
batteries.push([])
|
||||
}
|
||||
if (hasValue(parts[i])) {
|
||||
batteries[batteries.length - 1].push(parts[i]);
|
||||
}
|
||||
}
|
||||
let designCapacities = data.results[1].split('\r\n');
|
||||
let fullChargeCapacities = data.results[2].split('\r\n');
|
||||
if (parts && parts.length) {
|
||||
if (batteries && batteries.length) {
|
||||
let first = false;
|
||||
let additionalBatteries = [];
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
let lines = parts[i].split('\r\n');
|
||||
for (let i = 0; i < batteries.length; i++) {
|
||||
let lines = batteries[i]
|
||||
const designCapacity = designCapacities && designCapacities.length >= (i + 1) && designCapacities[i] ? util.toInt(designCapacities[i]) : 0;
|
||||
const fullChargeCapacity = fullChargeCapacities && fullChargeCapacities.length >= (i + 1) && fullChargeCapacities[i] ? util.toInt(fullChargeCapacities[i]) : 0;
|
||||
const parsed = parseWinBatteryPart(lines, designCapacity, fullChargeCapacity);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user