summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-06-14 17:32:36 +0200
committerBenjamin Berg <bberg@redhat.com>2022-06-14 17:32:36 +0200
commit2a1ab444e80c034f0efb0a2dcfe8aa879507fb48 (patch)
tree64d1403cb963c7bdee25fc3779ed54f2ac04eb03
parentce2478716517df002175d0c4f57c057a0977ccb3 (diff)
daemon: Move state guessing after percentage calculation
Otherwise we may not have the percentage to work with, rendering the guessing useless. This also moves the time estimation down (after the state guessing) and does it unconditionally. This is, however, not an issue, as the calculation matches with other places. Related: #146
-rw-r--r--src/up-daemon.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/up-daemon.c b/src/up-daemon.c
index ad7fe60..74c6741 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -233,6 +233,24 @@ up_daemon_update_display_battery (UpDaemon *daemon)
num_batteries++;
}
+ /* Handle multiple batteries */
+ if (num_batteries <= 1)
+ goto out;
+
+ g_debug ("Calculating percentage and time to full/to empty for %i batteries", num_batteries);
+
+ /* use percentage weighted for each battery capacity
+ * fall back to averaging the batteries.
+ * ASSUMPTION: If one battery has energy data, then all batteries do
+ */
+ if (energy_full_total > 0.0)
+ percentage_total = 100.0 * energy_total / energy_full_total;
+ else
+ percentage_total = percentage_total / num_batteries;
+
+out:
+ g_ptr_array_unref (array);
+
/* No battery means LAST state. If we have an UNKNOWN state (with
* a battery) then try to infer one. */
if (state_total == UP_DEVICE_STATE_LAST) {
@@ -265,17 +283,8 @@ up_daemon_update_display_battery (UpDaemon *daemon)
}
}
- /* Handle multiple batteries */
- if (num_batteries <= 1)
- goto out;
-
- g_debug ("Calculating percentage and time to full/to empty for %i batteries", num_batteries);
-
- /* use percentage weighted for each battery capacity */
- if (energy_full_total > 0.0)
- percentage_total = 100.0 * energy_total / energy_full_total;
-
- /* calculate a quick and dirty time remaining value */
+ /* calculate a quick and dirty time remaining value
+ * NOTE: Keep in sync with per-battery estimation code! */
if (energy_rate_total > 0) {
if (state_total == UP_DEVICE_STATE_DISCHARGING)
time_to_empty_total = SECONDS_PER_HOUR * (energy_total / energy_rate_total);
@@ -283,9 +292,6 @@ up_daemon_update_display_battery (UpDaemon *daemon)
time_to_full_total = SECONDS_PER_HOUR * ((energy_full_total - energy_total) / energy_rate_total);
}
-out:
- g_ptr_array_unref (array);
-
/* Did anything change? */
if (daemon->priv->kind == kind_total &&
daemon->priv->state == state_total &&