Skip to content

Commit

Permalink
backends/winrt: add address acquisition process when advertising data…
Browse files Browse the repository at this point in the history
… is None (#1571)

In some situations, device.details has the scan response data only and
advertising data is None.

Since the ble address cannot be obtained from device.details.adv this time,
the ble address is obtained from the device.details.scan (scan response data).
  • Loading branch information
kaz399 authored May 12, 2024
1 parent 181467f commit 73d2cb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased`_
=============

Changed
-------
* Retrieve the BLE address required by ``BleakClientWinRT`` from scan response if advertising is None (WinRT).
* Changed type hint for ``adv`` attribute of ``bleak.backends.winrt.scanner._RawAdvData``.

`0.22.1`_ (2024-05-07)
======================

Expand Down
6 changes: 4 additions & 2 deletions bleak/backends/winrt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def __init__(

# Backend specific. WinRT objects.
if isinstance(address_or_ble_device, BLEDevice):
self._device_info = address_or_ble_device.details.adv.bluetooth_address
data = address_or_ble_device.details
self._device_info = (data.adv or data.scan).bluetooth_address
else:
self._device_info = None
self._requested_services = (
Expand Down Expand Up @@ -293,7 +294,8 @@ async def connect(self, **kwargs) -> bool:
self.address, f"Device with address {self.address} was not found."
)

self._device_info = device.details.adv.bluetooth_address
data = device.details
self._device_info = (data.adv or data.scan).bluetooth_address

logger.debug("Connecting to BLE device @ %s", self.address)

Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/winrt/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _RawAdvData(NamedTuple):
advertising data like other platforms, so se have to do it ourselves.
"""

adv: BluetoothLEAdvertisementReceivedEventArgs
adv: Optional[BluetoothLEAdvertisementReceivedEventArgs]
"""
The advertisement data received from the BluetoothLEAdvertisementWatcher.Received event.
"""
Expand Down

0 comments on commit 73d2cb5

Please sign in to comment.