Skip to content

Commit e119201

Browse files
authored
fix: make cache not global (#122)
* feat: add datetime parsing in cleanrecord * chore: lint * chore: lint * fix: timezone for non-3.11 * chore: lint * feat: add is_available for ha and here in future * fix: add timeout as a variable and set a longer default timeout for cloud * chore: lint * fix: is_available true by default * fix: status type as class variable * fix: don't update status when it was none before listener * fix: reduce info logs * fix: don't cache device cache * chore: lint * fix: double keepalive * fix: don't continue calling unsupported functions * fix: revert keepalive for now
1 parent 36932c1 commit e119201

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

roborock/api.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,21 @@ def __init__(self, attribute: RoborockAttribute, api: RoborockClient):
118118
self.task = RepeatableTask(self.api.event_loop, self._async_value, EVICT_TIME)
119119
self._value: Any = None
120120
self._mutex = asyncio.Lock()
121+
self.unsupported: bool = False
121122

122123
@property
123124
def value(self):
124125
return self._value
125126

126127
async def _async_value(self):
127-
self._value = await self.api._send_command(self.attribute.get_command)
128+
if self.unsupported:
129+
return None
130+
try:
131+
self._value = await self.api._send_command(self.attribute.get_command)
132+
except UnknownMethodError as err:
133+
# Limit the amount of times we call unsupported methods
134+
self.unsupported = True
135+
raise err
128136
return self._value
129137

130138
async def async_value(self):
@@ -161,9 +169,6 @@ async def refresh_value(self):
161169
await self._async_value()
162170

163171

164-
device_cache: dict[str, dict[CacheableAttribute, AttributeCache]] = {}
165-
166-
167172
class RoborockClient:
168173
def __init__(self, endpoint: str, device_info: DeviceData, queue_timeout: int = 4) -> None:
169174
self.event_loop = get_running_loop_or_create_one()
@@ -176,13 +181,9 @@ def __init__(self, endpoint: str, device_info: DeviceData, queue_timeout: int =
176181
self.keep_alive = KEEPALIVE
177182
self._diagnostic_data: dict[str, dict[str, Any]] = {}
178183
self._logger = RoborockLoggerAdapter(device_info.device.name, _LOGGER)
179-
cache = device_cache.get(device_info.device.duid)
180-
if not cache:
181-
cache = {
182-
cacheable_attribute: AttributeCache(attr, self) for cacheable_attribute, attr in get_cache_map().items()
183-
}
184-
device_cache[device_info.device.duid] = cache
185-
self.cache: dict[CacheableAttribute, AttributeCache] = cache
184+
self.cache: dict[CacheableAttribute, AttributeCache] = {
185+
cacheable_attribute: AttributeCache(attr, self) for cacheable_attribute, attr in get_cache_map().items()
186+
}
186187
self._listeners: list[Callable[[str, CacheableAttribute, RoborockBase], None]] = []
187188
self.is_available: bool = True
188189
self.queue_timeout = queue_timeout

0 commit comments

Comments
 (0)