diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b9b16623..f0759eff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,7 @@ Added Changed ------- * Raise new ``BleakBluetoothNotAvailableError`` when Bluetooth is not supported, turned off or permission is denied. +* Allow multiple calls to ``disconnect()`` on Windows to align behaviour over all backends. Fixed ----- diff --git a/bleak/backends/winrt/client.py b/bleak/backends/winrt/client.py index da5800c6..f3a398bf 100644 --- a/bleak/backends/winrt/client.py +++ b/bleak/backends/winrt/client.py @@ -465,7 +465,12 @@ async def disconnect(self) -> None: """Disconnect from the specified GATT server.""" logger.debug("Disconnecting from BLE device...") - assert self.services + if self.services is None: + # No connection exists. Either one hasn't been created or + # we have already called disconnect and closed the gatt + # connection. + logger.debug("already disconnected") + return # Remove notifications. for handle, event_handler_token in list(self._notification_callbacks.items()):