Adjust esphome bluetooth client logging for unique id change (#83742)

This commit is contained in:
J. Nick Koston 2022-12-10 17:45:59 -10:00 committed by GitHub
parent d3df4dd3c1
commit 7178cacdc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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