summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Hsuan <hpa@redhat.com>2023-11-20 16:41:18 +0800
committerKate Hsuan <hpa@redhat.com>2023-11-20 17:13:03 +0800
commitfe83277fbef85287e7a69b4dd9b141b84ddb1d65 (patch)
tree0fe049017fa9e0cd47d77379f9d9fe22362312f1
parentdfde9e2274d1c53d09bd2278cc41d72eacaabc1a (diff)
up-device-supply-battery: Explicitly define the battery energy/charge unitwip/kate/issue253
Before, if the energy.full is very small, the energy unit will be changed from engery_full to charge_full. Now, we explicitly choose one of them when the udev attribute is found. Fixes: https://gitlab.freedesktop.org/upower/upower/-/issues/253
-rw-r--r--src/linux/up-device-supply-battery.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/linux/up-device-supply-battery.c b/src/linux/up-device-supply-battery.c
index 456f692..c2f47ae 100644
--- a/src/linux/up-device-supply-battery.c
+++ b/src/linux/up-device-supply-battery.c
@@ -160,16 +160,17 @@ up_device_supply_battery_refresh (UpDevice *device,
info.voltage_design = up_device_supply_battery_get_design_voltage (self, native);
info.charge_cycles = g_udev_device_get_sysfs_attr_as_int_uncached (native, "cycle_count");
- info.units = UP_BATTERY_UNIT_ENERGY;
- info.energy.full = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full") / 1000000.0;
- info.energy.design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full_design") / 1000000.0;
-
- /* Assume we couldn't read anything if energy.full is extremely small */
- if (info.energy.full < 0.01) {
+ if (g_udev_device_has_sysfs_attr (native, "energy_full") &&
+ g_udev_device_has_sysfs_attr (native, "energy_full_design")) {
+ info.units = UP_BATTERY_UNIT_ENERGY;
+ info.energy.full = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full") / 1000000.0;
+ info.energy.design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full_design") / 1000000.0;
+ } else {
info.units = UP_BATTERY_UNIT_CHARGE;
info.energy.full = g_udev_device_get_sysfs_attr_as_double_uncached (native, "charge_full") / 1000000.0;
info.energy.design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "charge_full_design") / 1000000.0;
}
+
info.technology = up_convert_device_technology (get_sysfs_attr_uncached (native, "technology"));
/* NOTE: We used to warn about full > design, but really that is prefectly fine to happen. */