Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup cache file clear #2003

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Loading