Skip to content

Commit 316cdde

Browse files
authored
Bump bleak to 2.0.0 (home-assistant#157766)
1 parent 2f71aec commit 316cdde

File tree

8 files changed

+53
-10
lines changed

8 files changed

+53
-10
lines changed

homeassistant/components/bluetooth/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"quality_scale": "internal",
1717
"requirements": [
18-
"bleak==1.0.1",
18+
"bleak==2.0.0",
1919
"bleak-retry-connector==4.4.3",
2020
"bluetooth-adapters==2.1.0",
2121
"bluetooth-auto-recovery==1.5.3",

homeassistant/package_constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ av==16.0.1
2121
awesomeversion==25.8.0
2222
bcrypt==5.0.0
2323
bleak-retry-connector==4.4.3
24-
bleak==1.0.1
24+
bleak==2.0.0
2525
bluetooth-adapters==2.1.0
2626
bluetooth-auto-recovery==1.5.3
2727
bluetooth-data-tools==1.28.4

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/components/bluetooth/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections.abc import Generator, Iterable
44
from contextlib import contextmanager
55
import itertools
6+
from platform import system
67
import time
78
from typing import Any
89
from unittest.mock import MagicMock, PropertyMock, patch
@@ -37,6 +38,7 @@
3738
"inject_advertisement_with_time_and_source_connectable",
3839
"inject_bluetooth_service_info",
3940
"patch_all_discovered_devices",
41+
"patch_bleak_backend_type",
4042
"patch_bluetooth_time",
4143
"patch_discovered_devices",
4244
)
@@ -76,6 +78,47 @@ def patch_bluetooth_time(mock_time: float) -> None:
7678
yield
7779

7880

81+
@contextmanager
82+
def patch_bleak_backend_type() -> Generator[None]:
83+
"""Patch bleak backend type based on current platform."""
84+
platform = system()
85+
86+
if platform == "Darwin":
87+
from bleak.backends.corebluetooth.client import ( # noqa: PLC0415
88+
BleakClientCoreBluetooth,
89+
)
90+
from bleak.backends.corebluetooth.scanner import ( # noqa: PLC0415
91+
BleakScannerCoreBluetooth,
92+
)
93+
94+
scanner_backend = (BleakScannerCoreBluetooth, "CoreBluetooth")
95+
client_backend = (BleakClientCoreBluetooth, "CoreBluetooth")
96+
elif platform == "Linux":
97+
from bleak.backends.bluezdbus.client import ( # noqa: PLC0415
98+
BleakClientBlueZDBus,
99+
)
100+
from bleak.backends.bluezdbus.scanner import ( # noqa: PLC0415
101+
BleakScannerBlueZDBus,
102+
)
103+
104+
scanner_backend = (BleakScannerBlueZDBus, "BlueZ")
105+
client_backend = (BleakClientBlueZDBus, "BlueZ")
106+
else:
107+
raise RuntimeError(f"Unsupported platform for Bluetooth testing: {platform}")
108+
109+
with (
110+
patch(
111+
"bleak.get_platform_scanner_backend_type",
112+
return_value=scanner_backend,
113+
),
114+
patch(
115+
"bleak.get_platform_client_backend_type",
116+
return_value=client_backend,
117+
),
118+
):
119+
yield
120+
121+
79122
def generate_advertisement_data(**kwargs: Any) -> AdvertisementData:
80123
"""Generate advertisement data with defaults."""
81124
new = kwargs.copy()

tests/components/bluetooth/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
HCI1_SOURCE_ADDRESS,
1818
NON_CONNECTABLE_REMOTE_SOURCE_ADDRESS,
1919
FakeScanner,
20+
patch_bleak_backend_type,
2021
)
2122

2223

@@ -88,7 +89,7 @@ def mock_operating_system_90():
8889
def macos_adapter() -> Generator[None]:
8990
"""Fixture that mocks the macos adapter."""
9091
with (
91-
patch("bleak.get_platform_scanner_backend_type"),
92+
patch_bleak_backend_type(),
9293
patch(
9394
"homeassistant.components.bluetooth.platform.system",
9495
return_value="Darwin",

tests/components/bluetooth/test_models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
generate_ble_device,
2727
inject_advertisement,
2828
inject_advertisement_with_source,
29+
patch_bleak_backend_type,
2930
)
3031

3132

@@ -595,7 +596,7 @@ async def async_get_device_by_address(self, address: str) -> BLEDevice | None:
595596
]
596597

597598
client = HaBleakClientWrapper(switchbot_proxy_device_no_connection_slot)
598-
with patch("bleak.get_platform_client_backend_type"):
599+
with patch_bleak_backend_type():
599600
await client.connect()
600601
assert client.is_connected is True
601602
client.set_disconnected_callback(lambda client: None)

tests/components/bluetooth/test_usage.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Tests for the Bluetooth integration."""
22

3-
from unittest.mock import patch
4-
53
import bleak
64
from habluetooth.usage import (
75
install_multiple_bleak_catcher,
@@ -12,7 +10,7 @@
1210

1311
from homeassistant.core import HomeAssistant
1412

15-
from . import generate_ble_device
13+
from . import generate_ble_device, patch_bleak_backend_type
1614

1715
MOCK_BLE_DEVICE = generate_ble_device(
1816
"00:00:00:00:00:00",
@@ -31,7 +29,7 @@ async def test_multiple_bleak_scanner_instances(hass: HomeAssistant) -> None:
3129

3230
uninstall_multiple_bleak_catcher()
3331

34-
with patch("bleak.get_platform_scanner_backend_type"):
32+
with patch_bleak_backend_type():
3533
instance = bleak.BleakScanner()
3634

3735
assert not isinstance(instance, HaBleakScannerWrapper)

0 commit comments

Comments
 (0)