From b773285d5efaa03f5ef536bb5472b7ce41b237d3 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Apr 2023 12:24:18 +0200 Subject: [PATCH] battery: Fix power rate checks for amount < 1W Fix the power rate check, energy_rate is a float, and abs() handles ints, so any rate under 1W would have been truncated to 0. --- src/up-device-battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/up-device-battery.c b/src/up-device-battery.c index 734b6a8..c814d9f 100644 --- a/src/up-device-battery.c +++ b/src/up-device-battery.c @@ -155,7 +155,7 @@ up_device_battery_estimate_power (UpDeviceBattery *self, UpBatteryValues *cur) */ if (cur->state == UP_DEVICE_STATE_UNKNOWN) { /* Consider a rate of 0.5W as "no change", otherwise set CHARGING/DISCHARGING */ - if (abs(energy_rate) < 0.5) + if (ABS(energy_rate) < 0.5) return; else if (energy_rate < 0.0) cur->state = UP_DEVICE_STATE_DISCHARGING;