mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Align cloud with changes in BackupAgent (#139766)
This commit is contained in:
parent
46ac44c248
commit
95fbba1d74
@ -18,7 +18,12 @@ from hass_nabucasa.cloud_api import (
|
|||||||
)
|
)
|
||||||
from hass_nabucasa.files import FilesError, StorageType, calculate_b64md5
|
from hass_nabucasa.files import FilesError, StorageType, calculate_b64md5
|
||||||
|
|
||||||
from homeassistant.components.backup import AgentBackup, BackupAgent, BackupAgentError
|
from homeassistant.components.backup import (
|
||||||
|
AgentBackup,
|
||||||
|
BackupAgent,
|
||||||
|
BackupAgentError,
|
||||||
|
BackupNotFound,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.aiohttp_client import ChunkAsyncStreamIterator
|
from homeassistant.helpers.aiohttp_client import ChunkAsyncStreamIterator
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
@ -90,9 +95,7 @@ class CloudBackupAgent(BackupAgent):
|
|||||||
:param backup_id: The ID of the backup that was returned in async_list_backups.
|
:param backup_id: The ID of the backup that was returned in async_list_backups.
|
||||||
:return: An async iterator that yields bytes.
|
:return: An async iterator that yields bytes.
|
||||||
"""
|
"""
|
||||||
if not (backup := await self._async_get_backup(backup_id)):
|
backup = await self._async_get_backup(backup_id)
|
||||||
raise BackupAgentError("Backup not found")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = await self._cloud.files.download(
|
content = await self._cloud.files.download(
|
||||||
storage_type=StorageType.BACKUP,
|
storage_type=StorageType.BACKUP,
|
||||||
@ -171,9 +174,7 @@ class CloudBackupAgent(BackupAgent):
|
|||||||
|
|
||||||
:param backup_id: The ID of the backup that was returned in async_list_backups.
|
:param backup_id: The ID of the backup that was returned in async_list_backups.
|
||||||
"""
|
"""
|
||||||
if not (backup := await self._async_get_backup(backup_id)):
|
backup = await self._async_get_backup(backup_id)
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await async_files_delete_file(
|
await async_files_delete_file(
|
||||||
self._cloud,
|
self._cloud,
|
||||||
@ -204,16 +205,12 @@ class CloudBackupAgent(BackupAgent):
|
|||||||
self,
|
self,
|
||||||
backup_id: str,
|
backup_id: str,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> AgentBackup | None:
|
) -> AgentBackup:
|
||||||
"""Return a backup."""
|
"""Return a backup."""
|
||||||
if not (backup := await self._async_get_backup(backup_id)):
|
backup = await self._async_get_backup(backup_id)
|
||||||
return None
|
|
||||||
return AgentBackup.from_dict(backup["Metadata"])
|
return AgentBackup.from_dict(backup["Metadata"])
|
||||||
|
|
||||||
async def _async_get_backup(
|
async def _async_get_backup(self, backup_id: str) -> FilesHandlerListEntry:
|
||||||
self,
|
|
||||||
backup_id: str,
|
|
||||||
) -> FilesHandlerListEntry | None:
|
|
||||||
"""Return a backup."""
|
"""Return a backup."""
|
||||||
backups = await self._async_list_backups()
|
backups = await self._async_list_backups()
|
||||||
|
|
||||||
@ -221,4 +218,4 @@ class CloudBackupAgent(BackupAgent):
|
|||||||
if backup["Metadata"]["backup_id"] == backup_id:
|
if backup["Metadata"]["backup_id"] == backup_id:
|
||||||
return backup
|
return backup
|
||||||
|
|
||||||
return None
|
raise BackupNotFound(f"Backup {backup_id} not found")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user