Align hassio with changes in BackupAgent (#139780)

pull/136603/merge
Erik Montnemery 2025-03-04 20:20:49 +01:00 committed by GitHub
parent e8099fd3b2
commit be3d678f23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 16 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
from collections.abc import AsyncIterator, Callable, Coroutine, Mapping
from contextlib import suppress
import logging
import os
from pathlib import Path, PurePath
@ -173,7 +174,7 @@ class SupervisorBackupAgent(BackupAgent):
),
)
except SupervisorNotFoundError as err:
raise BackupNotFound from err
raise BackupNotFound(f"Backup {backup_id} not found") from err
async def async_upload_backup(
self,
@ -186,6 +187,7 @@ class SupervisorBackupAgent(BackupAgent):
The upload will be skipped if the backup already exists in the agent's location.
"""
with suppress(BackupNotFound):
if await self.async_get_backup(backup.backup_id):
_LOGGER.debug(
"Backup %s already exists in location %s",
@ -218,14 +220,14 @@ class SupervisorBackupAgent(BackupAgent):
self,
backup_id: str,
**kwargs: Any,
) -> AgentBackup | None:
) -> AgentBackup:
"""Return a backup."""
try:
details = await self._client.backups.backup_info(backup_id)
except SupervisorNotFoundError:
return None
except SupervisorNotFoundError as err:
raise BackupNotFound(f"Backup {backup_id} not found") from err
if self.location not in details.location_attributes:
return None
raise BackupNotFound(f"Backup {backup_id} not found")
return _backup_details_to_agent_backup(details, self.location)
async def async_delete_backup(self, backup_id: str, **kwargs: Any) -> None:
@ -237,8 +239,8 @@ class SupervisorBackupAgent(BackupAgent):
location={self.location}
),
)
except SupervisorNotFoundError:
_LOGGER.debug("Backup %s does not exist", backup_id)
except SupervisorNotFoundError as err:
raise BackupNotFound(f"Backup {backup_id} not found") from err
class SupervisorBackupReaderWriter(BackupReaderWriter):
@ -492,10 +494,12 @@ class SupervisorBackupReaderWriter(BackupReaderWriter):
) -> None:
"""Restore a backup."""
manager = self._hass.data[DATA_MANAGER]
# The backup manager has already checked that the backup exists so we don't need to
# check that here.
# The backup manager has already checked that the backup exists so we don't
# need to catch BackupNotFound here.
backup = await manager.backup_agents[agent_id].async_get_backup(backup_id)
if (
# Check for None to be backwards compatible with the old BackupAgent API,
# this can be removed in HA Core 2025.10
backup
and restore_homeassistant
and restore_database != backup.database_included