diff --git a/homeassistant/components/bluetooth/manifest.json b/homeassistant/components/bluetooth/manifest.json index 1551a83ad6aa8c5ba25742149b25f7e447f076fb..9dfa4b84bb8dc338f52f30e3e9c904e77133aa30 100644 --- a/homeassistant/components/bluetooth/manifest.json +++ b/homeassistant/components/bluetooth/manifest.json @@ -20,6 +20,6 @@ "bluetooth-auto-recovery==1.3.0", "bluetooth-data-tools==1.19.0", "dbus-fast==2.21.0", - "habluetooth==2.1.0" + "habluetooth==2.2.0" ] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index c62a64f8de2e93bc582cd6cbadcbfe7132be40e4..59e003c12630aaf8be0525a3cb719a22a4ab7102 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -24,7 +24,7 @@ dbus-fast==2.21.0 fnv-hash-fast==0.5.0 ha-av==10.1.1 ha-ffmpeg==3.1.0 -habluetooth==2.1.0 +habluetooth==2.2.0 hass-nabucasa==0.75.1 hassil==1.5.2 home-assistant-bluetooth==1.12.0 diff --git a/requirements_all.txt b/requirements_all.txt index 3a30320ae7a45222bbe9747ccc039748223dc23b..3858efa640ab24d14ff32e5971b86e08101fc629 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1001,7 +1001,7 @@ ha-philipsjs==3.1.1 habitipy==0.2.0 # homeassistant.components.bluetooth -habluetooth==2.1.0 +habluetooth==2.2.0 # homeassistant.components.cloud hass-nabucasa==0.75.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c70b173ec89c456755a669ba99be1dc83a24581d..ded65914e0100b53b77f96b8f459a03dbaa4bbdc 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -806,7 +806,7 @@ ha-philipsjs==3.1.1 habitipy==0.2.0 # homeassistant.components.bluetooth -habluetooth==2.1.0 +habluetooth==2.2.0 # homeassistant.components.cloud hass-nabucasa==0.75.1 diff --git a/tests/components/bluetooth/__init__.py b/tests/components/bluetooth/__init__.py index 5ad4b5a6c310c6ddbdc190322b4dfe472fde4757..f4616abf8e5596d508577b10152a8197671e9516 100644 --- a/tests/components/bluetooth/__init__.py +++ b/tests/components/bluetooth/__init__.py @@ -1,6 +1,7 @@ """Tests for the Bluetooth integration.""" +from collections.abc import Iterable from contextlib import contextmanager import itertools import time @@ -295,7 +296,20 @@ class MockBleakClient(BleakClient): return True -class FakeScanner(BaseHaScanner): +class FakeScannerMixin: + def get_discovered_device_advertisement_data( + self, address: str + ) -> tuple[BLEDevice, AdvertisementData] | None: + """Return the advertisement data for a discovered device.""" + return self.discovered_devices_and_advertisement_data.get(address) + + @property + def discovered_addresses(self) -> Iterable[str]: + """Return an iterable of discovered devices.""" + return self.discovered_devices_and_advertisement_data + + +class FakeScanner(FakeScannerMixin, BaseHaScanner): """Fake scanner.""" @property diff --git a/tests/components/bluetooth/test_api.py b/tests/components/bluetooth/test_api.py index a42752dcfc7190ee512a4d58589b119b4c266b68..bc65874b0ccd046fc30c85aa8c16b56450adcf5e 100644 --- a/tests/components/bluetooth/test_api.py +++ b/tests/components/bluetooth/test_api.py @@ -8,7 +8,6 @@ from homeassistant.components import bluetooth from homeassistant.components.bluetooth import ( MONOTONIC_TIME, BaseHaRemoteScanner, - BaseHaScanner, HaBluetoothConnector, async_scanner_by_source, async_scanner_devices_by_address, @@ -124,7 +123,7 @@ async def test_async_scanner_devices_by_address_non_connectable( rssi=-100, ) - class FakeStaticScanner(BaseHaScanner): + class FakeStaticScanner(FakeScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" diff --git a/tests/components/bluetooth/test_diagnostics.py b/tests/components/bluetooth/test_diagnostics.py index a8e693c3f991c3223be4575cedeba3c113f93d43..debecb0ac80645e3e2eb1346f29e781f334e1418 100644 --- a/tests/components/bluetooth/test_diagnostics.py +++ b/tests/components/bluetooth/test_diagnostics.py @@ -3,17 +3,18 @@ from unittest.mock import ANY, MagicMock, patch from bleak.backends.scanner import AdvertisementData, BLEDevice from bluetooth_adapters import DEFAULT_ADDRESS -from habluetooth import HaScanner from homeassistant.components import bluetooth from homeassistant.components.bluetooth import ( MONOTONIC_TIME, BaseHaRemoteScanner, HaBluetoothConnector, + HaScanner, ) from homeassistant.core import HomeAssistant from . import ( + FakeScannerMixin, MockBleakClient, _get_manager, generate_advertisement_data, @@ -26,7 +27,7 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator -class FakeHaScanner(HaScanner): +class FakeHaScanner(FakeScannerMixin, HaScanner): """Fake HaScanner.""" @property diff --git a/tests/components/bluetooth/test_models.py b/tests/components/bluetooth/test_models.py index 9b513ed2197a8dd08d9f212c5754721b6b6e04b2..680d7c2e798865e378695da3e3182a359f9cabb5 100644 --- a/tests/components/bluetooth/test_models.py +++ b/tests/components/bluetooth/test_models.py @@ -18,6 +18,7 @@ from homeassistant.components.bluetooth import ( from homeassistant.core import HomeAssistant from . import ( + FakeScannerMixin, MockBleakClient, _get_manager, generate_advertisement_data, @@ -79,7 +80,7 @@ async def test_wrapped_bleak_client_local_adapter_only( local_name="wohand", service_uuids=[], manufacturer_data={1: b"\x01"}, rssi=-100 ) - class FakeScanner(BaseHaScanner): + class FakeScanner(FakeScannerMixin, BaseHaScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" @@ -155,7 +156,7 @@ async def test_wrapped_bleak_client_set_disconnected_callback_after_connected( local_name="wohand", service_uuids=[], manufacturer_data={1: b"\x01"}, rssi=-100 ) - class FakeScanner(BaseHaRemoteScanner): + class FakeScanner(FakeScannerMixin, BaseHaRemoteScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" @@ -266,7 +267,7 @@ async def test_ble_device_with_proxy_client_out_of_connections( local_name="wohand", service_uuids=[], manufacturer_data={1: b"\x01"} ) - class FakeScanner(BaseHaRemoteScanner): + class FakeScanner(FakeScannerMixin, BaseHaRemoteScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" @@ -331,7 +332,7 @@ async def test_ble_device_with_proxy_clear_cache( local_name="wohand", service_uuids=[], manufacturer_data={1: b"\x01"} ) - class FakeScanner(BaseHaRemoteScanner): + class FakeScanner(FakeScannerMixin, BaseHaRemoteScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" @@ -434,7 +435,7 @@ async def test_ble_device_with_proxy_client_out_of_connections_uses_best_availab "esp32_no_connection_slot", ) - class FakeScanner(BaseHaRemoteScanner): + class FakeScanner(FakeScannerMixin, BaseHaRemoteScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices.""" @@ -546,7 +547,7 @@ async def test_ble_device_with_proxy_client_out_of_connections_uses_best_availab "esp32_no_connection_slot", ) - class FakeScanner(BaseHaRemoteScanner): + class FakeScanner(FakeScannerMixin, BaseHaRemoteScanner): @property def discovered_devices(self) -> list[BLEDevice]: """Return a list of discovered devices."""