From 8dad45b5fa99f82ef284c3c885459f9e7c918e9c Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 21 Nov 2018 22:59:40 +0100 Subject: [PATCH] battery() timeremaining optimization (linux) --- CHANGELOG.md | 1 + README.md | 1 + lib/battery.js | 3 +++ 3 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b252a9..bebd98c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.49.4 | 2018-11-21 | `battery()` timeremaining optimization (linux) thanks to Jorai Rijsdijk | | 3.49.3 | 2018-11-20 | `memLayout()` optimized parsing (win) | | 3.49.2 | 2018-11-19 | code cleanup | | 3.49.1 | 2018-11-19 | `cpu().brand` removed extra spaces, tabs | diff --git a/README.md b/README.md index e170292..f10b2d8 100644 --- a/README.md +++ b/README.md @@ -586,6 +586,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra - Jimi M [ItsJimi](https://github.com/ItsJimi) - Git² [GitSquared](https://github.com/GitSquared) - weiyin [weiyin](https://github.com/weiyin) +- Jorai Rijsdijk [Erackron](https://github.com/Erackron) OSX Temperature: credits here are going to: diff --git a/lib/battery.js b/lib/battery.js index 2af4c68..2a8a583 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -70,6 +70,7 @@ module.exports = function (callback) { const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '='); const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10); const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10); + const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10); result.percent = parseInt('0' + percent, 10); if (result.maxcapacity && result.currentcapacity) { @@ -83,6 +84,8 @@ module.exports = function (callback) { } if (energy && power) { result.timeremaining = Math.floor(energy / power * 60); + } else if (current && result.currentcapacity) { + result.timeremaining = Math.floor(result.currentcapacity / current * 60); } result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '='); result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');