src: up-daemon: skip the battery if present = 0

If the battery is not present, skip it when estimating the battery
percentage.

Resolves: #292
This commit is contained in:
Kate Hsuan 2024-12-19 14:28:44 +08:00
parent eb5a327127
commit 6bd8cd90b3

View file

@ -156,6 +156,7 @@ up_daemon_update_display_battery (UpDaemon *daemon)
UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
gboolean present = FALSE;
gdouble percentage = 0.0;
gdouble energy = 0.0;
gdouble energy_full = 0.0;
@ -166,6 +167,7 @@ up_daemon_update_display_battery (UpDaemon *daemon)
device = g_ptr_array_index (array, i);
g_object_get (device,
"is-present", &present,
"type", &kind,
"state", &state,
"percentage", &percentage,
@ -177,6 +179,9 @@ up_daemon_update_display_battery (UpDaemon *daemon)
"power-supply", &power_supply,
NULL);
if (!present)
continue;
/* When we have a UPS, it's either a desktop, and
* has no batteries, or a laptop, in which case we
* ignore the batteries */