Improve bluetooth logging when there are multiple adapters (#77007)
parent
49957c752b
commit
18246bb8c8
|
@ -269,13 +269,17 @@ async def async_setup_entry(
|
|||
assert address is not None
|
||||
adapter = await manager.async_get_adapter_from_address(address)
|
||||
if adapter is None:
|
||||
raise ConfigEntryNotReady(f"Bluetooth adapter with address {address} not found")
|
||||
raise ConfigEntryNotReady(
|
||||
f"Bluetooth adapter {adapter} with address {address} not found"
|
||||
)
|
||||
|
||||
try:
|
||||
bleak_scanner = create_bleak_scanner(BluetoothScanningMode.ACTIVE, adapter)
|
||||
except RuntimeError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
scanner = HaScanner(hass, bleak_scanner, adapter)
|
||||
raise ConfigEntryNotReady(
|
||||
f"{adapter_human_name(adapter, address)}: {err}"
|
||||
) from err
|
||||
scanner = HaScanner(hass, bleak_scanner, adapter, address)
|
||||
entry.async_on_unload(scanner.async_register_callback(manager.scanner_adv_received))
|
||||
await scanner.async_start()
|
||||
entry.async_on_unload(manager.async_register_scanner(scanner))
|
||||
|
|
|
@ -33,6 +33,7 @@ from .const import (
|
|||
START_TIMEOUT,
|
||||
)
|
||||
from .models import BluetoothScanningMode
|
||||
from .util import adapter_human_name
|
||||
|
||||
OriginalBleakScanner = bleak.BleakScanner
|
||||
MONOTONIC_TIME = time.monotonic
|
||||
|
@ -76,7 +77,11 @@ class HaScanner:
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, scanner: bleak.BleakScanner, adapter: str | None
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
scanner: bleak.BleakScanner,
|
||||
adapter: str,
|
||||
address: str,
|
||||
) -> None:
|
||||
"""Init bluetooth discovery."""
|
||||
self.hass = hass
|
||||
|
@ -89,7 +94,7 @@ class HaScanner:
|
|||
self._callbacks: list[
|
||||
Callable[[BLEDevice, AdvertisementData, float, str], None]
|
||||
] = []
|
||||
self.name = self.adapter or "default"
|
||||
self.name = adapter_human_name(adapter, address)
|
||||
self.source = self.adapter or SOURCE_LOCAL
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue