From d6ea1d2e5c012f90b61aeac2814ccad170e1a7c7 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 28 Aug 2018 17:46:15 +0200 Subject: [PATCH] code cleanup --- CHANGELOG.md | 1 + lib/battery.js | 19 +++++++++++++++---- lib/cpu.js | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 537fdba..8a61d4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.44.1 | 2018-08-28 | code cleanup | | 3.44.0 | 2018-08-25 | `battery()` bugfix & added type, model, manufacturer, serial | | 3.43.0 | 2018-08-25 | `cpuCurrentspeed()` added cpu speed for all cores | | 3.42.10 | 2018-08-25 | `processes()` optimized start time parsing | diff --git a/lib/battery.js b/lib/battery.js index 9609e0e..d15a1cf 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -130,7 +130,7 @@ module.exports = function (callback) { if (parts && parts[0]) { let parts2 = parts[0].split('\t'); if (parts2 && parts2[1]) { - percent = parseFloat(parts2[1].trim().replace('%', '')); + percent = parseFloat(parts2[1].trim().replace(/%/g, '')); } } if (parts && parts[1]) { @@ -163,13 +163,24 @@ module.exports = function (callback) { if (stdout) { let lines = stdout.split('\r\n'); let status = util.getValue(lines, 'BatteryStatus', '=').trim(); - if (status) { - status = parseInt(status || '2'); + // 1 = "Discharging" + // 2 = "On A/C" + // 3 = "Fully Charged" + // 4 = "Low" + // 5 = "Critical" + // 6 = "Charging" + // 7 = "Charging High" + // 8 = "Charging Low" + // 9 = "Charging Critical" + // 10 = "Undefined" + // 11 = "Partially Charged" + if (status && status != '10') { + const statusValue = parseInt(status); result.hasbattery = true; result.maxcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0); result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0); result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100); - result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100); + result.ischarging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (!(statusValue === 3) && !(statusValue === 1) && result.percent < 100); result.acconnected = result.ischarging; } } diff --git a/lib/cpu.js b/lib/cpu.js index 6a2946a..d0b0558 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -522,7 +522,7 @@ function cpuTemperature(callback) { lines.forEach(function (line) { const parts = line.split(':'); if (parts.length > 0) { - const temp = parseFloat(parts[1].replace(',', '.'), 10); + const temp = parseFloat(parts[1].replace(',', '.')); if (temp > result.max) result.max = temp; sum = sum + temp; result.cores.push(temp);