1 """Websocket commands for the Backup integration."""
5 import voluptuous
as vol
10 from .const
import DATA_MANAGER, LOGGER
15 """Register websocket commands."""
17 websocket_api.async_register_command(hass, handle_backup_end)
18 websocket_api.async_register_command(hass, handle_backup_start)
21 websocket_api.async_register_command(hass, handle_details)
22 websocket_api.async_register_command(hass, handle_info)
23 websocket_api.async_register_command(hass, handle_create)
24 websocket_api.async_register_command(hass, handle_remove)
25 websocket_api.async_register_command(hass, handle_restore)
28 @websocket_api.require_admin
29 @websocket_api.websocket_command({vol.Required("type"):
"backup/info"})
30 @websocket_api.async_response
36 """List all stored backups."""
37 manager = hass.data[DATA_MANAGER]
38 backups = await manager.async_get_backups()
39 connection.send_result(
42 "backups":
list(backups.values()),
43 "backing_up": manager.backing_up,
48 @websocket_api.require_admin
49 @websocket_api.websocket_command(
{
vol.Required("type"):
"backup/details",
50 vol.Required(
"slug"): str,
53 @websocket_api.async_response
59 """Get backup details for a specific slug."""
60 backup = await hass.data[DATA_MANAGER].async_get_backup(slug=msg[
"slug"])
61 connection.send_result(
69 @websocket_api.require_admin
70 @websocket_api.websocket_command(
{
vol.Required("type"):
"backup/remove",
71 vol.Required(
"slug"): str,
74 @websocket_api.async_response
80 """Remove a backup."""
81 await hass.data[DATA_MANAGER].async_remove_backup(slug=msg[
"slug"])
82 connection.send_result(msg[
"id"])
85 @websocket_api.require_admin
86 @websocket_api.websocket_command(
{
vol.Required("type"):
"backup/restore",
87 vol.Required(
"slug"): str,
90 @websocket_api.async_response
96 """Restore a backup."""
97 await hass.data[DATA_MANAGER].async_restore_backup(msg[
"slug"])
98 connection.send_result(msg[
"id"])
101 @websocket_api.require_admin
102 @websocket_api.websocket_command({vol.Required("type"):
"backup/generate"})
103 @websocket_api.async_response
109 """Generate a backup."""
111 connection.send_result(msg[
"id"], backup)
114 @websocket_api.ws_require_user(only_supervisor=True)
115 @websocket_api.websocket_command({vol.Required("type"):
"backup/start"})
116 @websocket_api.async_response
122 """Backup start notification."""
123 manager = hass.data[DATA_MANAGER]
124 manager.backing_up =
True
125 LOGGER.debug(
"Backup start notification")
128 await manager.async_pre_backup_actions()
129 except Exception
as err:
130 connection.send_error(msg[
"id"],
"pre_backup_actions_failed",
str(err))
133 connection.send_result(msg[
"id"])
136 @websocket_api.ws_require_user(only_supervisor=True)
137 @websocket_api.websocket_command({vol.Required("type"):
"backup/end"})
138 @websocket_api.async_response
144 """Backup end notification."""
145 manager = hass.data[DATA_MANAGER]
146 manager.backing_up =
False
147 LOGGER.debug(
"Backup end notification")
150 await manager.async_post_backup_actions()
151 except Exception
as err:
152 connection.send_error(msg[
"id"],
"post_backup_actions_failed",
str(err))
155 connection.send_result(msg[
"id"])
156
None handle_info(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None handle_backup_start(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None handle_backup_end(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None handle_details(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None handle_remove(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None async_register_websocket_handlers(HomeAssistant hass, bool with_hassio)
None handle_create(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None handle_restore(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
dict async_create_backup(HomeAssistant hass, dict payload, bool partial=False)