mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-03 07:48:12 +02:00
Consider a discharging UPS as "on battery"
Implement get_{on,low}_battery() methods on HID devices for Linux. This will
treat discharging UPSes like batteries and set the "on-battery" and
"on-low-battery" properties accordingly.
This also fixes the test_ups_ac() case in the Linux integration tests.
This commit is contained in:
parent
a786d2fd16
commit
5cb1f4a9a3
1 changed files with 63 additions and 0 deletions
|
|
@ -434,6 +434,67 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_hid_get_on_battery:
|
||||
**/
|
||||
static gboolean
|
||||
up_device_hid_get_on_battery (UpDevice *device, gboolean *on_battery)
|
||||
{
|
||||
UpDeviceHid *hid = UP_DEVICE_HID (device);
|
||||
UpDeviceKind type;
|
||||
UpDeviceState state;
|
||||
gboolean is_present;
|
||||
g_return_val_if_fail (UP_IS_DEVICE_HID (hid), FALSE);
|
||||
g_return_val_if_fail (on_battery != NULL, FALSE);
|
||||
|
||||
g_object_get (device,
|
||||
"type", &type,
|
||||
"state", &state,
|
||||
"is-present", &is_present,
|
||||
NULL);
|
||||
|
||||
|
||||
if (type != UP_DEVICE_KIND_UPS)
|
||||
return FALSE;
|
||||
if (state == UP_DEVICE_STATE_UNKNOWN)
|
||||
return FALSE;
|
||||
if (!is_present)
|
||||
return FALSE;
|
||||
|
||||
*on_battery = (state == UP_DEVICE_STATE_DISCHARGING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_hid_get_low_battery:
|
||||
**/
|
||||
static gboolean
|
||||
up_device_hid_get_low_battery (UpDevice *device, gboolean *low_battery)
|
||||
{
|
||||
gboolean ret;
|
||||
gboolean on_battery;
|
||||
UpDeviceHid *hid = UP_DEVICE_HID (device);
|
||||
gdouble percentage;
|
||||
|
||||
g_return_val_if_fail (UP_IS_DEVICE_HID (hid), FALSE);
|
||||
g_return_val_if_fail (low_battery != NULL, FALSE);
|
||||
|
||||
/* reuse the common checks */
|
||||
ret = up_device_hid_get_on_battery (device, &on_battery);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
/* shortcut */
|
||||
if (!on_battery) {
|
||||
*low_battery = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_object_get (device, "percentage", &percentage, NULL);
|
||||
*low_battery = (percentage < 10.0f);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_hid_init:
|
||||
**/
|
||||
|
|
@ -482,6 +543,8 @@ up_device_hid_class_init (UpDeviceHidClass *klass)
|
|||
|
||||
object_class->finalize = up_device_hid_finalize;
|
||||
device_class->coldplug = up_device_hid_coldplug;
|
||||
device_class->get_on_battery = up_device_hid_get_on_battery;
|
||||
device_class->get_low_battery = up_device_hid_get_low_battery;
|
||||
device_class->refresh = up_device_hid_refresh;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (UpDeviceHidPrivate));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue