Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Before you submit a pull request, check that it meets these guidelines:
1. If the pull request adds functionality, the docs should be updated.
2. Modify the `CHANGELOG.rst`, describing your changes as is specified by the
guidelines in that document.
3. The pull request should work for Python 3.10+ on the following platforms:
3. The pull request should work for Python 3.11+ on the following platforms:
- Windows 11, version 22000 and greater
- Linux distributions with BlueZ >= 5.55
- OS X / macOS >= 10.15
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["310", "311", "312", "313", "314"]
python-version: ["311", "312", "313", "314", "315"]
env:
FORCE_COLOR: "1"
steps:
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["310", "311", "312", "313", "314"]
python-version: ["311", "312", "313", "314", "315"]
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -102,6 +102,13 @@ jobs:
export FORCE_COLOR=1
export CI=true
export GITHUB_ACTIONS=true
# The Alpine uv package lags behind uv releases, so it may not know
# about the latest Python releases, e.g. it picked a 3.15 beta
# after 3.15.0 was released. Install the latest uv from PyPI and
# put it first in PATH, since poe also runs uv from PATH.
uv tool install --quiet uv
export PATH="$HOME/.local/bin:$PATH"
uv --version
uv run poe test-py${{ matrix.python-version }} --bleak-vhci --cov-report=xml --cov-report=html:../.htmlcov --junitxml=junit.xml -o junit_family=legacy -o cache_dir=../.pytest_cache
'

Expand Down Expand Up @@ -137,7 +144,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["310", "311", "312", "313", "314"]
python-version: ["311", "312", "313", "314", "315"]
steps:
- uses: actions/checkout@v4

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased`_
=============

Added
-----
* Added support for Python 3.15.

Changed
-------
* Changed ``BleakBackend`` to be a ``StrEnum``, so ``str()`` and ``format()`` return the plain value, e.g. ``"bluez_dbus"``.

Removed
-------
* Removed support for Python 3.10.

`3.1.0`_ (2026-11-07)
=====================

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Before you submit a pull request, check that it meets these guidelines:
1. If the pull request adds functionality, the docs should be updated.
2. Modify the ``CHANGELOG.rst``, describing your changes as is specified by the
guidelines in that document.
3. The pull request should work for Python 3.10+ on the following platforms:
3. The pull request should work for Python 3.11+ on the following platforms:
- Windows 11, version 22000 and greater
- Linux distributions with BlueZ >= 5.55
- OS X / macOS >= 10.15
Expand Down
20 changes: 15 additions & 5 deletions bleak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@
import uuid
from collections.abc import AsyncGenerator, Awaitable, Callable, Iterable
from types import TracebackType
from typing import Any, Literal, Optional, TypedDict, Union, cast, overload
from typing import (
Any,
Literal,
Never,
Optional,
Self,
TypedDict,
Union,
Unpack,
assert_never,
cast,
overload,
)
from warnings import warn

from bleak._compat import Never, Self, Unpack, assert_never
from bleak._compat import timeout as async_timeout
from bleak.args import SizedBuffer
from bleak.args.bluez import (
BlueZAdapterArgs,
Expand Down Expand Up @@ -414,12 +424,12 @@ async def find_device_by_filter(
"""
async with cls(**kwargs) as scanner:
try:
async with async_timeout(timeout):
async with asyncio.timeout(timeout):
async for bd, ad in scanner.advertisement_data():
if filterfunc(bd, ad):
return bd
assert_never(cast(Never, "advertisement_data() should never stop"))
except asyncio.TimeoutError:
except TimeoutError:
return None


Expand Down
15 changes: 0 additions & 15 deletions bleak/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@

import sys

if sys.version_info < (3, 11):
from async_timeout import timeout as timeout
from typing_extensions import Never as Never
from typing_extensions import Self as Self
from typing_extensions import TypeVarTuple as TypeVarTuple
from typing_extensions import Unpack as Unpack
from typing_extensions import assert_never as assert_never
else:
from asyncio import timeout as timeout # noqa: F401
from typing import Never as Never # noqa: F401
from typing import Self as Self # noqa: F401
from typing import TypeVarTuple as TypeVarTuple # noqa: F401
from typing import Unpack as Unpack # noqa: F401
from typing import assert_never as assert_never # noqa: F401

if sys.version_info < (3, 12):
from typing_extensions import override as override
else:
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from bleak.exc import BleakError


class BleakBackend(str, enum.Enum):
class BleakBackend(enum.StrEnum):
"""
Identifiers for available built-in Bleak backends.

Expand Down
8 changes: 3 additions & 5 deletions bleak/backends/_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import asyncio
import logging
from collections.abc import Callable
from typing import Any, ParamSpec, TypeVar

from bleak._compat import TypeVarTuple, Unpack
from typing import Any, ParamSpec, TypeVar, TypeVarTuple

_Ts = TypeVarTuple("_Ts")

Expand All @@ -13,8 +11,8 @@

def try_call_soon_threadsafe(
event_loop: asyncio.AbstractEventLoop,
callback: Callable[[Unpack[_Ts]], Any],
*args: Unpack[_Ts],
callback: Callable[[*_Ts], Any],
*args: *_Ts,
) -> None:
"""Call a callback on the event loop thread, handling closed loop errors gracefully."""
try:
Expand Down
3 changes: 1 addition & 2 deletions bleak/backends/adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any
from typing import Any, Self

from bleak._compat import Self
from bleak.backends import BleakBackend, get_default_backend
from bleak.backends.device import BLEDevice
from bleak.exc import BleakError
Expand Down
6 changes: 3 additions & 3 deletions bleak/backends/android/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import asyncio
import logging
from typing import Any, cast
from typing import Any, Self, cast

from android.bluetooth import (
BluetoothAdapter,
Expand All @@ -19,7 +19,7 @@
)
from android.content import Context

from bleak._compat import Self, override
from bleak._compat import override
from bleak.backends.adapter import BaseBleakAdapter
from bleak.backends.android.client import BleakClientAndroid
from bleak.backends.android.permissions import check_for_permissions
Expand Down Expand Up @@ -123,7 +123,7 @@ async def _discover_service_uuids(self, address: str) -> frozenset[str]:
return frozenset(
normalize_uuid_str(s.uuid) for s in client.services.services.values()
)
except (BleakError, asyncio.TimeoutError) as e:
except (BleakError, TimeoutError) as e:
logger.debug("service discovery failed for %s: %s", address, e)
return frozenset()
finally:
Expand Down
3 changes: 1 addition & 2 deletions bleak/backends/android/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from java.util import UUID

from bleak._compat import override
from bleak._compat import timeout as async_timeout
from bleak.args import SizedBuffer
from bleak.assigned_numbers import gatt_char_props_to_strs
from bleak.backends.android.broadcast import BroadcastReceiver
Expand Down Expand Up @@ -153,7 +152,7 @@ def _do_connect() -> BluetoothGatt:
return pending_gatt

try:
async with async_timeout(timeout):
async with asyncio.timeout(timeout):
gatt, conn_result = await callbacks.dispatcher.perform_and_wait(
dispatch_func=_do_connect,
callback_api=OnConnectionStateChangeCallback(),
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/android/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _do_start_scan() -> None:
try:
# Wait a short time to check if "onScanFailed" is called.
await asyncio.wait_for(scanfuture, timeout=0.2)
except asyncio.exceptions.TimeoutError:
except TimeoutError:
# If the scan started successfully but no device is found in the
# short waiting period, a timeout occurs. This is not an error.
pass
Expand Down
4 changes: 2 additions & 2 deletions bleak/backends/bluezdbus/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
if sys.platform != "linux":
assert False, "This backend is only available on Linux"

from typing import Any
from typing import Any, Self

from bleak._compat import Self, override
from bleak._compat import override
from bleak.args.bluez import BlueZAdapterArgs
from bleak.backends.adapter import BaseBleakAdapter
from bleak.backends.bluezdbus.manager import get_global_bluez_manager
Expand Down
11 changes: 5 additions & 6 deletions bleak/backends/bluezdbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from bleak import BleakScanner
from bleak._compat import override
from bleak._compat import timeout as async_timeout
from bleak.args import SizedBuffer
from bleak.backends.bluezdbus import defs
from bleak.backends.bluezdbus.manager import get_global_bluez_manager
Expand Down Expand Up @@ -123,7 +122,7 @@ async def connect(
Raises:
BleakError: If the device is already connected or if the device could not be found.
BleakDBusError: If there was a D-Bus error
asyncio.TimeoutError: If the connection timed out
TimeoutError: If the connection timed out
"""
logger.debug("Connecting to device @ %s", self.address)

Expand Down Expand Up @@ -157,7 +156,7 @@ async def connect(

manager = await get_global_bluez_manager()

async with async_timeout(timeout):
async with asyncio.timeout(timeout):
while True:
async with AsyncExitStack() as stack:
# Each BLE connection session needs a new D-Bus connection to avoid a
Expand Down Expand Up @@ -420,7 +419,7 @@ async def disconnect(self) -> None:

Raises:
BleakDBusError: If there was a D-Bus error
asyncio.TimeoutError if the device was not disconnected within 10 seconds
TimeoutError if the device was not disconnected within 10 seconds
"""
logger.debug("Disconnecting (%s)", self._device_path)

Expand All @@ -434,7 +433,7 @@ async def disconnect(self) -> None:
if self._disconnecting_event:
# another call to disconnect() is already in progress
logger.debug("already in progress (%s)", self._device_path)
async with async_timeout(10):
async with asyncio.timeout(10):
await self._disconnecting_event.wait()
else:
self._disconnecting_event = asyncio.Event()
Expand All @@ -451,7 +450,7 @@ async def disconnect(self) -> None:
)
assert_reply(reply)

async with async_timeout(10):
async with asyncio.timeout(10):
await self._disconnecting_event.wait()
except Exception as e:
if self._bus.connected:
Expand Down
8 changes: 3 additions & 5 deletions bleak/backends/corebluetooth/CentralManagerDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import asyncio
import logging
from collections.abc import Callable
from typing import Any, Optional, TypedDict, cast
from typing import Any, Optional, Self, TypedDict, cast

import objc
from CoreBluetooth import (
Expand All @@ -43,8 +43,6 @@
)
from libdispatch import DISPATCH_QUEUE_SERIAL, dispatch_queue_create

from bleak._compat import Self
from bleak._compat import timeout as async_timeout
from bleak.backends._utils import external_thread_callback, try_call_soon_threadsafe
from bleak.backends.corebluetooth.utils import cb_manager_state_message
from bleak.exc import (
Expand Down Expand Up @@ -295,12 +293,12 @@ async def connect(
self._connect_futures[peripheral.identifier()] = future
try:
self.central_manager.connectPeripheral_options_(peripheral, None)
async with async_timeout(timeout):
async with asyncio.timeout(timeout):
await future
finally:
del self._connect_futures[peripheral.identifier()]

except asyncio.TimeoutError:
except TimeoutError:
logger.debug(f"Connection timed out after {timeout} seconds.")
del self._disconnect_callbacks[peripheral.identifier()]
future = self.event_loop.create_future()
Expand Down
6 changes: 2 additions & 4 deletions bleak/backends/corebluetooth/PeripheralDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import itertools
import logging
from collections.abc import Iterable
from typing import Any, Optional
from typing import Any, Optional, Self

import objc
from CoreBluetooth import (
Expand All @@ -35,8 +35,6 @@
)
from Foundation import NSUUID, NSArray, NSData, NSError, NSNumber, NSObject

from bleak._compat import Self
from bleak._compat import timeout as async_timeout
from bleak.args.corebluetooth import NotificationDiscriminator
from bleak.backends._utils import external_thread_callback, try_call_soon_threadsafe
from bleak.backends.client import NotifyCallback
Expand Down Expand Up @@ -408,7 +406,7 @@ async def read_characteristic(

try:
self.peripheral.readValueForCharacteristic_(characteristic)
async with async_timeout(timeout):
async with asyncio.timeout(timeout):
return await future
finally:
del self._characteristic_read_futures[characteristic.handle()]
Expand Down
4 changes: 2 additions & 2 deletions bleak/backends/corebluetooth/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
if sys.platform != "darwin":
assert False, "This backend is only available on macOS"

from typing import Any
from typing import Any, Self

from CoreBluetooth import CBUUID
from Foundation import NSArray

from bleak._compat import Self, override
from bleak._compat import override
from bleak.backends.adapter import BaseBleakAdapter
from bleak.backends.corebluetooth.CentralManagerDelegate import CentralManagerDelegate
from bleak.backends.device import BLEDevice
Expand Down
5 changes: 2 additions & 3 deletions bleak/backends/p4android/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from jnius import cast, java_method

from bleak._compat import override
from bleak._compat import timeout as async_timeout
from bleak.backends.p4android import defs, utils
from bleak.backends.scanner import (
AdvertisementData,
Expand Down Expand Up @@ -138,9 +137,9 @@ def handle_permissions(permissions, grantResults):
self.__javascanner.flushPendingScanResults(self.__callback.java)

try:
async with async_timeout(0.2):
async with asyncio.timeout(0.2):
await scanfuture
except asyncio.exceptions.TimeoutError:
except TimeoutError:
pass
except BleakError as bleakerror:
await self.stop()
Expand Down
Loading
Loading