From 85add8ec09302b9e4d613cddd078ea84a6e590fe Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 5 Jan 2025 15:12:52 +0100 Subject: [PATCH] battery() improved serial and model parsing --- CHANGELOG.md | 3 ++- README.md | 2 +- docs/history.html | 5 +++++ docs/index.html | 2 +- lib/battery.js | 5 +++-- lib/cpu.js | 2 +- lib/system.js | 6 +++--- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f78f491..c4bd7372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,7 +90,8 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | -| 5.25.1 | 2025-01-05 | `cpuCurrentSpeed()` denno speed workarround | +| 5.25.2 | 2025-01-05 | `battery()` improved serial and model parsing | +| 5.25.1 | 2025-01-05 | `cpuCurrentSpeed()` Deno CPU speed workarround (linux) | | 5.25.0 | 2025-01-05 | `versions()` added homebrew | | 5.24.9 | 2025-01-04 | `checkWebsite()` reestablished certificate validation | | 5.24.9 | 2025-01-04 | `checkWebsite()` reestablished certificate validation | diff --git a/README.md b/README.md index a1bde067..6472ff15 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ si.cpu() (last 7 major and minor version releases) -- Version 5.24.0: `versions()` added homebrew +- Version 5.25.0: `versions()` added homebrew - Version 5.24.0: `versions()` added bun and deno - Version 5.23.0: `usb()` added serial number (linux) - Version 5.22.0: `wifiConnections()` added signal quality diff --git a/docs/history.html b/docs/history.html index 876b0864..9e2eaaef 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@

Full version history

+ + 5.25.2 + 2024-01-05 + battery() improved model and serial parsing (macOS) + 5.25.1 2024-01-05 diff --git a/docs/index.html b/docs/index.html index ff9e2d5b..f5141e95 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
- 3
New Version: 5.25.1
+ 3
New Version: 5.25.2
diff --git a/lib/battery.js b/lib/battery.js index c61ec3b6..eced1435 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -181,7 +181,7 @@ module.exports = function (callback) { } if (_darwin) { - exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining|Voltage"; pmset -g batt | grep %', function (error, stdout) { + exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|DeviceName|BatterySerialNumber|Serial|TimeRemaining|Voltage"; pmset -g batt | grep %', function (error, stdout) { if (stdout) { let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n'); result.cycleCount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10); @@ -191,7 +191,8 @@ module.exports = function (callback) { result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawcurrentcapacity', '='), 10) * (result.voltage || 1)); result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1)); result.manufacturer = 'Apple'; - result.serial = util.getValue(lines, 'BatterySerialNumber', '='); + result.serial = util.getValue(lines, 'BatterySerialNumber', '=') || util.getValue(lines, 'Serial', '='); + result.model = util.getValue(lines, 'DeviceName', '='); let percent = null; const line = util.getValue(lines, 'internal', 'Battery'); let parts = line.split(';'); diff --git a/lib/cpu.js b/lib/cpu.js index bd060d9c..27ca7287 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -1019,7 +1019,7 @@ function getCpuCurrentSpeedSync() { if (speeds[i] < minFreq) { minFreq = speeds[i]; } cores.push(parseFloat(speeds[i].toFixed(2))); } - avgFreq = avgFreq / cpus.length; + avgFreq = avgFreq / speeds.length; return { min: parseFloat(minFreq.toFixed(2)), max: parseFloat(maxFreq.toFixed(2)), diff --git a/lib/system.js b/lib/system.js index f982ea8d..4abc9387 100644 --- a/lib/system.js +++ b/lib/system.js @@ -48,11 +48,11 @@ function system(callback) { if (_linux || _freebsd || _openbsd || _netbsd) { exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', function (error, stdout) { let lines = stdout.toString().split('\n'); - result.manufacturer = util.getValue(lines, 'manufacturer'); - result.model = util.getValue(lines, 'product name'); + result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer')); + result.model = cleanDefaults(util.getValue(lines, 'product name')); result.version = cleanDefaults(util.getValue(lines, 'version')); result.serial = cleanDefaults(util.getValue(lines, 'serial number')); - result.uuid = cleanDefaults((util.getValue(lines, 'uuid').toLowerCase())); + result.uuid = cleanDefaults((util.getValue(lines, 'uuid'))).toLowerCase(); result.sku = cleanDefaults(util.getValue(lines, 'sku number')); // Non-Root values const cmd = `echo -n "product_name: "; cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null; echo;