Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Backup integration."""
2 
3 from homeassistant.core import HomeAssistant, ServiceCall
4 from homeassistant.helpers import config_validation as cv
5 from homeassistant.helpers.hassio import is_hassio
6 from homeassistant.helpers.typing import ConfigType
7 
8 from .const import DATA_MANAGER, DOMAIN, LOGGER
9 from .http import async_register_http_views
10 from .manager import BackupManager
11 from .websocket import async_register_websocket_handlers
12 
13 CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
14 
15 
16 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
17  """Set up the Backup integration."""
18  backup_manager = BackupManager(hass)
19  hass.data[DATA_MANAGER] = backup_manager
20 
21  with_hassio = is_hassio(hass)
22 
23  async_register_websocket_handlers(hass, with_hassio)
24 
25  if with_hassio:
26  if DOMAIN in config:
27  LOGGER.error(
28  "The backup integration is not supported on this installation method, "
29  "please remove it from your configuration"
30  )
31  return True
32 
33  async def async_handle_create_service(call: ServiceCall) -> None:
34  """Service handler for creating backups."""
35  await backup_manager.async_create_backup()
36 
37  hass.services.async_register(DOMAIN, "create", async_handle_create_service)
38 
40 
41  return True
None async_register_http_views(HomeAssistant hass)
Definition: http.py:21
None async_register_websocket_handlers(HomeAssistant hass, bool with_hassio)
Definition: websocket.py:14
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:16
bool is_hassio(HomeAssistant hass)
Definition: __init__.py:302