mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add backup.create service (#70118)
This commit is contained in:
parent
725339145f
commit
c460100af1
@ -1,6 +1,6 @@
|
|||||||
"""The Backup integration."""
|
"""The Backup integration."""
|
||||||
from homeassistant.components.hassio import is_hassio
|
from homeassistant.components.hassio import is_hassio
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
@ -18,7 +18,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data[DOMAIN] = BackupManager(hass)
|
backup_manager = BackupManager(hass)
|
||||||
|
hass.data[DOMAIN] = backup_manager
|
||||||
|
|
||||||
|
async def async_handle_create_service(call: ServiceCall) -> None:
|
||||||
|
"""Service handler for creating backups."""
|
||||||
|
await backup_manager.generate_backup()
|
||||||
|
|
||||||
|
hass.services.async_register(DOMAIN, "create", async_handle_create_service)
|
||||||
|
|
||||||
async_register_websocket_handlers(hass)
|
async_register_websocket_handlers(hass)
|
||||||
async_register_http_views(hass)
|
async_register_http_views(hass)
|
||||||
|
3
homeassistant/components/backup/services.yaml
Normal file
3
homeassistant/components/backup/services.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
create:
|
||||||
|
name: Create backup
|
||||||
|
description: Create a new backup.
|
@ -1,6 +1,9 @@
|
|||||||
"""Tests for the Backup integration."""
|
"""Tests for the Backup integration."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.backup.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import setup_backup_integration
|
from .common import setup_backup_integration
|
||||||
@ -16,3 +19,21 @@ async def test_setup_with_hassio(
|
|||||||
"The backup integration is not supported on this installation method, please remove it from your configuration"
|
"The backup integration is not supported on this installation method, please remove it from your configuration"
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_create_service(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
|
"""Test generate backup."""
|
||||||
|
await setup_backup_integration(hass)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.backup.websocket.BackupManager.generate_backup",
|
||||||
|
) as generate_backup:
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
"create",
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert generate_backup.called
|
||||||
|
Loading…
x
Reference in New Issue
Block a user