Skip to content

Commit 88fbe7b

Browse files
authored
fix: select latest V1 cleaning record regardless of response order (#978)
1 parent 1269a8d commit 88fbe7b

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎roborock/devices/traits/v1/clean_summary.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ async def refresh(self) -> None:
8282
_LOGGER.debug("No clean records available in clean summary.")
8383
self.last_clean_record = None
8484
return
85-
last_record_id = self.records[0]
85+
# Record IDs are start timestamps; devices may return them in either order.
86+
last_record_id = max(self.records)
8687
self.last_clean_record = await self.get_clean_record(last_record_id)
8788

8889
async def get_clean_record(self, record_id: int) -> CleanRecord:

‎tests/devices/traits/v1/test_clean_summary.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@ async def test_get_clean_summary_success(
9797
)
9898

9999

100+
@pytest.mark.parametrize(
101+
"records",
102+
[
103+
[1700000000, 1700000400, 1700000800],
104+
[1700000800, 1700000400, 1700000000],
105+
[1700000400, 1700000800, 1700000000],
106+
[1700000800],
107+
],
108+
ids=["ascending", "descending", "unordered", "single"],
109+
)
110+
async def test_get_clean_summary_latest_record(
111+
clean_summary_trait: CleanSummaryTrait, mock_rpc_channel: AsyncMock, records: list[int]
112+
) -> None:
113+
"""Load the latest cleaning regardless of the order returned by the device."""
114+
mock_rpc_channel.send_command.side_effect = [
115+
[3600, 1000000, len(records), records],
116+
[[1700000800, 1700000900, 100, 1000000]],
117+
]
118+
119+
await clean_summary_trait.refresh()
120+
121+
assert mock_rpc_channel.send_command.call_args_list == [
122+
call(RoborockCommand.GET_CLEAN_SUMMARY),
123+
call(RoborockCommand.GET_CLEAN_RECORD, params=[1700000800]),
124+
]
125+
assert clean_summary_trait.records == records
126+
assert clean_summary_trait.last_clean_record is not None
127+
assert clean_summary_trait.last_clean_record.begin == 1700000800
128+
assert clean_summary_trait.last_clean_record.end == 1700000900
129+
130+
100131
async def test_get_clean_summary_clean_time_only(
101132
clean_summary_trait: CleanSummaryTrait, mock_rpc_channel: AsyncMock, sample_clean_summary: CleanSummary
102133
) -> None:

0 commit comments

Comments
 (0)