Add debug logging for which adapter is used to connect bluetooth devices (#103264)
Log which adapter is used to connect bluetooth devices This is a debug logging improvement to help users find problems with their setup
This commit is contained in:
parent
a63c420890
commit
c81ada16ba
1 changed files with 9 additions and 3 deletions
|
@ -270,6 +270,8 @@ class HaBleakClientWrapper(BleakClient):
|
|||
"""Connect to the specified GATT server."""
|
||||
assert models.MANAGER is not None
|
||||
manager = models.MANAGER
|
||||
if debug_logging := _LOGGER.isEnabledFor(logging.DEBUG):
|
||||
_LOGGER.debug("%s: Looking for backend to connect", self.__address)
|
||||
wrapped_backend = self._async_get_best_available_backend_and_device(manager)
|
||||
device = wrapped_backend.device
|
||||
scanner = wrapped_backend.scanner
|
||||
|
@ -281,12 +283,14 @@ class HaBleakClientWrapper(BleakClient):
|
|||
timeout=self.__timeout,
|
||||
hass=manager.hass,
|
||||
)
|
||||
if debug_logging := _LOGGER.isEnabledFor(logging.DEBUG):
|
||||
if debug_logging:
|
||||
# Only lookup the description if we are going to log it
|
||||
description = ble_device_description(device)
|
||||
_, adv = scanner.discovered_devices_and_advertisement_data[device.address]
|
||||
rssi = adv.rssi
|
||||
_LOGGER.debug("%s: Connecting (last rssi: %s)", description, rssi)
|
||||
_LOGGER.debug(
|
||||
"%s: Connecting via %s (last rssi: %s)", description, scanner.name, rssi
|
||||
)
|
||||
connected = None
|
||||
try:
|
||||
connected = await super().connect(**kwargs)
|
||||
|
@ -301,7 +305,9 @@ class HaBleakClientWrapper(BleakClient):
|
|||
manager.async_release_connection_slot(device)
|
||||
|
||||
if debug_logging:
|
||||
_LOGGER.debug("%s: Connected (last rssi: %s)", description, rssi)
|
||||
_LOGGER.debug(
|
||||
"%s: Connected via %s (last rssi: %s)", description, scanner.name, rssi
|
||||
)
|
||||
return connected
|
||||
|
||||
@hass_callback
|
||||
|
|
Loading…
Add table
Reference in a new issue