Update bluetooth debug logging for newer bleak (#91643)

fixes

```
homeassistant/components/bluetooth/wrappers.py:268: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
  rssi = wrapped_backend.device.rssi
```
pull/91681/head
J. Nick Koston 2023-04-19 05:26:02 -10:00 committed by GitHub
parent f8fa382ebc
commit 573c15d67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -251,8 +251,10 @@ class HaBleakClientWrapper(BleakClient):
assert models.MANAGER is not None
manager = models.MANAGER
wrapped_backend = self._async_get_best_available_backend_and_device(manager)
device = wrapped_backend.device
scanner = wrapped_backend.scanner
self._backend = wrapped_backend.client(
wrapped_backend.device,
device,
disconnected_callback=self._make_disconnected_callback(
self.__disconnected_callback
),
@ -261,8 +263,9 @@ class HaBleakClientWrapper(BleakClient):
)
if debug_logging := _LOGGER.isEnabledFor(logging.DEBUG):
# Only lookup the description if we are going to log it
description = ble_device_description(wrapped_backend.device)
rssi = wrapped_backend.device.rssi
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)
connected = None
try:
@ -271,11 +274,11 @@ class HaBleakClientWrapper(BleakClient):
# If we failed to connect and its a local adapter (no source)
# we release the connection slot
if not connected:
self.__connect_failures[wrapped_backend.scanner] = (
self.__connect_failures.get(wrapped_backend.scanner, 0) + 1
self.__connect_failures[scanner] = (
self.__connect_failures.get(scanner, 0) + 1
)
if not wrapped_backend.source:
manager.async_release_connection_slot(wrapped_backend.device)
manager.async_release_connection_slot(device)
if debug_logging:
_LOGGER.debug("%s: Connected (last rssi: %s)", description, rssi)