Skip to content

Conversation

@dlech
Copy link
Collaborator

@dlech dlech commented Nov 22, 2025

Added

  • Added bleak.backends.get_default_backend() and BleakBackend enum for a centralized backend detection.
  • Added BleakClient().backend_id and BleakScanner().backend_id properties to identify the backend in use.

Changed

  • Use "AcquireNotify" rather than "StartNotify" for Linux backend on supported characteristics
  • Allow multiple calls to disconnect() on Windows to align behavior over all backends.
  • Raise new BleakBluetoothNotAvailableError when Bluetooth is not supported, turned off or permission is denied.

Fixed

  • Fixed potential race condition causing timeout while connecting in WinRT backend.
  • Fixed file handle leak in BlueZ backend when D-Bus connection is lost and re-established.
  • Fixed crash in CoreBluetooth backend if an ObjC delegate callback is called after the asyncio run loop stops.
  • Fixed possible deadlock when starting scanning on Windows when Bluetooth is turned off.
  • Fixed "Bluetooth device is turned off" Exception on macOS, when a Bluetooth permission request popup is shown to the user by the OS.

Removed

  • Removed support for Python 3.9.
  • Removed support for macOS < 10.15.

dlech and others added 30 commits September 7, 2025 14:46
Prefer `name: SomeType[T] = SomeType()` over `name = SomeType[T]()`.
We have, e.g `name: list[T] = []`, in many places, so this makes the
style consistent.
The `__init__()` method already ensures that `_or_patterns` is not `None`
when `_scanning_mode` is `"passive"`, but the type checker cannot infer
that in other methods.
Add a few more that were missed in commit a242cfb.
Rectified typo at backend/winrt/scanner.py
Change the minimum macOS version is now 10.15, because CBCentralManager.authorization is not earlier available. We will be using this in  a future commit.
Add a new BleakBluetoothNotAvailableError specialized exception to be able to provide more useful error messages on how to recover from Bluetooth not being available. This exception includes a `reason` property that can be used to programatically check the reason as well.

This is only implemented in the corebluetooth backend currently. Other backends will be adapted in later commits.
Drop support for Python 3.9 as it has reached end-of-life.
Give more nuanced exceptions when Bluetooth is not available on Linux.
Update poetry.lock to get latest versions and Python 3.14 support.
Document the version this was added/changed and add a few missing docstrings.
Change - bullets to * bullets in CHANGELOG.rst. This is consistent with
the rest of the file.
These were added automatically be VSCode.
Check the Bluetooth adapter/radio status when starting scanning on
Windows backend. This uses the new BleakBluetoothNotAvailableError with
appropriate reason codes when no adapter is found, or the radio is turned
off. Also, it fixes a possible deadlock when starting scanning while the
radio is off which happens because of the while loop waiting for the
watcher status to change from CREATED.
Add NO_BLE_CENTRAL reason to BleakBluetoothNotAvailableReason enum.
In some backends, we can actually check if the Bluetooth adapter
supports the BLE 'central' role required by Bleak.
… for rubicon-objc

Split ObjC delegate classes into two separate classes, one with only ObjC methods and one with only Python methods. This will allow sharing more code between PyObjC and Rubicon ObjC runtimes.
Fix a missing return statement when looking up the Bluetooth address
for a peripheral fails.
Various assortment of type checking fixes and improvements in the CoreBluetooth backend.
Replace `__del__` with `weakref.finalize` to ensure proper cleanup of
observers. This is slightly more deterministic than relying on `__del__`
which is not guaranteed to be called.
We forgot to add BleakClient.name to the docs when the property was
added. Add it now.

Fixes: #1854
Add try/except blocks to all delegate callbacks to catch RuntimeError
exceptions that can occur if the asyncio event loop is closed while
callbacks are being processed.

In rare cases, one of these can be triggered while Python is shutting
down causing the process to crash rather than exiting successfully.
Add new backend enum and detection function. This de-duplicates the backend detection logic.

Also add new `backend_id` property to `BleakClient` and `BleakScanner` to get the backend used by each instance.
align WinRT implementation with other backends
Using StartNotify in the BlueZ backend has a similar issue as the CoreBluetooth backend in that we get the same signal that the characteristic value has changed for both notifications and reads and there isn't a way to tell the difference.

Using AcquireNotify instead of StartNotify creates a pipe that only receives notifications for a single characteristic. Having this separate communication channel makes it known that the change was a notification and not a read. 

As a bonus, this should be more performant since it avoids a D-Bus signal on every notification (although we didn't actually measure it).
Call disconnect() on the old bus object if we have to reconnect to the
D-Bus system bus. This ensures that file handles are released and we
don't leak them.
We need to check the current session status *after* registering the
event handler, otherwise we might miss the event if the session
status changes between checking the status and registering the handler.
This pulls in some fixes to prevent leaking resources and allows us to
drop a bunch of "assert reply" lines that were only there to keep type
checkers happy.

We still allow older versions of dbus-fast for better compatibility
with existing installations.
@dlech dlech changed the base branch from develop to master November 22, 2025 18:18
@dlech dlech merged commit 75f7469 into master Nov 22, 2025
31 of 32 checks passed
@dlech dlech deleted the release/v2.0.0 branch November 22, 2025 18:22
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.

7 participants