Skip to content

Commit 31a0478

Browse files
Bump python-roborock to 3.9.2 (home-assistant#157815)
Co-authored-by: Robert Resch <[email protected]>
1 parent 24da3f0 commit 31a0478

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

homeassistant/components/roborock/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"loggers": ["roborock"],
2121
"quality_scale": "silver",
2222
"requirements": [
23-
"python-roborock==3.8.4",
23+
"python-roborock==3.9.2",
2424
"vacuum-map-parser-roborock==0.1.4"
2525
]
2626
}

homeassistant/components/roborock/roborock_storage.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Roborock storage."""
22

3-
import dataclasses
43
import logging
54
from pathlib import Path
65
import shutil
@@ -17,7 +16,7 @@
1716

1817
STORAGE_PATH = f".storage/{DOMAIN}"
1918
MAPS_PATH = "maps"
20-
CACHE_VERSION = 1
19+
CACHE_VERSION = 2
2120

2221

2322
def _storage_path_prefix(hass: HomeAssistant, entry_id: str) -> Path:
@@ -44,6 +43,31 @@ def remove(path_prefix: Path) -> None:
4443
await hass.async_add_executor_job(remove, path_prefix)
4544

4645

46+
class StoreImpl(Store[dict[str, Any]]):
47+
"""Store implementation for Roborock cache."""
48+
49+
def __init__(self, hass: HomeAssistant, entry_id: str) -> None:
50+
"""Initialize StoreImpl."""
51+
super().__init__(
52+
hass,
53+
version=CACHE_VERSION,
54+
key=f"{DOMAIN}/{entry_id}",
55+
private=True,
56+
)
57+
58+
async def _async_migrate_func(
59+
self,
60+
old_major_version: int,
61+
old_minor_version: int,
62+
old_data: dict[str, Any],
63+
) -> dict[str, Any]:
64+
"""Wipe out old caches with the old format."""
65+
if old_major_version == 1:
66+
# No need for migration as version 1 was never in any stable releases
67+
return {}
68+
return old_data
69+
70+
4771
class CacheStore(Cache):
4872
"""Store and retrieve cache for a Roborock device.
4973
@@ -55,19 +79,14 @@ class CacheStore(Cache):
5579

5680
def __init__(self, hass: HomeAssistant, entry_id: str) -> None:
5781
"""Initialize CacheStore."""
58-
self._cache_store = Store[dict[str, Any]](
59-
hass,
60-
version=CACHE_VERSION,
61-
key=f"{DOMAIN}/{entry_id}",
62-
private=True,
63-
)
82+
self._cache_store = StoreImpl(hass, entry_id)
6483
self._cache_data: CacheData | None = None
6584

6685
async def get(self) -> CacheData:
6786
"""Retrieve cached metadata."""
6887
if self._cache_data is None:
6988
if data := await self._cache_store.async_load():
70-
self._cache_data = CacheData(**data)
89+
self._cache_data = CacheData.from_dict(data)
7190
else:
7291
self._cache_data = CacheData()
7392

@@ -80,7 +99,7 @@ async def set(self, value: CacheData) -> None:
8099
async def flush(self) -> None:
81100
"""Flush cached metadata to disk."""
82101
if self._cache_data is not None:
83-
await self._cache_store.async_save(dataclasses.asdict(self._cache_data))
102+
await self._cache_store.async_save(self._cache_data.as_dict())
84103

85104
async def async_remove(self) -> None:
86105
"""Remove cached metadata from disk."""

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)