Skip to content

Commit 4cc38fe

Browse files
fix: local api failing to send message
1 parent 1a9351d commit 4cc38fe

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

roborock/local_api.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import logging
55
import socket
6-
from asyncio import Transport
6+
from asyncio import Transport, Lock
77
from typing import Callable, Mapping, Optional
88

99
import 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

0 commit comments

Comments
 (0)