From 2fc1d04644b80a7641abe820b02f441f3191c183 Mon Sep 17 00:00:00 2001 From: Koen Vervloesem Date: Fri, 8 Dec 2023 22:09:14 +0100 Subject: [PATCH] Stop scan loop and show error message on BleakError (#179) --- TheengsGateway/ble_gateway.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TheengsGateway/ble_gateway.py b/TheengsGateway/ble_gateway.py index dc60b972..12057dd0 100644 --- a/TheengsGateway/ble_gateway.py +++ b/TheengsGateway/ble_gateway.py @@ -370,9 +370,13 @@ async def ble_scan_loop(self) -> None: while not self.stopped: if self.client.is_connected(): self.published_messages = 0 - await scanner.start() - await asyncio.sleep(self.configuration["ble_scan_time"]) - await scanner.stop() + try: + await scanner.start() + await asyncio.sleep(self.configuration["ble_scan_time"]) + await scanner.stop() + except BleakError as error: + logger.exception(error) # noqa: TRY401 + self.stopped = True logger.info( "Sent %s messages to MQTT", self.published_messages,