battery() added designcapacity, voltage, unit

This commit is contained in:
Sebastian Hildebrandt 2020-01-25 22:39:36 +01:00
parent afa594e8c0
commit 52ad8d5cf5
7 changed files with 71 additions and 31 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.20.0 | 2020-01-25 | `battery()` added designcapacity, voltage, unit |
| 4.19.4 | 2020-01-24 | `mem()` prevent log messages, `memgetDefaultNetworkInterface()` catch errors |
| 4.19.3 | 2020-01-24 | `memLayout()` bank info fix macOS |
| 4.19.2 | 2020-01-19 | `cpu()` muli-processor fix windows |

View File

@ -29,20 +29,6 @@
[![Caretaker][caretaker-image]][caretaker-url]
[![MIT license][license-img]][license-url]
#### Happy new year
```
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.''.: /\ : ./)\ ':'* /\ * : '..'. -=:o:=-
:_\/_:'.:::. ' *''* * '.\'/.' _\(/_'.':'.'
: /\ : ::::: *_\/_* -= o =- /)\ ' *
'..' ':::' * /\ * .'/.\'. '
* *..* :
*
```
This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 250 versions published, up to 1 mio downloads per month, > 4 mio downloads overall. Thank you to all who contributed to this project!
## New Version 4.0
@ -98,13 +84,13 @@ si.cpu()
(last 7 major and minor version releases)
- Version 4.20.0: `battery()` added designcapacity, voltage, unit
- Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup)
- Version 4.18.0: `networkInterfaces()` added dhcp for mac os, added dhcp linux fallback
- Version 4.17.0: `networkInterfaces()` added dhcp, dnsSuffix, ieee8021xAuth, ieee8021xState
- Version 4.16.0: `networkGatewayDefault()` added
- Version 4.15.0: `cpu()` added governor (linux)
- Version 4.14.0: `processes()` added process path and params
- Version 4.13.0: `networkConnections()` added PID, process
- ...
You can find all changes here: [detailed changelog][changelog-url]
@ -246,8 +232,11 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | hasbattery | X | X | X | X | | indicates presence of battery |
| | cyclecount | X | | X | | | numbers of recharges |
| | ischarging | X | X | X | X | | indicates if battery is charging |
| | maxcapacity | X | | X | X | | max capacity of battery |
| | currentcapacity | X | | X | X | | current capacity of battery |
| | designedcapacity | X | | X | X | | max capacity of battery (mWh) |
| | maxcapacity | X | | X | X | | max capacity of battery (mWh) |
| | currentcapacity | X | | X | X | | current capacity of battery (mWh) |
| | capacityUnit | X | | X | X | | capacity unit (mWh) |
| | voltage | X | | X | X | | current voltage of battery (V) |
| | percent | X | X | X | X | | charging level in percent |
| | timeremaining | X | | X | | | minutes left (if discharging) |
| | acconnected | X | X | X | X | | AC connected |

View File

@ -105,6 +105,16 @@
<td></td>
<td>indicates if battery is charging</td>
</tr>
<tr>
<td></td>
<td>designedcapacity</td>
<td>X</td>
<td></td>
<td>X</td>
<td>X</td>
<td></td>
<td>designed capacity of battery (mWh)</td>
</tr>
<tr>
<td></td>
<td>maxcapacity</td>
@ -113,7 +123,7 @@
<td>X</td>
<td>X</td>
<td></td>
<td>max capacity of battery</td>
<td>max capacity of battery (mWh)</td>
</tr>
<tr>
<td></td>
@ -123,7 +133,27 @@
<td>X</td>
<td>X</td>
<td></td>
<td>current capacity of battery</td>
<td>current capacity of battery (mWh)</td>
</tr>
<tr>
<td></td>
<td>capacityUnit</td>
<td>X</td>
<td></td>
<td>X</td>
<td>X</td>
<td></td>
<td>capacity unit (mWh)</td>
</tr>
<tr>
<td></td>
<td>voltage</td>
<td>X</td>
<td></td>
<td>X</td>
<td>X</td>
<td></td>
<td>current voltage of battery (V)</td>
</tr>
<tr>
<td></td>

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.20.0</th>
<td>2020-01-25</td>
<td><span class="code">battery()</span> added designcapacity, voltage, unit</td>
</tr>
<tr>
<th scope="row">4.19.4</th>
<td>2020-01-24</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.19.4</span></div>
<div class="version">Current Version: <span id="version">4.20.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">
@ -206,7 +206,7 @@
<div class="title">Downloads last month</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">236</div>
<div class="numbers">239</div>
<div class="title">Dependends</div>
</div>
</div>

