Skip to content

Commit

Permalink
Merge pull request #1097 from hbldh/release/0.19.1
Browse files Browse the repository at this point in the history
Release/0.19.1
  • Loading branch information
dlech authored Oct 29, 2022
2 parents fc8cc49 + 572d0ee commit 433d2a6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11.0-rc.2']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased`_
=============

`0.19.1`_ (2022-10-29)
======================

Fixed
-----
* Fixed crash in Android backend introduced in v0.19.0. Fixes #1085.
* Fixed service discovery blocking forever if device disconnects in BlueZ backend. Merged #1092.
* Fixed ``AttributeError`` crash when scanning on Windows builds < 19041. Fixes #1094.

`0.19.0`_ (2022-10-13)
======================

Expand Down Expand Up @@ -841,7 +850,8 @@ Fixed
* Bleak created.


.. _Unreleased: https://github.com/hbldh/bleak/compare/v0.19.0...develop
.. _Unreleased: https://github.com/hbldh/bleak/compare/v0.19.1...develop
.. _0.19.1: https://github.com/hbldh/bleak/compare/v0.19.0...v0.19.1
.. _0.19.0: https://github.com/hbldh/bleak/compare/v0.18.1...v0.19.0
.. _0.18.1: https://github.com/hbldh/bleak/compare/v0.18.0...v0.18.1
.. _0.18.0: https://github.com/hbldh/bleak/compare/v0.17.0...v0.18.0
Expand Down
25 changes: 24 additions & 1 deletion bleak/backends/bluezdbus/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ async def get_services(
logger.debug("Using cached services for %s", device_path)
return services

await self._wait_condition(device_path, "ServicesResolved", True)
await self._wait_for_services_discovery(device_path)

services = BleakGATTServiceCollection()

Expand Down Expand Up @@ -648,6 +648,29 @@ def is_connected(self, device_path: str) -> bool:
except KeyError:
return False

async def _wait_for_services_discovery(self, device_path: str) -> None:
"""
Waits for the device services to be discovered.
If a disconnect happens before the completion a BleakError exception is raised.
"""
services_discovered_wait_task = asyncio.create_task(
self._wait_condition(device_path, "ServicesResolved", True)
)
device_disconnected_wait_task = asyncio.create_task(
self._wait_condition(device_path, "Connected", False)
)
done, pending = await asyncio.wait(
{services_discovered_wait_task, device_disconnected_wait_task},
return_when=asyncio.FIRST_COMPLETED,
)

for p in pending:
p.cancel()

if device_disconnected_wait_task in done:
raise BleakError("failed to discover services, device disconnected")

async def _wait_condition(
self, device_path: str, property_name: str, property_value: Any
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/p4android/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _handle_scan_result(self, result):
service_data=service_data,
service_uuids=service_uuids,
tx_power=tx_power,
rssi=native_device.getRssi(),
rssi=result.getRssi(),
platform_data=(result,),
)

Expand Down
12 changes: 10 additions & 2 deletions bleak/backends/winrt/scanner.py
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bleak"
version = "0.19.0"
version = "0.19.1"
description = "Bluetooth Low Energy platform Agnostic Klient"
authors = ["Henrik Blidh <henrik.blidh@nedomkull.com>"]
license = "MIT"
Expand Down

0 comments on commit 433d2a6

Please sign in to comment.