Skip to content

Commit

Permalink
Cleanup cache file clear (#2003)
Browse files Browse the repository at this point in the history
* Cleanup cache file clear

* Update persistent.py
  • Loading branch information
SukramJ authored Jan 21, 2025
1 parent c2e6881 commit dcd62d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version 2025.1.11 (2025-01-20)

- Cleanup cache file clear
- Delay start of scheduler until devices are created
- Rename instance_name to central_name
- Slugify cache file name
Expand Down
18 changes: 14 additions & 4 deletions hahomematic/caches/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__(
"""Initialize the base class of the persistent cache."""
self._save_load_semaphore: Final = asyncio.Semaphore()
self._central: Final = central
self._cache_dir: Final = f"{central.config.storage_folder}/{CACHE_PATH}"
self._filename: Final = f"{slugify(central.name)}_{self._file_postfix}"
self._cache_dir: Final = _get_cache_path(storage_folder=central.config.storage_folder)
self._filename: Final = _get_filename(central_name=central.name, file_name=self._file_postfix)
self._persistent_cache: Final = persistent_cache
self.last_save_triggered: datetime = INIT_DATETIME
self.last_hash_saved = hash_sha256(value=persistent_cache)
Expand Down Expand Up @@ -393,8 +393,18 @@ async def save(self) -> DataOperationResult:
return await super().save()


def _get_cache_path(storage_folder: str) -> str:
"""Return the cache path."""
return f"{storage_folder}/{CACHE_PATH}"


def _get_filename(central_name: str, file_name: str) -> str:
"""Return the cache filename."""
return f"{slugify(central_name)}_{file_name}"


def cleanup_cache_dirs(central_name: str, storage_folder: str) -> None:
"""Clean up the used cached directories."""
cache_dir = f"{storage_folder}/{CACHE_PATH}"
cache_dir = _get_cache_path(storage_folder=storage_folder)
for file_to_delete in (FILE_DEVICES, FILE_PARAMSETS):
delete_file(folder=cache_dir, file_name=f"{slugify(central_name)}_{file_to_delete}")
delete_file(folder=cache_dir, file_name=_get_filename(central_name=central_name, file_name=file_to_delete))

0 comments on commit dcd62d1

Please sign in to comment.