Skip to content

Commit ea5fe45

Browse files
authored
backends: winrt: allow multiple disconnect() calls
align WinRT implementation with other backends
1 parent a6fea5a commit ea5fe45

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Added
1818
Changed
1919
-------
2020
* Raise new ``BleakBluetoothNotAvailableError`` when Bluetooth is not supported, turned off or permission is denied.
21+
* Allow multiple calls to ``disconnect()`` on Windows to align behaviour over all backends.
2122

2223
Fixed
2324
-----

bleak/backends/winrt/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,12 @@ async def disconnect(self) -> None:
465465
"""Disconnect from the specified GATT server."""
466466
logger.debug("Disconnecting from BLE device...")
467467

468-
assert self.services
468+
if self.services is None:
469+
# No connection exists. Either one hasn't been created or
470+
# we have already called disconnect and closed the gatt
471+
# connection.
472+
logger.debug("already disconnected")
473+
return
469474

470475
# Remove notifications.
471476
for handle, event_handler_token in list(self._notification_callbacks.items()):

0 commit comments

Comments
 (0)