Skip to content

Commit 51ce9c9

Browse files
committed
fix: adjust cache implementation defaults
1 parent 0426edc commit 51ce9c9

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

roborock/devices/cache.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ async def get(self) -> CacheData:
4545

4646
async def set(self, value: CacheData) -> None:
4747
self._data = value
48+
49+
50+
class NoCache(Cache):
51+
"""No-op cache implementation."""
52+
53+
async def get(self) -> CacheData:
54+
return CacheData()
55+
56+
async def set(self, value: CacheData) -> None:
57+
pass

roborock/devices/device_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from roborock.protocol import create_mqtt_params
1919
from roborock.web_api import RoborockApiClient
2020

21-
from .cache import Cache, InMemoryCache
21+
from .cache import Cache, NoCache
2222
from .channel import Channel
2323
from .mqtt_channel import create_mqtt_channel
2424
from .traits.dyad import DyadApi
@@ -137,7 +137,7 @@ async def create_device_manager(
137137
include caching or other optimizations.
138138
"""
139139
if cache is None:
140-
cache = InMemoryCache()
140+
cache = NoCache()
141141

142142
mqtt_params = create_mqtt_params(user_data.rriot)
143143
mqtt_session = await create_mqtt_session(mqtt_params)

tests/devices/test_device_manager.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from roborock.containers import HomeData, UserData
9+
from roborock.devices.cache import CacheData, InMemoryCache
910
from roborock.devices.device_manager import create_device_manager, create_home_data_api
1011
from roborock.exceptions import RoborockException
1112

@@ -109,9 +110,6 @@ async def mock_home_data_with_counter() -> HomeData:
109110
call_count += 1
110111
return HomeData.from_dict(mock_data.HOME_DATA_RAW)
111112

112-
# Create a real cache implementation for testing
113-
from roborock.devices.cache import CacheData
114-
115113
class TestCache:
116114
def __init__(self):
117115
self._data = CacheData()
@@ -122,9 +120,8 @@ async def get(self) -> CacheData:
122120
async def set(self, value: CacheData) -> None:
123121
self._data = value
124122

125-
cache = TestCache()
126123
# First call happens during create_device_manager initialization
127-
device_manager = await create_device_manager(USER_DATA, mock_home_data_with_counter, cache)
124+
device_manager = await create_device_manager(USER_DATA, mock_home_data_with_counter, cache=InMemoryCache())
128125
assert call_count == 1
129126

130127
# Second call should use cache, not increment call_count

0 commit comments

Comments
 (0)