up-device: a filter to ignore the unknown status from the devices

Ignore all the unknown events from the devices.
This commit is contained in:
Kate Hsuan 2024-02-26 17:10:26 +08:00
parent ab50a2bb3e
commit 76e2b9e571

View file

@ -183,6 +183,19 @@ ensure_history (UpDevice *device)
up_history_set_id (priv->history, id);
}
static gboolean
up_device_history_filter (UpDevice *device, UpHistory *history)
{
UpExportedDevice *skeleton = UP_EXPORTED_DEVICE (device);
if (up_exported_device_get_state (skeleton) == UP_DEVICE_STATE_UNKNOWN) {
g_debug ("device %s has unknown state, not saving history",
up_exported_device_get_native_path (skeleton));
return FALSE;
}
return TRUE;
}
static void
update_history (UpDevice *device)
{
@ -191,6 +204,9 @@ update_history (UpDevice *device)
ensure_history (device);
if (!up_device_history_filter (device, priv->history))
return;
/* save new history */
up_history_set_state (priv->history, up_exported_device_get_state (skeleton));
up_history_set_charge_data (priv->history, up_exported_device_get_percentage (skeleton));