code cleanup

This commit is contained in:
Sebastian Hildebrandt 2018-08-28 17:46:15 +02:00
parent e03dd54920
commit d6ea1d2e5c
3 changed files with 17 additions and 5 deletions

View File

@ -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 |

View File

@ -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;
}
}

View File

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