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

fix: support new backup methods for homeassistant 2024.11.0 #161

Merged
merged 1 commit into from
Nov 9, 2024
Merged
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
20 changes: 16 additions & 4 deletions custom_components/auto_backup/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ async def create_backup(
self, config: Dict, partial: bool = False, timeout: Optional[int] = None
) -> Dict:
if not config.get(PATCH_NAME):
backup = await self._manager.generate_backup()
if hasattr(self._manager, "async_create_backup"):
backup = await self._manager.async_create_backup()
else:
backup = await self._manager.generate_backup()
else:
_LOGGER.debug("Support name is set: %s", config)
if not hasattr(self._manager, "_mkdir_and_generate_backup_contents"):
Expand Down Expand Up @@ -210,7 +213,10 @@ def wrapper(*args, **kwargs):
self._manager._generate_backup_contents = wrapper
else:
self._manager._mkdir_and_generate_backup_contents = wrapper
backup = await self._manager.generate_backup()
if hasattr(self._manager, "async_create_backup"):
backup = await self._manager.async_create_backup()
else:
backup = await self._manager.generate_backup()
backup.name = config[ATTR_NAME]
finally:
if hasattr(self._manager, "_generate_backup_contents"):
Expand All @@ -221,12 +227,18 @@ def wrapper(*args, **kwargs):
return backup.as_dict()

async def remove_backup(self, slug):
await self._manager.remove_backup(slug)
if hasattr(self._manager, "async_remove_backup"):
await self._manager.async_remove_backup(slug=slug)
else:
await self._manager.remove_backup(slug)

async def download_backup(
self, slug: str, destination: str, timeout: int = DEFAULT_BACKUP_TIMEOUT_SECONDS
):
backup = await self._manager.get_backup(slug)
if hasattr(self._manager, "async_get_backup"):
backup = await self._manager.async_get_backup(slug=slug)
else:
backup = await self._manager.get_backup(slug)
if backup:
shutil.copyfile(backup.path, destination)
else:
Expand Down