2023-01-16 10:03:44 +00:00
|
|
|
"""Config flow to configure the Kitchen Sink component."""
|
2024-03-08 14:01:29 +00:00
|
|
|
|
2023-01-16 10:03:44 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-08-28 11:01:00 +00:00
|
|
|
from collections.abc import Mapping
|
2023-01-16 10:03:44 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2024-06-25 09:02:00 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant import data_entry_flow
|
|
|
|
from homeassistant.config_entries import (
|
|
|
|
ConfigEntry,
|
|
|
|
ConfigFlow,
|
|
|
|
ConfigFlowResult,
|
|
|
|
OptionsFlowWithConfigEntry,
|
|
|
|
)
|
|
|
|
from homeassistant.core import callback
|
2023-01-16 10:03:44 +00:00
|
|
|
|
|
|
|
from . import DOMAIN
|
|
|
|
|
2024-06-25 09:02:00 +00:00
|
|
|
CONF_BOOLEAN = "bool"
|
|
|
|
CONF_INT = "int"
|
|
|
|
|
2023-01-16 10:03:44 +00:00
|
|
|
|
2024-02-29 19:08:46 +00:00
|
|
|
class KitchenSinkConfigFlow(ConfigFlow, domain=DOMAIN):
|
2023-01-16 10:03:44 +00:00
|
|
|
"""Kitchen Sink configuration flow."""
|
|
|
|
|
|
|
|
VERSION = 1
|
|
|
|
|
2024-06-25 09:02:00 +00:00
|
|
|
@staticmethod
|
|
|
|
@callback
|
|
|
|
def async_get_options_flow(
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
) -> OptionsFlowHandler:
|
|
|
|
"""Get the options flow for this handler."""
|
|
|
|
return OptionsFlowHandler(config_entry)
|
|
|
|
|
2024-08-27 08:34:47 +00:00
|
|
|
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
2023-01-16 10:03:44 +00:00
|
|
|
"""Set the config entry up from yaml."""
|
2024-08-27 08:34:47 +00:00
|
|
|
return self.async_create_entry(title="Kitchen Sink", data=import_data)
|
2024-01-31 19:40:26 +00:00
|
|
|
|
2024-08-28 11:01:00 +00:00
|
|
|
async def async_step_reauth(
|
|
|
|
self, entry_data: Mapping[str, Any]
|
|
|
|
) -> ConfigFlowResult:
|
2024-01-31 19:40:26 +00:00
|
|
|
"""Reauth step."""
|
|
|
|
return await self.async_step_reauth_confirm()
|
|
|
|
|
2024-08-30 09:05:18 +00:00
|
|
|
async def async_step_reauth_confirm(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
) -> ConfigFlowResult:
|
2024-01-31 19:40:26 +00:00
|
|
|
"""Reauth confirm step."""
|
|
|
|
if user_input is None:
|
|
|
|
return self.async_show_form(step_id="reauth_confirm")
|
|
|
|
return self.async_abort(reason="reauth_successful")
|
2024-06-25 09:02:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OptionsFlowHandler(OptionsFlowWithConfigEntry):
|
|
|
|
"""Handle options."""
|
|
|
|
|
|
|
|
async def async_step_init(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
) -> ConfigFlowResult:
|
|
|
|
"""Manage the options."""
|
|
|
|
return await self.async_step_options_1()
|
|
|
|
|
|
|
|
async def async_step_options_1(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
) -> ConfigFlowResult:
|
|
|
|
"""Manage the options."""
|
|
|
|
if user_input is not None:
|
|
|
|
self.options.update(user_input)
|
|
|
|
return await self._update_options()
|
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="options_1",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required("section_1"): data_entry_flow.section(
|
|
|
|
vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Optional(
|
|
|
|
CONF_BOOLEAN,
|
|
|
|
default=self.config_entry.options.get(
|
|
|
|
CONF_BOOLEAN, False
|
|
|
|
),
|
|
|
|
): bool,
|
|
|
|
vol.Optional(
|
|
|
|
CONF_INT,
|
|
|
|
default=self.config_entry.options.get(CONF_INT, 10),
|
|
|
|
): int,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
{"collapsed": False},
|
|
|
|
),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
async def _update_options(self) -> ConfigFlowResult:
|
|
|
|
"""Update config entry options."""
|
|
|
|
return self.async_create_entry(title="", data=self.options)
|