From 07810926d0cc59e23e52858d3b9d1a90118d8af2 Mon Sep 17 00:00:00 2001
From: "J. Nick Koston" <nick@koston.org>
Date: Sat, 13 Jan 2024 18:50:47 -1000
Subject: [PATCH] Update habluetooth to 2.2.0 (#108000)

* Update habluetooth to 2.2.0

* fixes

* lib
---
 homeassistant/components/bluetooth/manifest.json |  2 +-
 homeassistant/package_constraints.txt            |  2 +-
 requirements_all.txt                             |  2 +-
 requirements_test_all.txt                        |  2 +-
 tests/components/bluetooth/__init__.py           | 16 +++++++++++++++-
 tests/components/bluetooth/test_api.py           |  3 +--
 tests/components/bluetooth/test_diagnostics.py   |  5 +++--
 tests/components/bluetooth/test_models.py        | 13 +++++++------
 8 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/homeassistant/components/bluetooth/manifest.json b/homeassistant/components/bluetooth/manifest.json
index 1551a83ad6a..9dfa4b84bb8 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 c62a64f8de2..59e003c1263 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 3a30320ae7a..3858efa640a 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 c70b173ec89..ded65914e01 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 5ad4b5a6c31..f4616abf8e5 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 a42752dcfc7..bc65874b0cc 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 a8e693c3f99..debecb0ac80 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 9b513ed2197..680d7c2e798 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."""
-- 
GitLab