From 03c84f99deba04c3d04236f608e24ad137540b8c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 25 Sep 2023 13:25:14 -0500 Subject: [PATCH] fix: do not try to stop notify if read char is missing (#36) --- .pre-commit-config.yaml | 2 +- src/led_ble/led_ble.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d0963b8..6056a97 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/psf/black diff --git a/src/led_ble/led_ble.py b/src/led_ble/led_ble.py index 06e2e2e..02c695a 100644 --- a/src/led_ble/led_ble.py +++ b/src/led_ble/led_ble.py @@ -498,7 +498,13 @@ async def _execute_disconnect(self) -> None: self._read_char = None self._write_char = None if client and client.is_connected: - await client.stop_notify(read_char) + if read_char: + try: + await client.stop_notify(read_char) + except BleakError: + _LOGGER.debug( + "%s: Failed to stop notifications", self.name, exc_info=True + ) await client.disconnect() @retry_bluetooth_connection_error(DEFAULT_ATTEMPTS)