Skip to content

Commit e4a291d

Browse files
fix: minor fixes
1 parent f3e675f commit e4a291d

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

roborock/cloud_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def on_message(self, *args, **kwargs):
8585
def on_disconnect(self, *args, **kwargs):
8686
_, __, rc, ___ = args
8787
try:
88-
super().on_connection_lost(RoborockException(mqtt.error_string(rc)))
88+
exc = RoborockException(mqtt.error_string(rc)) if rc != mqtt.MQTT_ERR_SUCCESS else None
89+
super().on_connection_lost(exc)
8990
if rc == mqtt.MQTT_ERR_PROTOCOL:
9091
self.update_client_id()
9192
connection_queue = self._waiting_queue.get(DISCONNECT_REQUEST_ID)

roborock/local_api.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def data_received(self, message):
4040
self.on_message_received(parser_msg)
4141

4242
def connection_lost(self, exc: Optional[Exception]):
43-
self.sync_disconnect()
43+
self.loop.run_until_complete(self.async_disconnect())
4444
self.on_connection_lost(exc)
4545

4646
def is_connected(self):
@@ -55,7 +55,6 @@ async def async_connect(self) -> None:
5555
try:
5656
is_connected = self.is_connected()
5757
if not is_connected:
58-
self.sync_disconnect()
5958
async with async_timeout.timeout(QUEUE_TIMEOUT):
6059
_LOGGER.info(f"Connecting to {self.host}")
6160
self.transport, _ = await self.loop.create_connection( # type: ignore
@@ -68,16 +67,13 @@ async def async_connect(self) -> None:
6867
await self.hello()
6968
await self.keep_alive_func()
7069

71-
def sync_disconnect(self) -> None:
72-
if self.transport and self.loop.is_running():
73-
_LOGGER.debug(f"Disconnecting from {self.host}")
74-
self.transport.close()
75-
if self.keep_alive_task:
76-
self.keep_alive_task.cancel()
77-
7870
async def async_disconnect(self) -> None:
7971
async with self._mutex:
80-
self.sync_disconnect()
72+
if self.transport and self.loop.is_running():
73+
_LOGGER.debug(f"Disconnecting from {self.host}")
74+
self.transport.close()
75+
if self.keep_alive_task:
76+
self.keep_alive_task.cancel()
8177

8278
def build_roborock_message(self, method: RoborockCommand, params: Optional[list | dict] = None) -> RoborockMessage:
8379
secured = True if method in COMMANDS_SECURED else False

roborock/roborock_typing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class RoborockCommand(str, Enum):
8787
GET_WASH_TOWEL_MODE = "get_wash_towel_mode"
8888
LOAD_MULTI_MAP = "load_multi_map"
8989
NAME_SEGMENT = "name_segment"
90-
NONE = ""
9190
RESET_CONSUMABLE = "reset_consumable"
9291
RESUME_SEGMENT_CLEAN = "resume_segment_clean"
9392
RESUME_ZONED_CLEAN = "resume_zoned_clean"
@@ -232,7 +231,6 @@ class CommandInfo:
232231
RoborockCommand.GET_WASH_TOWEL_MODE: CommandInfo(params=None),
233232
RoborockCommand.LOAD_MULTI_MAP: CommandInfo(params=None),
234233
RoborockCommand.NAME_SEGMENT: CommandInfo(params=None),
235-
RoborockCommand.NONE: CommandInfo(params=None),
236234
RoborockCommand.RESET_CONSUMABLE: CommandInfo(params=None),
237235
RoborockCommand.RESUME_SEGMENT_CLEAN: CommandInfo(params=None),
238236
RoborockCommand.RESUME_ZONED_CLEAN: CommandInfo(params=None),

roborock/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def wrapped(*args, **kwargs):
3636

3737
class CacheableResult:
3838
last_run_result = None
39-
use_count = 0
4039

4140

4241
RT = TypeVar("RT", bound=Callable[..., Coroutine])
@@ -48,13 +47,14 @@ def fallback_cache(func: RT) -> RT:
4847
@functools.wraps(func)
4948
async def wrapped(*args, **kwargs):
5049
try:
51-
cache.last_run_result = await func(*args, **kwargs)
52-
cache.use_count = 0
50+
last_run_result = await func(*args, **kwargs)
51+
cache.last_run_result = last_run_result
5352
except Exception as e:
54-
if cache.last_run_result is None or cache.use_count > 0:
53+
if cache.last_run_result is None:
5554
raise e
56-
cache.last_run_result.is_cached = True
57-
cache.use_count += 1
58-
return cache.last_run_result
55+
last_run_result = cache.last_run_result
56+
cache.last_run_result = None
57+
return last_run_result
58+
return last_run_result
5959

6060
return wrapped # type: ignore

0 commit comments

Comments
 (0)