diff --git a/homeassistant/components/esphome/bluetooth/client.py b/homeassistant/components/esphome/bluetooth/client.py index 878e305da00..0eb57420b3c 100644 --- a/homeassistant/components/esphome/bluetooth/client.py +++ b/homeassistant/components/esphome/bluetooth/client.py @@ -78,7 +78,7 @@ def verify_connected(func: _WrapFuncType) -> _WrapFuncType: with contextlib.suppress(asyncio.CancelledError): await task raise BleakError( - f"{self._source}: {self._ble_device.name} - {self._ble_device.address}: " # pylint: disable=protected-access + f"{self._source_name}: {self._ble_device.name} - {self._ble_device.address}: " # pylint: disable=protected-access "Disconnected during operation" ) return next(iter(done)).result() @@ -109,7 +109,7 @@ def api_error_as_bleak_error(func: _WrapFuncType) -> _WrapFuncType: if ex.error.error == -1: _LOGGER.debug( "%s: %s - %s: BLE device disconnected during %s operation", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, func.__name__, @@ -154,6 +154,7 @@ class ESPHomeClient(BaseBleakClient): assert device_info is not None self._connection_version = device_info.bluetooth_proxy_version self._address_type = address_or_ble_device.details["address_type"] + self._source_name = f"{config_entry.title} [{self._source}]" def __str__(self) -> str: """Return the string representation of the client.""" @@ -168,7 +169,7 @@ class ESPHomeClient(BaseBleakClient): except (AssertionError, ValueError) as ex: _LOGGER.debug( "%s: %s - %s: Failed to unsubscribe from connection state (likely connection dropped): %s", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ex, @@ -194,7 +195,7 @@ class ESPHomeClient(BaseBleakClient): if was_connected: _LOGGER.debug( "%s: %s - %s: BLE device disconnected", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -204,7 +205,7 @@ class ESPHomeClient(BaseBleakClient): """Handle the esp32 client disconnecting from hass.""" _LOGGER.debug( "%s: %s - %s: ESP device disconnected", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -245,7 +246,7 @@ class ESPHomeClient(BaseBleakClient): """Handle a connect or disconnect.""" _LOGGER.debug( "%s: %s - %s: Connection state changed to connected=%s mtu=%s error=%s", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, connected, @@ -286,7 +287,7 @@ class ESPHomeClient(BaseBleakClient): _LOGGER.debug( "%s: %s - %s: connected, registering for disconnected callbacks", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -295,7 +296,7 @@ class ESPHomeClient(BaseBleakClient): timeout = kwargs.get("timeout", self._timeout) if not (scanner := async_scanner_by_source(self._hass, self._source)): - raise BleakError("Scanner disappeared for {self._source}") + raise BleakError("Scanner disappeared for {self._source_name}") with scanner.connecting(): try: self._cancel_connection_state = ( @@ -352,7 +353,7 @@ class ESPHomeClient(BaseBleakClient): return _LOGGER.debug( "%s: %s - %s: Out of connection slots, waiting for a free one", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -401,7 +402,7 @@ class ESPHomeClient(BaseBleakClient): ) and (cached_services := entry_data.get_gatt_services_cache(address_as_int)): _LOGGER.debug( "%s: %s - %s: Cached services hit", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -409,7 +410,7 @@ class ESPHomeClient(BaseBleakClient): return self.services _LOGGER.debug( "%s: %s - %s: Cached services miss", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -418,7 +419,7 @@ class ESPHomeClient(BaseBleakClient): ) _LOGGER.debug( "%s: %s - %s: Got services: %s", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, esphome_services, @@ -453,7 +454,7 @@ class ESPHomeClient(BaseBleakClient): self.services = services _LOGGER.debug( "%s: %s - %s: Cached services saved", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, ) @@ -612,7 +613,7 @@ class ESPHomeClient(BaseBleakClient): _LOGGER.debug( "%s: %s - %s: Writing to CCD descriptor %s for notifications with properties=%s", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, cccd_descriptor.handle, @@ -650,7 +651,7 @@ class ESPHomeClient(BaseBleakClient): if self._cancel_connection_state: _LOGGER.warning( "%s: %s - %s: ESPHomeClient bleak client was not properly disconnected before destruction", - self._source, + self._source_name, self._ble_device.name, self._ble_device.address, )