Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth Connection sensor incorrectly assumes connected devices are not paired #2736

Closed
jpelgrom opened this issue Jul 30, 2022 · 4 comments · Fixed by #2738
Closed

Bluetooth Connection sensor incorrectly assumes connected devices are not paired #2736

jpelgrom opened this issue Jul 30, 2022 · 4 comments · Fixed by #2738
Labels
bug Something isn't working sensor-tracking

Comments

@jpelgrom
Copy link
Member

Home Assistant Android version: 2022.6.0-full, beta-2534-90a9a27e-full

Android version: 13

Phone model: Pixel 4a

Home Assistant version: not relevant

Last working Home Assistant release (if known): looking at the history of BluetoothUtils, it has always been broken

Description of problem: Discovered while reviewing a PR: paired devices that are connected via GATT will show up both in connected_paired_devices and connected_not_paired_devices because for connected_not_paired_devices it actually isn't checked if the device is paired or not:

val btConnectedDevices = bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)

BluetoothDevice(
btDev.address,
name,
false,
isConnected(btDev)
)

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):

n/a

Screenshot of problem:

App settings showing sensor attributes, with one device showing up in both connected_paired_devices and connected_not_paired_devices

(the device addresses are the same, just blacked out for privacy)

Additional information: After adding debug logging into the app to check the bondState of the device, it shows up as BOND_BONDED in both cases. This makes sense because they share the same hardware address and the developer documentation says that it is: "(...) a thin wrapper for a Bluetooth hardware address".

@jpelgrom jpelgrom added the bug Something isn't working label Jul 30, 2022
@dshokouhi
Copy link
Member

After adding debug logging into the app to check the bondState of the device, it shows up as BOND_BONDED in both cases.

ran a test myself on my Mi Band 7, still shows up as unpaired if we check the bondState instead of assuming its false

@jpelgrom
Copy link
Member Author

ran a test myself on my Mi Band 7, still shows up as unpaired if we check the bondState instead of assuming its false

Hmm, does the bondState also show as not paired if you replace the assumed true in the list of paired devices?

I used the following check to determine if the device is paired: btDev.bondState == android.bluetooth.BluetoothDevice.BOND_BONDED

@dshokouhi
Copy link
Member

Hmm, does the bondState also show as not paired if you replace the assumed true in the list of paired devices?

I decided not to test that originally only because we are getting the first list from bondedDevices 😂

Ran a test now and don't see any differences, although I wouldn't expect to only because of the method used to get the list

I used the following check to determine if the device is paired: btDev.bondState == android.bluetooth.BluetoothDevice.BOND_BONDED

That was exactly what I used in my testing, but only for getConnectedDevices() as that can contain devices not paired

@jpelgrom
Copy link
Member Author

I decided not to test that originally only because we are getting the first list from bondedDevices 😂

In getConnectedDevices it is also still checking if the device is actually connected instead of assuming it.

Ran a test now and don't see any differences

This puzzles me but might be a device-specific issue, or at least not in the scope of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sensor-tracking
Projects
None yet
2 participants