From ecc0fbdae9deb28480ab46af6d0ef8312a1c5c47 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 28 Jun 2021 11:22:12 -0400 Subject: [PATCH] mqtt: return a boolean in the wait_connection method Rather than require consumers handle the TimeoutError, handle it directly and return the connection state. SIgned-off-by: Eric Callahan --- moonraker/components/mqtt.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/moonraker/components/mqtt.py b/moonraker/components/mqtt.py index 3c80ab2..75106df 100644 --- a/moonraker/components/mqtt.py +++ b/moonraker/components/mqtt.py @@ -339,10 +339,12 @@ class MQTTClient(APITransport): break self.reconnect_task = None - async def wait_connection(self, timeout: Optional[float] = None) -> None: - if self.connect_evt.is_set(): - return - await asyncio.wait_for(self.connect_evt.wait(), timeout) + async def wait_connection(self, timeout: Optional[float] = None) -> bool: + try: + await asyncio.wait_for(self.connect_evt.wait(), timeout) + except asyncio.TimeoutError: + return False + return True def is_connected(self) -> bool: return self.connect_evt.is_set()