From 232db036b596f4d8bbb71cfb6026baa9b9ce4a6d Mon Sep 17 00:00:00 2001 From: Paul Ragot Date: Sat, 12 Jul 2025 00:08:25 +0200 Subject: [PATCH] fix: correct battery discharge time calculation --- sensors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sensors.js b/sensors.js index fa49d41..c4c1160 100644 --- a/sensors.js +++ b/sensors.js @@ -455,7 +455,7 @@ export const Sensors = GObject.registerClass({ this._returnValue(callback, 'Energy (now)', output['ENERGY_NOW'], 'battery', 'watt-hour'); } - 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')) { + 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')) { let timeLeft = 0; @@ -463,7 +463,7 @@ export const Sensors = GObject.registerClass({ if (output['STATUS'] == 'Charging') { timeLeft = ((output['ENERGY_FULL'] - output['ENERGY_NOW']) / output['POWER_NOW']); } else { - timeLeft = (output['ENERGY_NOW'] / output['POWER_NOW']); + timeLeft = (output['ENERGY_NOW'] / Math.abs(output['POWER_NOW'])); } // don't process Infinity values @@ -644,7 +644,7 @@ export const Sensors = GObject.registerClass({ if(vendor === "0x1002") { // read GPU usage and create group lebel for card new FileModule.File('/sys/class/drm/card'+i+'/device/gpu_busy_percent').read().then(value => { - // create group + // create group this._returnGpuValue(callback, 'Graphics', parseInt(value) * 0.01, typeName + '-group', 'percent'); this._returnGpuValue(callback, 'Vendor', "AMD", typeName, 'string'); this._returnGpuValue(callback, 'Usage', parseInt(value) * 0.01, typeName, 'percent');