mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-05 22:48:04 +02:00
bugfix: use 0 for unknown, not -1 as some values like rate and voltage are valid when negative
This commit is contained in:
parent
eded5b20fc
commit
885c3e4748
4 changed files with 22 additions and 22 deletions
|
|
@ -36,15 +36,15 @@ dkp_object_clear_internal (DkpObject *obj)
|
|||
{
|
||||
obj->type = DKP_DEVICE_TYPE_UNKNOWN;
|
||||
obj->update_time = 0;
|
||||
obj->energy = -1;
|
||||
obj->energy_full = -1;
|
||||
obj->energy_full_design = -1;
|
||||
obj->energy_rate = -1;
|
||||
obj->voltage = -1;
|
||||
obj->percentage = -1;
|
||||
obj->capacity = -1;
|
||||
obj->time_to_empty = -1;
|
||||
obj->time_to_full = -1;
|
||||
obj->energy = 0;
|
||||
obj->energy_full = 0;
|
||||
obj->energy_full_design = 0;
|
||||
obj->energy_rate = 0;
|
||||
obj->voltage = 0;
|
||||
obj->percentage = 0;
|
||||
obj->capacity = 0;
|
||||
obj->time_to_empty = 0;
|
||||
obj->time_to_full = 0;
|
||||
obj->state = DKP_DEVICE_STATE_UNKNOWN;
|
||||
obj->technology = DKP_DEVICE_TECHNOLGY_UNKNOWN;
|
||||
obj->vendor = NULL;
|
||||
|
|
|
|||
|
|
@ -792,15 +792,15 @@ dkp_device_class_init (DkpDeviceClass *klass)
|
|||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_TIME_TO_EMPTY,
|
||||
g_param_spec_int64 ("time-to-empty", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
|
||||
g_param_spec_int64 ("time-to-empty", NULL, NULL, 0, G_MAXINT64, 0, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_TIME_TO_FULL,
|
||||
g_param_spec_int64 ("time-to-full", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
|
||||
g_param_spec_int64 ("time-to-full", NULL, NULL, 0, G_MAXINT64, 0, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_PERCENTAGE,
|
||||
g_param_spec_double ("percentage", NULL, NULL, -1, 100, -1, G_PARAM_READABLE));
|
||||
g_param_spec_double ("percentage", NULL, NULL, 0, 100, 0, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_TECHNOLOGY,
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ dkp_supply_reset_values (DkpSupply *supply)
|
|||
native_path = g_strdup (obj->native_path);
|
||||
|
||||
supply->priv->has_coldplug_values = FALSE;
|
||||
supply->priv->energy_old = -1;
|
||||
supply->priv->energy_old = 0;
|
||||
supply->priv->energy_old_timespec.tv_sec = 0;
|
||||
dkp_object_clear (obj);
|
||||
|
||||
|
|
@ -320,11 +320,11 @@ dkp_supply_refresh_battery (DkpSupply *supply)
|
|||
* to calculate the true rate. We should set the rate zero, and wait
|
||||
* for the BIOS to stabilise. */
|
||||
if (obj->energy_rate == 0xffff)
|
||||
obj->energy_rate = -1;
|
||||
obj->energy_rate = 0;
|
||||
|
||||
/* sanity check to less than 100W */
|
||||
if (obj->energy_rate > 100*1000)
|
||||
obj->energy_rate = -1;
|
||||
obj->energy_rate = 0;
|
||||
|
||||
/* the hardware reporting failed -- try to calculate this */
|
||||
if (obj->energy_rate < 0) {
|
||||
|
|
@ -339,8 +339,8 @@ dkp_supply_refresh_battery (DkpSupply *supply)
|
|||
obj->percentage = 100.0;
|
||||
|
||||
/* calculate a quick and dirty time remaining value */
|
||||
obj->time_to_empty = -1;
|
||||
obj->time_to_full = -1;
|
||||
obj->time_to_empty = 0;
|
||||
obj->time_to_full = 0;
|
||||
if (obj->energy_rate > 0) {
|
||||
if (state == DKP_DEVICE_STATE_DISCHARGING) {
|
||||
obj->time_to_empty = 3600 * (obj->energy / obj->energy_rate);
|
||||
|
|
@ -351,9 +351,9 @@ dkp_supply_refresh_battery (DkpSupply *supply)
|
|||
/* check the remaining time is under a set limit, to deal with broken
|
||||
primary batteries rate */
|
||||
if (obj->time_to_empty > (100 * 60 * 60))
|
||||
obj->time_to_empty = -1;
|
||||
obj->time_to_empty = 0;
|
||||
if (obj->time_to_full > (100 * 60 * 60))
|
||||
obj->time_to_full = -1;
|
||||
obj->time_to_full = 0;
|
||||
|
||||
/* set the old status */
|
||||
supply->priv->energy_old = obj->energy;
|
||||
|
|
@ -361,7 +361,7 @@ dkp_supply_refresh_battery (DkpSupply *supply)
|
|||
|
||||
/* we changed state */
|
||||
if (obj->state != state) {
|
||||
supply->priv->energy_old = -1;
|
||||
supply->priv->energy_old = 0;
|
||||
obj->state = state;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@
|
|||
<property name="time-to-empty" type="x" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
Number of seconds until the power source is considered empty.
|
||||
Is set to -1 if unknown.
|
||||
Is set to 0 if unknown.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:type">type</doc:ref>
|
||||
|
|
@ -279,7 +279,7 @@
|
|||
<property name="time-to-full" type="x" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
Number of seconds until the power source is considered full.
|
||||
Is set to -1 if unknown.
|
||||
Is set to 0 if unknown.
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:type">type</doc:ref>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue