linux: up-device-supply-battery: read values of capacity_level and voltage_min/max

For Linux systems that provide these attributes, extend the implementation by
reading the values for the design maximum and minimum voltage for the battery,
as well as the coarse capacity level reported by the kernel.

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
This commit is contained in:
Sicelo A. Mhlongo 2025-03-30 20:08:06 +02:00 committed by Kate Hsuan
parent 1decdd53f4
commit c4b32387b0

View file

@ -198,6 +198,7 @@ up_device_supply_battery_refresh (UpDevice *device,
g_autofree gchar *model = NULL;
g_autofree gchar *serial = NULL;
g_autofree gchar *technology = NULL;
g_autofree gchar *capacity_level = NULL;
native = G_UDEV_DEVICE (up_device_get_native (device));
@ -239,6 +240,9 @@ up_device_supply_battery_refresh (UpDevice *device,
technology = get_sysfs_attr_uncached (native, "technology");
info.technology = up_convert_device_technology (technology);
info.voltage_max_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_max_design") / 1000000.0;
info.voltage_min_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_min_design") / 1000000.0;
if (up_device_supply_battery_get_charge_control_limits (native, &info)) {
info.charge_control_supported = TRUE;
info.charge_control_enabled = FALSE;
@ -261,6 +265,8 @@ up_device_supply_battery_refresh (UpDevice *device,
if (values.voltage < 0.01)
values.voltage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_avg") / 1000000.0;
capacity_level = up_make_safe_string (get_sysfs_attr_uncached (native, "capacity_level"));
values.capacity_level = capacity_level;
switch (values.units) {
case UP_BATTERY_UNIT_CHARGE: