Skip to content

Commit 7dd3aa4

Browse files
fix: cache concurrency
1 parent df2524f commit 7dd3aa4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

roborock/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(self, attribute: RoborockAttribute, api: RoborockClient):
104104
self.attribute = attribute
105105
self.task = RepeatableTask(self.api.event_loop, self._async_value, EVICT_TIME)
106106
self._value: Any = None
107+
self._mutex = asyncio.Lock()
107108

108109
@property
109110
def value(self):
@@ -114,9 +115,10 @@ async def _async_value(self):
114115
return self._value
115116

116117
async def async_value(self):
117-
if self._value is None:
118-
return await self.task.reset()
119-
return self._value
118+
async with self._mutex:
119+
if self._value is None:
120+
return await self.task.reset()
121+
return self._value
120122

121123
def stop(self):
122124
self.task.cancel()
@@ -126,10 +128,10 @@ async def update_value(self, params):
126128
await self._async_value()
127129
return response
128130

129-
async def close_value(self, params):
131+
async def close_value(self):
130132
if self.attribute.close_command is None:
131133
raise RoborockException(f"{self.attribute.attribute} is not closeable")
132-
response = await self.api._send_command(self.attribute.close_command, params)
134+
response = await self.api._send_command(self.attribute.close_command)
133135
await self._async_value()
134136
return response
135137

0 commit comments

Comments
 (0)