mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-20 17:10:03 +01:00
up-device-supply-battery: Explicitly define the battery energy/charge unit
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
This commit is contained in:
parent
dfde9e2274
commit
fe83277fbe
1 changed files with 7 additions and 6 deletions
|
|
@ -160,16 +160,17 @@ up_device_supply_battery_refresh (UpDevice *device,
|
||||||
info.voltage_design = up_device_supply_battery_get_design_voltage (self, native);
|
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.charge_cycles = g_udev_device_get_sysfs_attr_as_int_uncached (native, "cycle_count");
|
||||||
|
|
||||||
|
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.units = UP_BATTERY_UNIT_ENERGY;
|
||||||
info.energy.full = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full") / 1000000.0;
|
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;
|
info.energy.design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "energy_full_design") / 1000000.0;
|
||||||
|
} else {
|
||||||
/* Assume we couldn't read anything if energy.full is extremely small */
|
|
||||||
if (info.energy.full < 0.01) {
|
|
||||||
info.units = UP_BATTERY_UNIT_CHARGE;
|
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.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.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"));
|
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. */
|
/* NOTE: We used to warn about full > design, but really that is prefectly fine to happen. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue