The code that handles battery information coming from the kernel didn't
have any code to set audio type of devices. As we add support for USB
wireless headsets in the kernel, add code to detect those and set the
UPDevice kind to the right value.
Closes: #229
up_device_battery_estimate_power() expects a charge/discharge rate of
0.5W to be significant, but the existing code yielded a rate of
-0.000240W.
Fix the units so that the amount of change in energy_now is at least
1W/s converted to µWh.
Now that device loop is fixed, we also need to fix the D-Bus object
path for the devices themselves to match what UPower generates so
we can get its properties.
As we iterate over the expected array, the elements are the basenames
of those object paths. Reconstruct the full object paths by prepending
/org/freedesktop/UPower/devices/
The test uses a generator to get the list of basenames for the devices:
names = (n.split('/')[-1] for n in devs)
Unfortunately, using that "names" varible will consume the generator,
and our array will be lost.
When passing a device dictionary, this code:
print(sorted(names))
print(sorted(names))
will yield:
['battery_hidpp_battery_0']
[]
Save the sorted array, and use that to test for properties equality.
When a kernel device appears after the Bluetooth device, we could be
trying to bind the model property onto itself on the Bluetooth device.
Avoid this possibility by always binding the property from the bluez
device to the non-bluez device.
GLib-GObject-WARNING **: 20:20:50.644: Unable to bind the same property on the same instance
Fixes: 778b93a336 ("linux: Hide duplicate Logitech Bluetooth devices")
Commit 1550d50f ("linux: Remove "usb" subsystem match") broke detection of
some idevices, since it left just the "usbmisc" subsystem match while some
idevice / kernel combinations (at least an iPhone 11 on a 6.0 kernel) don't
present any such udev usbmisc devices.
However, they do present "usb" subsystem ones, so add this match back.
Leave idevice detection also for the "usbmisc" match since that's what the
original (known working) code before aforementioned commit did - it is
possible that it is required for some kernel / idevice combinations.
up-enumerator-udev.c forgot to include the build config file, resulting in
HAVE_IDEVICE macro always being undefined.
This meant that the idevice backend was never actually instantiated - as
evidenced by the file not even compiling when this was fixed, due to
missing "up-device-idevice.h" include.
Fix both of these issues.
A lot of newer Logitech devices support both the BATT Bluetooth LE
service as well the HID++ protocol. This advertises 2 separate battery
interfaces, one HID++ one through the kernel, one BATT one through
BlueZ.
Avoid confusing UIs and hide the Bluetooth battery from the interface by
checking for duplicates each time a new device is added.
Closes: #166
Newer development versions of libgudev now strip the linefeeds by
themselves, so fix our naive linefeed-stripping which munched on the
last character of the string if there was no linefeed.
Could not find a percentage for capacity level 'Ful'
See https://gitlab.gnome.org/GNOME/libgudev/-/merge_requests/26
This fixes the serial number not being set on Bluetooth devices which
might not have a serial number but should always have a Bluetooth
address to differentiate them.
We were correctly handling an "Alias" property changing, but never
passed the property to that code as we were dropping anything that
wasn't a battery related update.
It seems that the test was still flaky, the reason for that would be
that we did not explicitly wait for the log line saying that the
aggregate state was calculated.
The only reason that it did not consistently fail appears to be that
searching for the state conflict caused messages to be skipped. That is
wrong, we should account for every "Calculating percentage" message to
ensure that upowerd and the test is in sync.
Assuming we have some estimation for the current battery capacity (i.e.
percentage), we can infer a FULL/EMPTY state. Do so if the battery state
is unknown.
Related: #196
This makes the switch. There are a few behaviour changes with regard to
estimations (which hopefully got both simpler and more robust at the
same time).
The state guessing code based on the AC state was not tested well.
Improve the test by testing both 1 and 2 batteries and checking the
reported state in more detail.
Using energy is broken as the value might be zero if it is not provided.
However, either energy or percentage ("capacity") should have been read
from the sysfs. And, in both cases the percentage should reflect
something reasonable.
Related: #146
The state aggregation test requires an idle handler to run, which can be
a bit unreliable as it may or may not run twice.
Force running it twice and add code to wait for it to complete. Do so
properly by waiting for the correct log messages rather than sleeping so
that everything is ordered nicely while not slowing down the test a lot.
Closes: #193
If we have an input node with both a keyboard and a mouse in one node,
then prefer the mouse. However, if we have separate mouse and keyboard
device nodes, prefer the keyboard.
Closes: #189
This adds a test that checks all possible inputs for the battery state
aggregation. Not all states are actually tested in this case, as some
states may be handled through state inference and others might not be
well defined.
Stop trying to guess a battery state based on the AC information for a
single battery. Instead, just do the guessing in the display device.
This means that cases with more than one battery work fine. It also
means that we still report an UNKNOWN state for the battery itself.
Also get the on_battery information from the display devices discharging
state, there is no need to iterate all of the batteries to figure that
out.
Note that we don't really have a well defined state for the display
device in all cases. We'll add a test in the next step, marking those
cases as TBD or ANY to show where the issues are. AFAICT we do not have
a regression though, so this should be fine for now.
Fixes: #146
The umockdev code to disable it by setting the variable does not
propagate through python. Set the variable here until there is a more
permament solution available.
This removes some code duplication between the linux and freebsd
backend. And, this file could become home to other small helper
functions in the future.
Using tearDown is brittle, as an assertion will stop it from running
through completely. So move cleanup into a helper that is called via
addCleanup for logind and bluez.