From 9bcb7f1cce153be19593ff059bd4103148caba8b Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 19 Jan 2019 15:26:29 +0100 Subject: [PATCH] Fix race condition --- aioesphomeapi/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aioesphomeapi/client.py b/aioesphomeapi/client.py index 704f37d..794669b 100644 --- a/aioesphomeapi/client.py +++ b/aioesphomeapi/client.py @@ -600,10 +600,14 @@ class APIClient: raise APIConnectionError("Already connected!") connected = False + stopped = False async def _on_stop(): - if self._connection is None: + nonlocal stopped + + if stopped: return + stopped = True self._connection = None if connected and on_stop is not None: await on_stop()