summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-06-02 18:29:50 +0200
committerBenjamin Berg <bberg@redhat.com>2022-06-03 10:36:02 +0200
commit792fc7bb1bd4c7bf4b779106329aa4487bfa0386 (patch)
tree5c572b1c631d50d5e8acaae92759b38a07adc906
parent7ed8d0e9ef0a79fcb3f6fe43cc7b6d1385a03d1b (diff)
downloadupower-792fc7bb1bd4c7bf4b779106329aa4487bfa0386.tar.gz
supply: Consistently use 90% threshold to consider a battery full
-rwxr-xr-xsrc/linux/integration-test.py4
-rw-r--r--src/linux/up-device-supply.c6
-rw-r--r--src/up-constants.h1
3 files changed, 5 insertions, 6 deletions
diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py
index 3185b03..4d9be50 100755
--- a/src/linux/integration-test.py
+++ b/src/linux/integration-test.py
@@ -677,8 +677,8 @@ class Tests(dbusmock.DBusTestCase):
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_FULLY_CHARGED)
self.stop_daemon()
- # and make sure we still return pending-charge below 100%
- self.testbed.set_attribute(bat0, 'capacity', '99')
+ # and make sure we still return pending-charge below the threshold
+ self.testbed.set_attribute(bat0, 'capacity', '89')
self.start_daemon()
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_PENDING_CHARGE)
self.stop_daemon()
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 39907d0..5e6a6a8 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -42,8 +42,6 @@ enum {
PROP_IGNORE_SYSTEM_PERCENTAGE
};
-#define UP_DEVICE_SUPPLY_CHARGED_THRESHOLD 90.0f /* % */
-
#define UP_DEVICE_SUPPLY_COLDPLUG_UNITS_CHARGE TRUE
#define UP_DEVICE_SUPPLY_COLDPLUG_UNITS_ENERGY FALSE
@@ -706,7 +704,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
/* Some devices report "Not charging" when the battery is full and AC
* power is connected. In this situation we should report fully-charged
* instead of pending-charge. */
- if (state == UP_DEVICE_STATE_PENDING_CHARGE && percentage == 100.0)
+ if (state == UP_DEVICE_STATE_PENDING_CHARGE && percentage >= UP_FULLY_CHARGED_THRESHOLD)
state = UP_DEVICE_STATE_FULLY_CHARGED;
/* the battery isn't charging or discharging, it's just
@@ -732,7 +730,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
if (has_ac) {
if (ac_online) {
- if (percentage > UP_DEVICE_SUPPLY_CHARGED_THRESHOLD)
+ if (percentage > UP_FULLY_CHARGED_THRESHOLD)
state = UP_DEVICE_STATE_FULLY_CHARGED;
else
state = UP_DEVICE_STATE_CHARGING;
diff --git a/src/up-constants.h b/src/up-constants.h
index b4d3522..33324c5 100644
--- a/src/up-constants.h
+++ b/src/up-constants.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
#define UP_DAEMON_SHORT_TIMEOUT 30 /* seconds */
#define UP_DAEMON_LONG_TIMEOUT 120 /* seconds */
+#define UP_FULLY_CHARGED_THRESHOLD 90 /* % */
#define UP_DAEMON_EPSILON 0.01 /* I can't believe it's not zero */
#define SECONDS_PER_HOUR 3600 /* seconds in an hour */