Skip to content

Commit

Permalink
Initialize the asyncio Lock object in the discover call to ensure it'…
Browse files Browse the repository at this point in the history
…s created in the same loop that is running.

Close #74
  • Loading branch information
mill1000 committed Sep 26, 2023
1 parent 21a3f44 commit 97564b5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion msmart/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Discover:

_account = OPEN_MIDEA_APP_ACCOUNT
_password = OPEN_MIDEA_APP_PASSWORD
_lock = asyncio.Lock()
_lock = None
_cloud = None
_auto_connect = False

Expand All @@ -155,6 +155,10 @@ async def discover(
) -> List[Device]:
"""Discover devices via broadcast."""

# Create lock if nonexistent within the context of the current loop
if cls._lock is None:
cls._lock = asyncio.Lock()

# Always use a new cloud connection
cls._cloud = None

Expand Down

0 comments on commit 97564b5

Please sign in to comment.