battery() added designcapacity, voltage, unit
This commit is contained in:
+22
-10
@@ -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);
|
||||
|
||||
Vendored
+3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user