linux: up-device-supply-battery: Don't mark fully charged batteries as discharging

This commit addresses the changes from commit d7ff457784
by excluding fully charged batteries even if their current_now is
negative.
This commit is contained in:
initramfs 2025-04-09 14:37:26 +00:00
parent a86d2d059c
commit ebcefcea55
No known key found for this signature in database
GPG key ID: 0BF5E22B0D6B4C3B

View file

@ -304,11 +304,12 @@ up_device_supply_battery_refresh (UpDevice *device,
/* For some battery solutions, for example axp20x-battery, the kernel reports
* status = charging but the battery actually discharges when connecting a
* charger. Upower reports the battery is "discharging" when current_now is
* found and is a negative value.*/
if (g_udev_device_get_sysfs_attr_as_double_uncached (native, "current_now") < 0.0)
* found and is a negative value as long as the battery isn't fully charged.*/
values.state = up_device_supply_get_state (native);
if (values.state != UP_DEVICE_STATE_FULLY_CHARGED &&
g_udev_device_get_sysfs_attr_as_double_uncached (native, "current_now") < 0.0)
values.state = UP_DEVICE_STATE_DISCHARGING;
else
values.state = up_device_supply_get_state (native);
values.temperature = g_udev_device_get_sysfs_attr_as_double_uncached (native, "temp") / 10.0;