Skip to content

Commit

Permalink
winrt/scanner: fix AttributeError on Windows < 19041
Browse files Browse the repository at this point in the history
The transmit power property of the advertising data was added in Windows
build 19041, so we need a fallback for older versions of Windows.

Fixes #1094
  • Loading branch information
dlech committed Oct 29, 2022
1 parent 850cab4 commit 60aa4aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -15,6 +15,7 @@ Fixed
* Fixed crash in Android backend introduced in v0.19.0. Fixes #1085.
* BlueZ: Cancel the device discovery wait task if the device disconnects in
between to avoid a timeout
* Fixed ``AttributeError`` crash when scanning on Windows builds < 19041. Fixes #1094.

`0.19.0`_ (2022-10-13)
======================
Expand Down
12 changes: 10 additions & 2 deletions bleak/backends/winrt/scanner.py
Expand Up @@ -156,8 +156,16 @@ def _received_handler(
if args.advertisement.local_name:
local_name = args.advertisement.local_name

if args.transmit_power_level_in_d_bm is not None:
tx_power = raw_data.adv.transmit_power_level_in_d_bm
try:
if args.transmit_power_level_in_d_bm is not None:
tx_power = args.transmit_power_level_in_d_bm
except AttributeError:
# the transmit_power_level_in_d_bm property was introduce in
# Windows build 19041 so we have a fallback for older versions
for section in args.advertisement.get_sections_by_type(
AdvertisementDataType.TX_POWER_LEVEL
):
tx_power = bytes(section.data)[0]

# Decode service data
for section in args.advertisement.get_sections_by_type(
Expand Down

0 comments on commit 60aa4aa

Please sign in to comment.