diff --git a/homeassistant/components/bluetooth/wrappers.py b/homeassistant/components/bluetooth/wrappers.py index 7ccbce453c1..67e401cd40a 100644 --- a/homeassistant/components/bluetooth/wrappers.py +++ b/homeassistant/components/bluetooth/wrappers.py @@ -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)