Document changes in BackupAgent API (#2588)

This commit is contained in:
Erik Montnemery 2025-03-04 17:45:57 +01:00 committed by GitHub
parent 52d6fae57e
commit f5ab94a1dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -0,0 +1,12 @@
---
author: Erik Montnemery
authorURL: https://github.com/emontnemery
title: "Changes to the BackupAgent API"
---
The `BackupAgent` API has been adjusted such that the following methods should now raise `BackupNotFound` when a backup is not found:
- `BackupAgent.async_delete_backup`
- `BackupAgent.async_download_backup`
- `BackupAgent.async_get_backup`
Check the backup agent documentation](/docs/core/platform/backup#backup-agents), and the [home assistant core PR #139754](https://github.com/home-assistant/core/pull/139754) for additional background.

View File

@ -81,6 +81,8 @@ class ExampleBackupAgent(BackupAgent):
) -> AsyncIterator[bytes]:
"""Download a backup file.
Raises BackupNotFound if the backup does not exist.
:param backup_id: The ID of the backup that was returned in async_list_backups.
:return: An async iterator that yields bytes.
"""
@ -105,6 +107,8 @@ class ExampleBackupAgent(BackupAgent):
) -> None:
"""Delete a backup file.
Raises BackupNotFound if the backup does not exist.
:param backup_id: The ID of the backup that was returned in async_list_backups.
"""
@ -115,11 +119,14 @@ class ExampleBackupAgent(BackupAgent):
self,
backup_id: str,
**kwargs: Any,
) -> AgentBackup | None:
"""Return a backup."""
) -> AgentBackup:
"""Return a backup.
Raises BackupNotFound if the backup does not exist.
"""
```
Backup agents should raise a `BackupAgentError` exception on error. Other exceptions are not expected to leave the backup agent.
Backup agents should raise a `BackupAgentError` (or a subclass of `BackupAgentError`) exception on error. Other exceptions are not expected to leave the backup agent.
## Pre- and post-operations