Skip to content

Commit

Permalink
fix: lock before connect
Browse files Browse the repository at this point in the history
  • Loading branch information
IATkachenko committed Jul 9, 2022
1 parent 1820505 commit 615a9a6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tion_btle/tion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import asyncio
import inspect
import logging
import time
from asyncio import Semaphore
from typing import Callable, List, final
from time import localtime, strftime

Expand Down Expand Up @@ -98,6 +98,7 @@ def __init__(self, mac: str):
self.__connections_count: int = 0
self.__notifications_enabled: bool = False
self.have_breezer_state: bool = False
self._semaphore = Semaphore(1)

@abc.abstractmethod
async def _send_request(self, request: bytearray):
Expand Down Expand Up @@ -492,7 +493,8 @@ async def connect(self):

if self.__connections_count == 0:
self.have_breezer_state = False
await self._connect()
async with self._semaphore:
await self._connect()

self.__connections_count += 1

Expand Down

0 comments on commit 615a9a6

Please sign in to comment.