Skip to content

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

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

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

Conversation

@Vodur

@Vodur Vodur commented May 6, 2026

Copy link
Copy Markdown

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

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.72%. Comparing base (ae2f589) to head (e7f4e1c).

Files with missing lines Patch % Lines
bleak/backends/bluezdbus/client.py 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1984      +/-   ##
===========================================
+ Coverage    52.45%   52.72%   +0.27%     
===========================================
  Files           43       43              
  Lines         4097     4106       +9     
  Branches       504      506       +2     
===========================================
+ Hits          2149     2165      +16     
+ Misses        1817     1813       -4     
+ Partials       131      128       -3     
Flag Coverage Δ
bluez-integration-py310 39.45% <86.66%> (+0.30%) ⬆️
bluez-integration-py311 39.45% <86.66%> (+0.30%) ⬆️
bluez-integration-py312 39.45% <86.66%> (+0.30%) ⬆️
bluez-integration-py313 39.45% <86.66%> (+0.30%) ⬆️
bluez-integration-py314 37.96% <86.66%> (+0.31%) ⬆️
macos-latest-py310 19.99% <0.00%> (-0.05%) ⬇️
macos-latest-py311 19.99% <0.00%> (-0.05%) ⬇️
macos-latest-py312 19.99% <0.00%> (-0.05%) ⬇️
macos-latest-py313 19.99% <0.00%> (-0.05%) ⬇️
macos-latest-py314 19.80% <0.00%> (-0.05%) ⬇️
ubuntu-latest-py310 23.91% <6.66%> (-0.03%) ⬇️
ubuntu-latest-py311 23.91% <6.66%> (-0.03%) ⬇️
ubuntu-latest-py312 23.91% <6.66%> (-0.03%) ⬇️
ubuntu-latest-py313 23.91% <6.66%> (-0.03%) ⬇️
ubuntu-latest-py314 22.02% <6.66%> (-0.03%) ⬇️
windows-latest-py310 18.67% <0.00%> (-0.05%) ⬇️
windows-latest-py311 18.67% <0.00%> (-0.05%) ⬇️
windows-latest-py312 18.67% <0.00%> (-0.05%) ⬇️
windows-latest-py313 18.67% <0.00%> (-0.05%) ⬇️
windows-latest-py314 18.40% <0.00%> (-0.05%) ⬇️

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.

@Vodur Vodur force-pushed the bluez-keep-connected branch from faea97f to 75708ed Compare May 6, 2026 10:01
Comment thread tests/integration/test_adapter.py Outdated
Comment thread tests/integration/test_adapter.py Outdated
Comment thread tests/integration/test_adapter.py Outdated
Comment thread bleak/backends/bluezdbus/client.py Outdated
Comment thread bleak/backends/bluezdbus/client.py Outdated
Comment thread bleak/backends/bluezdbus/client.py Outdated
@Vodur Vodur force-pushed the bluez-keep-connected branch 3 times, most recently from 3c1a7c6 to 37b4549 Compare May 9, 2026 18:53
Comment thread tests/integration/test_adapter.py Outdated
Comment thread tests/integration/test_adapter.py Outdated
Comment thread CHANGELOG.rst Outdated
Comment thread tests/integration/test_adapter.py Outdated
@Vodur Vodur force-pushed the bluez-keep-connected branch from 37b4549 to 9e20aad Compare May 10, 2026 06:31
@Vodur Vodur requested a review from dlech May 23, 2026 14:57
BleakClientBlueZDBus.disconnect() now skips the BlueZ Disconnect call when the BLEDevice was retrieved from BleakAdapterBlueZDBus.get_connected_devices(). The marker 'from_connected_devices' is set on the BLEDevice details by get_connected_devices() and read by BleakClient on construction.

See bluez/bluez#89.
@Vodur Vodur force-pushed the bluez-keep-connected branch from 9e20aad to e7f4e1c Compare June 1, 2026 17:57
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.

3 participants