33
44import asyncio
55import logging
6- from collections .abc import Callable , Generator
6+ from collections .abc import Generator
77from contextlib import contextmanager
8- from dataclasses import dataclass
98from typing import TYPE_CHECKING , Any , Final , final
109
1110from bleak .backends .device import BLEDevice
1413from bluetooth_adapters import DiscoveredDeviceAdvertisementData , adapter_human_name
1514from bluetooth_data_tools import monotonic_time_coarse
1615
16+ from .central_manager import get_manager
1717from .const import (
1818 CALLBACK_TYPE ,
1919 CONNECTABLE_FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS ,
3131_str = str
3232
3333
34- @dataclass (slots = True )
35- class BluetoothScannerDevice :
36- """Data for a bluetooth device from a given scanner."""
37-
38- scanner : BaseHaScanner
39- ble_device : BLEDevice
40- advertisement : AdvertisementData
41-
42-
4334class BaseHaScanner :
4435 """Base class for high availability BLE scanners."""
4536
@@ -55,6 +46,7 @@ class BaseHaScanner:
5546 "_start_time" ,
5647 "_cancel_watchdog" ,
5748 "_loop" ,
49+ "_manager" ,
5850 )
5951
6052 def __init__ (
@@ -75,6 +67,7 @@ def __init__(
7567 self ._start_time = 0.0
7668 self ._cancel_watchdog : asyncio .TimerHandle | None = None
7769 self ._loop : asyncio .AbstractEventLoop | None = None
70+ self ._manager = get_manager ()
7871
7972 def async_setup (self ) -> CALLBACK_TYPE :
8073 """Set up the scanner."""
@@ -191,7 +184,6 @@ class BaseHaRemoteScanner(BaseHaScanner):
191184 """Base class for a high availability remote BLE scanner."""
192185
193186 __slots__ = (
194- "_new_info_callback" ,
195187 "_discovered_device_advertisement_datas" ,
196188 "_details" ,
197189 "_expire_seconds" ,
@@ -203,13 +195,11 @@ def __init__(
203195 self ,
204196 scanner_id : str ,
205197 name : str ,
206- new_info_callback : Callable [[BluetoothServiceInfoBleak ], None ],
207198 connector : HaBluetoothConnector | None ,
208199 connectable : bool ,
209200 ) -> None :
210201 """Initialize the scanner."""
211202 super ().__init__ (scanner_id , name , connector )
212- self ._new_info_callback = new_info_callback
213203 self ._discovered_device_advertisement_datas : dict [
214204 str , tuple [BLEDevice , AdvertisementData ]
215205 ] = {}
@@ -434,7 +424,7 @@ def _async_on_advertisement(
434424 advertisement_monotonic_time ,
435425 )
436426 self ._previous_service_info [address ] = service_info
437- self ._new_info_callback (service_info )
427+ self ._manager . scanner_adv_received (service_info )
438428
439429 async def async_diagnostics (self ) -> dict [str , Any ]:
440430 """Return diagnostic information about the scanner."""
0 commit comments