diff --git a/CHANGELOG.md b/CHANGELOG.md index 414f999..9ae5c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.38.0 | 2018-04-06 | added `battery().acconnected` | | 3.37.12 | 2018-04-05 | another optimization `battery().ischarging` for macOS | | 3.37.11 | 2018-04-05 | another optimization `battery().ischarging` for macOS | | 3.37.10 | 2018-04-05 | `battery().ischarging` optimized for macOS | diff --git a/README.md b/README.md index 6973848..4986110 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ async function cpu() { ### Latest Activity (last 7 major and minor version releases) +- Version 3.38.0: added `battery.acconnected` - Version 3.37.0: extended FreeBSD support `networkStats()` - Version 3.36.0: extended FreeBSD support `networkConnections()` - Version 3.35.0: extended FreeBSD support `processLoad()` - Version 3.34.0: first partial FreeBSD support - Version 3.33.0: added bios `bios()` and main board `baseboard()` information - Version 3.32.0: extended `memLayout()` - added manufacturer -- Version 3.31.0: extended windows support `cpuFlags()` (partially) - ... You can find all changes here: [detailed changelog][changelog-url] @@ -196,6 +196,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | maxcapacity | X | | X | X | max capacity of battery | | | currentcapacity | X | | X | X | current capacity of battery | | | percent | X | X | X | X | charging level in percent | +| | acconnected | X | X | X | X | AC connected | | si.graphics(cb) | {...} | X | | X | X | arrays of graphics controllers and displays | | | controllers[]| X | | X | X | graphics controllers array | | | ...[0].model | X | | X | X | graphics controller model | diff --git a/lib/battery.js b/lib/battery.js index 0d245a8..66049c3 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -38,7 +38,8 @@ module.exports = function (callback) { ischarging: false, maxcapacity: 0, currentcapacity: 0, - percent: 0 + percent: 0, + acconnected: true }; if (_linux) { @@ -53,6 +54,7 @@ module.exports = function (callback) { if (!error) { let lines = stdout.toString().split('\n'); if (lines.length > 0 && lines[0]) result.ischarging = (lines[0].trim().toLowerCase() === 'charging'); + result.acconnected = result.ischarging; } exec('cat ' + battery_path + 'cyclec_ount', function (error, stdout) { if (!error) { @@ -92,6 +94,7 @@ module.exports = function (callback) { result.hasbattery = (batteries > 0); result.cyclecount = -1; result.ischarging = util.getValue(lines, 'hw.acpi.acline') !== '1'; + result.acconnected = result.ischarging; result.maxcapacity = -1; result.currentcapacity = -1; result.percent = batteries ? percent : -1; @@ -117,9 +120,11 @@ module.exports = function (callback) { } } if (parts && parts[1]) { - result.ischarging = !(parts[1].trim() === 'charged' || parts[1].trim() === 'discharging'); + result.ischarging = (parts[1].trim() === 'charging'); + result.acconnected = (parts[1].trim() !== 'discharging'); } else { result.ischarging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes'; + result.acconnected = result.ischarging; } if (result.maxcapacity && result.currentcapacity) { result.hasbattery = true; @@ -142,6 +147,7 @@ module.exports = function (callback) { 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.acconnected = result.ischarging; } } if (callback) { callback(result); }