Skip to content

Commit 81fe8b9

Browse files
authored
Merge pull request #490 from ragotpaul/fix-negative-power
Fix negative voltage value when discharging, preventing battery time estimation
2 parents 66b99a7 + 232db03 commit 81fe8b9

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

sensors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,15 @@ export const Sensors = GObject.registerClass({
455455
this._returnValue(callback, 'Energy (now)', output['ENERGY_NOW'], 'battery', 'watt-hour');
456456
}
457457

458-
if ('ENERGY_FULL' in output && 'ENERGY_NOW' in output && 'POWER_NOW' in output && output['POWER_NOW'] > 0 && 'STATUS' in output && (output['STATUS'] == 'Charging' || output['STATUS'] == 'Discharging')) {
458+
if ('ENERGY_FULL' in output && 'ENERGY_NOW' in output && 'POWER_NOW' in output && output['POWER_NOW'] !== 0 && 'STATUS' in output && (output['STATUS'] == 'Charging' || output['STATUS'] == 'Discharging')) {
459459

460460
let timeLeft = 0;
461461

462462
// two different formulas depending on if we are charging or discharging
463463
if (output['STATUS'] == 'Charging') {
464464
timeLeft = ((output['ENERGY_FULL'] - output['ENERGY_NOW']) / output['POWER_NOW']);
465465
} else {
466-
timeLeft = (output['ENERGY_NOW'] / output['POWER_NOW']);
466+
timeLeft = (output['ENERGY_NOW'] / Math.abs(output['POWER_NOW']));
467467
}
468468

469469
// don't process Infinity values
@@ -644,7 +644,7 @@ export const Sensors = GObject.registerClass({
644644
if(vendor === "0x1002") {
645645
// read GPU usage and create group lebel for card
646646
new FileModule.File('/sys/class/drm/card'+i+'/device/gpu_busy_percent').read().then(value => {
647-
// create group
647+
// create group
648648
this._returnGpuValue(callback, 'Graphics', parseInt(value) * 0.01, typeName + '-group', 'percent');
649649
this._returnGpuValue(callback, 'Vendor', "AMD", typeName, 'string');
650650
this._returnGpuValue(callback, 'Usage', parseInt(value) * 0.01, typeName, 'percent');

0 commit comments

Comments
 (0)