mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Align google_drive with changes in BackupAgent (#139767)
This commit is contained in:
parent
7359013db0
commit
3b9bb96784
@ -8,7 +8,12 @@ from typing import Any
|
||||
|
||||
from google_drive_api.exceptions import GoogleDriveApiError
|
||||
|
||||
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.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.aiohttp_client import ChunkAsyncStreamIterator
|
||||
@ -93,13 +98,13 @@ class GoogleDriveBackupAgent(BackupAgent):
|
||||
self,
|
||||
backup_id: str,
|
||||
**kwargs: Any,
|
||||
) -> AgentBackup | None:
|
||||
) -> AgentBackup:
|
||||
"""Return a backup."""
|
||||
backups = await self.async_list_backups()
|
||||
for backup in backups:
|
||||
if backup.backup_id == backup_id:
|
||||
return backup
|
||||
return None
|
||||
raise BackupNotFound(f"Backup {backup_id} not found")
|
||||
|
||||
async def async_download_backup(
|
||||
self,
|
||||
@ -120,7 +125,7 @@ class GoogleDriveBackupAgent(BackupAgent):
|
||||
return ChunkAsyncStreamIterator(stream)
|
||||
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
|
||||
raise BackupAgentError(f"Failed to download backup: {err}") from err
|
||||
raise BackupAgentError("Backup not found")
|
||||
raise BackupNotFound(f"Backup {backup_id} not found")
|
||||
|
||||
async def async_delete_backup(
|
||||
self,
|
||||
@ -138,5 +143,7 @@ class GoogleDriveBackupAgent(BackupAgent):
|
||||
_LOGGER.debug("Deleting file_id: %s", file_id)
|
||||
await self._client.async_delete(file_id)
|
||||
_LOGGER.debug("Deleted backup_id: %s", backup_id)
|
||||
return
|
||||
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
|
||||
raise BackupAgentError(f"Failed to delete backup: {err}") from err
|
||||
raise BackupNotFound(f"Backup {backup_id} not found")
|
||||
|
@ -247,9 +247,9 @@ async def test_agents_download_file_not_found(
|
||||
resp = await client.get(
|
||||
f"/api/backup/download/{TEST_AGENT_BACKUP.backup_id}?agent_id={TEST_AGENT_ID}"
|
||||
)
|
||||
assert resp.status == 500
|
||||
assert resp.status == 404
|
||||
content = await resp.content.read()
|
||||
assert "Backup not found" in content.decode()
|
||||
assert content == b""
|
||||
|
||||
|
||||
async def test_agents_download_metadata_not_found(
|
||||
|
Loading…
x
Reference in New Issue
Block a user