Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug logging for which adapter is used to connect bluetooth devices #103264

Merged
merged 1 commit into from Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/bluetooth/wrappers.py
Expand Up @@ -270,6 +270,8 @@
"""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)

Check warning on line 274 in homeassistant/components/bluetooth/wrappers.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluetooth/wrappers.py#L274

Added line #L274 was not covered by tests
wrapped_backend = self._async_get_best_available_backend_and_device(manager)
device = wrapped_backend.device
scanner = wrapped_backend.scanner
Expand All @@ -281,12 +283,14 @@
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(

Check warning on line 291 in homeassistant/components/bluetooth/wrappers.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluetooth/wrappers.py#L291

Added line #L291 was not covered by tests
"%s: Connecting via %s (last rssi: %s)", description, scanner.name, rssi
)
connected = None
try:
connected = await super().connect(**kwargs)
Expand All @@ -301,7 +305,9 @@
manager.async_release_connection_slot(device)

if debug_logging:
_LOGGER.debug("%s: Connected (last rssi: %s)", description, rssi)
_LOGGER.debug(

Check warning on line 308 in homeassistant/components/bluetooth/wrappers.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/bluetooth/wrappers.py#L308

Added line #L308 was not covered by tests
"%s: Connected via %s (last rssi: %s)", description, scanner.name, rssi
)
return connected

@hass_callback
Expand Down