Skip to content

backends/bluez: don't disconnect devices we did not connect#1984

Open
Vodur wants to merge 1 commit intohbldh:developfrom
Vodur:bluez-keep-connected
Open

backends/bluez: don't disconnect devices we did not connect#1984
Vodur wants to merge 1 commit intohbldh:developfrom
Vodur:bluez-keep-connected

Conversation

@Vodur
Copy link
Copy Markdown
Contributor

@Vodur Vodur commented May 6, 2026

BleakClientBlueZDBus.disconnect() now only calls BlueZ Disconnect when this client initiated the connection. The decision is based on a from_connected_devices marker that BleakAdapterBlueZDBus.get_connected_devices() sets on each returned BLEDevice.

If a device is found already connected at connect() time and the user did not opt into the existing connection (no marker), the client still owns the connection so it can clean up an orphan from a crashed previous run. Only when the BLEDevice was retrieved via BleakAdapter.get_connected_devices() does the new client leave the connection up on close.

See bluez/bluez#89.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.30%. Comparing base (8ba2718) to head (75708ed).

Files with missing lines Patch % Lines
bleak/backends/bluezdbus/client.py 88.23% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1984      +/-   ##
===========================================
+ Coverage    52.06%   52.30%   +0.23%     
===========================================
  Files           43       43              
  Lines         4091     4103      +12     
  Branches       503      505       +2     
===========================================
+ Hits          2130     2146      +16     
+ Misses        1830     1828       -2     
+ Partials       131      129       -2     
Flag Coverage Δ
bluez-integration-py3.10 39.02% <88.88%> (+0.27%) ⬆️
bluez-integration-py3.11 39.02% <88.88%> (+0.27%) ⬆️
bluez-integration-py3.12 39.02% <88.88%> (+0.27%) ⬆️
bluez-integration-py3.13 39.02% <88.88%> (+0.27%) ⬆️
bluez-integration-py3.14 37.51% <88.88%> (+0.28%) ⬆️
macos-latest-py3.10 20.00% <0.00%> (-0.06%) ⬇️
macos-latest-py3.11 20.00% <0.00%> (-0.06%) ⬇️
macos-latest-py3.12 20.00% <0.00%> (-0.06%) ⬇️
macos-latest-py3.13 20.00% <0.00%> (-0.06%) ⬇️
macos-latest-py3.14 19.82% <0.00%> (-0.06%) ⬇️
ubuntu-latest-py3.10 23.93% <11.11%> (-0.03%) ⬇️
ubuntu-latest-py3.11 23.93% <11.11%> (-0.03%) ⬇️
ubuntu-latest-py3.12 23.93% <11.11%> (-0.03%) ⬇️
ubuntu-latest-py3.13 23.93% <11.11%> (-0.03%) ⬇️
ubuntu-latest-py3.14 22.04% <11.11%> (-0.02%) ⬇️
windows-latest-py3.10 18.69% <0.00%> (-0.06%) ⬇️
windows-latest-py3.11 18.69% <0.00%> (-0.06%) ⬇️
windows-latest-py3.12 18.69% <0.00%> (-0.06%) ⬇️
windows-latest-py3.13 18.69% <0.00%> (-0.06%) ⬇️
windows-latest-py3.14 18.42% <0.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

BleakClientBlueZDBus.disconnect() now only calls BlueZ Disconnect when this client initiated the connection. The decision is based on a 'from_connected_devices' marker that BleakAdapterBlueZDBus.get_connected_devices() sets on each returned BLEDevice.

If a device is found already connected at connect() time and the user did not opt into the existing connection (no marker), the client still owns the connection so it can clean up an orphan from a crashed previous run. Only when the BLEDevice was retrieved via BleakAdapter.get_connected_devices() does the new client leave the connection up on close.

See bluez/bluez#89.
@Vodur Vodur force-pushed the bluez-keep-connected branch from faea97f to 75708ed Compare May 6, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant