mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Address review comments
This commit is contained in:
@@ -45,14 +45,16 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
"""Set up the Backup integration."""
|
"""Set up the Backup integration."""
|
||||||
with_hassio = is_hassio(hass)
|
with_hassio = is_hassio(hass)
|
||||||
|
|
||||||
|
reader_writer: BackupReaderWriter
|
||||||
if not with_hassio:
|
if not with_hassio:
|
||||||
backup_manager = BackupManager(hass, CoreBackupReaderWriter(hass))
|
reader_writer = CoreBackupReaderWriter(hass)
|
||||||
else:
|
else:
|
||||||
# pylint: disable-next=import-outside-toplevel, hass-component-root-import
|
# pylint: disable-next=import-outside-toplevel, hass-component-root-import
|
||||||
from homeassistant.components.hassio.backup import SupervisorBackupReaderWriter
|
from homeassistant.components.hassio.backup import SupervisorBackupReaderWriter
|
||||||
|
|
||||||
backup_manager = BackupManager(hass, SupervisorBackupReaderWriter(hass))
|
reader_writer = SupervisorBackupReaderWriter(hass)
|
||||||
|
|
||||||
|
backup_manager = BackupManager(hass, reader_writer)
|
||||||
hass.data[DATA_MANAGER] = backup_manager
|
hass.data[DATA_MANAGER] = backup_manager
|
||||||
await backup_manager.async_setup()
|
await backup_manager.async_setup()
|
||||||
|
|
||||||
|
@@ -41,6 +41,7 @@ class SupervisorLocalBackupAgent(LocalBackupAgent):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._backup_dir = Path("/backups")
|
self._backup_dir = Path("/backups")
|
||||||
|
self._client = get_supervisor_client(hass)
|
||||||
|
|
||||||
async def async_download_backup(
|
async def async_download_backup(
|
||||||
self,
|
self,
|
||||||
@@ -60,7 +61,7 @@ class SupervisorLocalBackupAgent(LocalBackupAgent):
|
|||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Upload a backup."""
|
"""Upload a backup."""
|
||||||
await get_supervisor_client(self._hass).backups.reload()
|
await self._client.backups.reload()
|
||||||
|
|
||||||
async def async_list_backups(self, **kwargs: Any) -> list[BaseBackup]:
|
async def async_list_backups(self, **kwargs: Any) -> list[BaseBackup]:
|
||||||
"""List backups."""
|
"""List backups."""
|
||||||
@@ -72,7 +73,7 @@ class SupervisorLocalBackupAgent(LocalBackupAgent):
|
|||||||
protected=backup.protected,
|
protected=backup.protected,
|
||||||
size=backup.size,
|
size=backup.size,
|
||||||
)
|
)
|
||||||
for backup in await get_supervisor_client(self._hass).backups.list()
|
for backup in await self._client.backups.list()
|
||||||
]
|
]
|
||||||
|
|
||||||
async def async_get_backup(
|
async def async_get_backup(
|
||||||
@@ -104,6 +105,7 @@ class SupervisorBackupReaderWriter(BackupReaderWriter):
|
|||||||
def __init__(self, hass: HomeAssistant) -> None:
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
"""Initialize the backup reader/writer."""
|
"""Initialize the backup reader/writer."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
|
self._client = get_supervisor_client(hass)
|
||||||
|
|
||||||
async def async_create_backup(
|
async def async_create_backup(
|
||||||
self,
|
self,
|
||||||
@@ -120,8 +122,7 @@ class SupervisorBackupReaderWriter(BackupReaderWriter):
|
|||||||
addons_included_set = set(addons_included) if addons_included else None
|
addons_included_set = set(addons_included) if addons_included else None
|
||||||
folders_included_set = set(folders_included) if folders_included else None
|
folders_included_set = set(folders_included) if folders_included else None
|
||||||
|
|
||||||
client = get_supervisor_client(self._hass)
|
backup = await self._client.backups.partial_backup(
|
||||||
backup = await client.backups.partial_backup(
|
|
||||||
supervisor_backups.PartialBackupOptions(
|
supervisor_backups.PartialBackupOptions(
|
||||||
addons=addons_included_set,
|
addons=addons_included_set,
|
||||||
folders=folders_included_set, # type: ignore[arg-type]
|
folders=folders_included_set, # type: ignore[arg-type]
|
||||||
@@ -157,8 +158,7 @@ class SupervisorBackupReaderWriter(BackupReaderWriter):
|
|||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Restore a backup."""
|
"""Restore a backup."""
|
||||||
client = get_supervisor_client(self._hass)
|
await self._client.backups.partial_restore(
|
||||||
await client.backups.partial_restore(
|
|
||||||
backup_id,
|
backup_id,
|
||||||
supervisor_backups.PartialRestoreOptions(
|
supervisor_backups.PartialRestoreOptions(
|
||||||
addons=None,
|
addons=None,
|
||||||
|
Reference in New Issue
Block a user