supply: Avoid emitting notification for line power changes

Setting the property will create a notification, which in turn causes
the daemon code to trigger a battery refresh. As such, avoid actually
setting the property if it still has the same value.

Note that we shouldn't usually get spurious notifications, but it is
good to be safe here in case e.g. a bad firmware just sends out
notifications when the battery capacity changes.

Related: #184
This commit is contained in:
Benjamin Berg 2022-05-13 17:44:37 +02:00 committed by Benjamin Berg
parent 2d6080d253
commit 4cccf81cad

View file

@ -79,12 +79,20 @@ up_device_supply_refresh_line_power (UpDeviceSupply *supply,
{
UpDevice *device = UP_DEVICE (supply);
GUdevDevice *native;
gboolean online_old, online_new;
/* get new AC value */
native = G_UDEV_DEVICE (up_device_get_native (device));
g_object_set (device,
"online", g_udev_device_get_sysfs_attr_as_int_uncached (native, "online"),
g_object_get (device,
"online", &online_old,
NULL);
online_new = g_udev_device_get_sysfs_attr_as_int_uncached (native, "online");
/* Avoid notification if the value did not change. */
if (online_old != online_new)
g_object_set (device,
"online", online_new,
NULL);
return TRUE;
}