File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 33import asyncio
44import logging
55import socket
6- from asyncio import Transport
6+ from asyncio import Transport , Lock
77from typing import Callable , Mapping , Optional
88
99import async_timeout
@@ -122,6 +122,7 @@ def __init__(
122122 self .timeout = timeout
123123 self .remaining = b""
124124 self .transport : Transport | None = None
125+ self ._mutex = Lock ()
125126
126127 def data_received (self , message ):
127128 if self .remaining :
@@ -151,10 +152,11 @@ def disconnect(self):
151152 self .transport .close ()
152153
153154 async def send_message (self , data : bytes ) -> None :
154- await self .connect ()
155- try :
156- if not self .transport :
157- raise RoborockException ("Can not send message without connection" )
158- self .transport .write (data )
159- except Exception as e :
160- raise RoborockException (e ) from e
155+ async with self ._mutex :
156+ await self .connect ()
157+ try :
158+ if not self .transport :
159+ raise RoborockException ("Can not send message without connection" )
160+ self .transport .write (data )
161+ except Exception as e :
162+ raise RoborockException (e ) from e
You can’t perform that action at this time.
0 commit comments