Skip to content

Commit

Permalink
backends/winrt/client: improve get_services() error messages
Browse files Browse the repository at this point in the history
The error messages were reporting something like:

    <_bleak_winrt_Windows_Devices_Bluetooth_GenericAttributeProfile.GattDeviceService object at 0x00000206F9189750>

This is the repr of the service object which isn't very useful. Change
the error message to include some useful identification properties
instead.
  • Loading branch information
dlech committed Apr 29, 2023
1 parent 63adefa commit 3216f20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased`_
=============

Changed
-------
- Improved error messages when failing to get services in WinRT backend.

`0.20.2`_ (2023-04-19)
======================

Expand Down
5 changes: 2 additions & 3 deletions bleak/backends/winrt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ async def pair(self, protection_level: int = None, **kwargs) -> bool:
device_information.pairing.can_pair
and not device_information.pairing.is_paired
):

# Currently only supporting Just Works solutions...
ceremony = DevicePairingKinds.CONFIRM_ONLY
custom_pairing = device_information.pairing.custom
Expand Down Expand Up @@ -706,7 +705,7 @@ def dispose_on_cancel(future):
characteristics: Sequence[GattCharacteristic] = _ensure_success(
await FutureLike(service.get_characteristics_async(*args)),
"characteristics",
f"Could not get GATT characteristics for {service}",
f"Could not get GATT characteristics for service {service.uuid} ({service.attribute_handle})",
)

logger.debug("returned from get_characteristics_async")
Expand All @@ -723,7 +722,7 @@ def dispose_on_cancel(future):
descriptors: Sequence[GattDescriptor] = _ensure_success(
await FutureLike(characteristic.get_descriptors_async(*args)),
"descriptors",
f"Could not get GATT descriptors for {service}",
f"Could not get GATT descriptors for characteristic {characteristic.uuid} ({characteristic.attribute_handle})",
)

logger.debug("returned from get_descriptors_async")
Expand Down

0 comments on commit 3216f20

Please sign in to comment.