View File

@ -35,8 +35,11 @@ module.exports = function (callback) {
hasbattery: false,
cyclecount: 0,
ischarging: false,
designedcapacity: 0,
maxcapacity: 0,
currentcapacity: 0,
voltage: 0,
capacityUnit: '',
percent: 0,
timeremaining: -1,
acconnected: true,
@ -60,14 +63,16 @@ module.exports = function (callback) {
result.ischarging = (util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging');
result.acconnected = result.ischarging;
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
result.cyclecount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10);
result.maxcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10) / 1000.0 / (result.voltage || 1) * 100) / 100;
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 / (result.voltage || 1) * 100) / 100| result.maxcapacity;
result.currentcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 / (result.voltage || 1) * 100) / 100;
result.capacityUnit = 'mWh';
if (!result.maxcapacity) {
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10);
}
result.currentcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10);
if (!result.currentcapacity) {
result.currentcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10) / 1000.0;
result.designcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '='), 10) / 1000.0 | result.maxcapacity;
result.currentcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
}
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
@ -113,6 +118,7 @@ module.exports = function (callback) {
result.acconnected = result.ischarging;
result.maxcapacity = -1;
result.currentcapacity = -1;
result.capacityUnit = 'unknown';
result.percent = batteries ? percent : -1;
if (callback) { callback(result); }
resolve(result);
@ -120,12 +126,15 @@ module.exports = function (callback) {
}
if (_darwin) {
exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining"; pmset -g batt | grep %', function (error, stdout) {
exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|BatterySerialNumber|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);
result.maxcapacity = parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10);
result.currentcapacity = parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10);
result.capacityUnit = 'mWh';
result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
result.maxcapacity = Math.round(parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10) * (result.voltage || 1) * 100) / 100;
result.currentcapacity = Math.round(parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10) * (result.voltage || 1) * 100) / 100;
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1) * 100) / 100;
result.manufacturer = 'Apple';
result.serial = util.getValue(lines, 'BatterySerialNumber', '=');
let percent = -1;
@ -163,7 +172,7 @@ module.exports = function (callback) {
}
if (_windows) {
try {
util.wmic('Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value').then((stdout) => {
util.wmic('Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining, DesignVoltage, FullChargeCapacity /value').then((stdout) => {
if (stdout) {
let lines = stdout.split('\r\n');
let status = util.getValue(lines, 'BatteryStatus', '=').trim();
@ -182,6 +191,9 @@ module.exports = function (callback) {
const statusValue = parseInt(status);
result.hasbattery = true;
result.maxcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0);
result.designcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0);
result.voltage = parseInt(util.getValue(lines, 'DesignVoltage', '=') || 0) / 1000.0;
result.capacityUnit = 'mWh';
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100);
result.ischarging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (!(statusValue === 3) && !(statusValue === 1) && result.percent < 100);

3
lib/index.d.ts vendored
View File

@ -146,8 +146,11 @@ export namespace Systeminformation {
hasbattery: boolean;
cyclecount: number;
ischarging: boolean;
voltage: number;
designedcapacity: number;
maxcapacity: number;
currentcapacity: number;
capacityUnit: string;
percent: number;
timeremaining: number,
acconnected: boolean;