-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions_flow.py
More file actions
56 lines (46 loc) · 1.94 KB
/
options_flow.py
File metadata and controls
56 lines (46 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Options flow for Microsoft 365 OneDrive."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.data_entry_flow import FlowResult
DEFAULT_BACKUP_FOLDER = "Home Assistant Backups"
DEFAULT_MAX_BACKUPS = 10
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle an options flow for Microsoft 365 OneDrive."""
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage the options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
# Get current options
backup_folder = self.config_entry.options.get(
"backup_folder", DEFAULT_BACKUP_FOLDER
)
max_backups = self.config_entry.options.get(
"max_backups", DEFAULT_MAX_BACKUPS
)
auto_cleanup = self.config_entry.options.get(
"auto_cleanup", True
)
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Required("backup_folder", default=backup_folder): str,
vol.Optional("max_backups", default=max_backups): vol.All(
int, vol.Range(min=1, max=100)
),
vol.Optional("auto_cleanup", default=auto_cleanup): bool,
}
),
description_placeholders={
"backup_folder_desc": "The OneDrive folder where backups will be stored",
"max_backups_desc": "Maximum number of backups to keep (oldest will be deleted)",
"auto_cleanup_desc": "Automatically delete old backups when max is reached",
},
)