core/homeassistant/components/kitchen_sink/config_flow.py

164 lines
5.0 KiB
Python
Raw Normal View History

"""Config flow to configure the Kitchen Sink component."""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
Merge config subentry feature branch to dev (#136121) * Reapply "Add support for subentries to config entries" (#133470) (#136061) * Reapply "Add support for subentries to config entries" (#133470) This reverts commit ecb3bf79f32a2e25d141ff467e5958826ed9fc3a. * Update test snapshot * Add config subentry support to device registry (#128157) * Add config subentry support to device registry * Apply suggestions from code review * Update syrupy serializer * Update snapshots * Address review comments * Allow a device to be connected to no or a single subentry of a config entry * Update snapshots * Revert "Allow a device to be connected to no or a single subentry of a config entry" This reverts commit ec6f613151cb4a806b7961033c004b71b76510c2. * Update test snapshots * Bump release version in comments * Rename config_subentries to config_entries_subentries * Add config subentry support to entity registry (#128155) * Add config subentry support to entity registry * Update syrupy serializer * Update snapshots * Update snapshots * Accept suggested changes * Clean registries when removing subentry (#136671) * Clean up registries when removing subentry * Update tests * Clean up subentries from deleted devices when removing config entry (#136669) * Clean up subentries from deleted devices when removing config entry * Move * Add config subentry support to entity platform (#128161) * Add config subentry support to entity platform * Rename subentry_id to config_subentry_id * Store subentry type in subentry (#136687) * Add reconfigure support to config subentries (#133353) * Add reconfigure support to config subentries * Update test * Minor adjustment * Rename supported_subentry_flows to supported_subentry_types * Address review comments * Add subentry support to kitchen sink (#136755) * Add subentry support to kitchen sink * Add subentry reconfigure support to kitchen_sink * Update kitchen_sink tests with subentry type stored in config entry * Update kitchen_sink * Update kitchen_sink * Adjust kitchen sink tests * Fix hassfest * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Improve docstrings and strings.json --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-10 15:40:07 +00:00
ConfigSubentryFlow,
OptionsFlow,
Merge config subentry feature branch to dev (#136121) * Reapply "Add support for subentries to config entries" (#133470) (#136061) * Reapply "Add support for subentries to config entries" (#133470) This reverts commit ecb3bf79f32a2e25d141ff467e5958826ed9fc3a. * Update test snapshot * Add config subentry support to device registry (#128157) * Add config subentry support to device registry * Apply suggestions from code review * Update syrupy serializer * Update snapshots * Address review comments * Allow a device to be connected to no or a single subentry of a config entry * Update snapshots * Revert "Allow a device to be connected to no or a single subentry of a config entry" This reverts commit ec6f613151cb4a806b7961033c004b71b76510c2. * Update test snapshots * Bump release version in comments * Rename config_subentries to config_entries_subentries * Add config subentry support to entity registry (#128155) * Add config subentry support to entity registry * Update syrupy serializer * Update snapshots * Update snapshots * Accept suggested changes * Clean registries when removing subentry (#136671) * Clean up registries when removing subentry * Update tests * Clean up subentries from deleted devices when removing config entry (#136669) * Clean up subentries from deleted devices when removing config entry * Move * Add config subentry support to entity platform (#128161) * Add config subentry support to entity platform * Rename subentry_id to config_subentry_id * Store subentry type in subentry (#136687) * Add reconfigure support to config subentries (#133353) * Add reconfigure support to config subentries * Update test * Minor adjustment * Rename supported_subentry_flows to supported_subentry_types * Address review comments * Add subentry support to kitchen sink (#136755) * Add subentry support to kitchen sink * Add subentry reconfigure support to kitchen_sink * Update kitchen_sink tests with subentry type stored in config entry * Update kitchen_sink * Update kitchen_sink * Adjust kitchen sink tests * Fix hassfest * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Improve docstrings and strings.json --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-10 15:40:07 +00:00
SubentryFlowResult,
)
from homeassistant.core import callback
from . import DOMAIN
CONF_BOOLEAN = "bool"
CONF_INT = "int"
class KitchenSinkConfigFlow(ConfigFlow, domain=DOMAIN):
"""Kitchen Sink configuration flow."""
VERSION = 1
@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
) -> OptionsFlowHandler:
"""Get the options flow for this handler."""
return OptionsFlowHandler()
Merge config subentry feature branch to dev (#136121) * Reapply "Add support for subentries to config entries" (#133470) (#136061) * Reapply "Add support for subentries to config entries" (#133470) This reverts commit ecb3bf79f32a2e25d141ff467e5958826ed9fc3a. * Update test snapshot * Add config subentry support to device registry (#128157) * Add config subentry support to device registry * Apply suggestions from code review * Update syrupy serializer * Update snapshots * Address review comments * Allow a device to be connected to no or a single subentry of a config entry * Update snapshots * Revert "Allow a device to be connected to no or a single subentry of a config entry" This reverts commit ec6f613151cb4a806b7961033c004b71b76510c2. * Update test snapshots * Bump release version in comments * Rename config_subentries to config_entries_subentries * Add config subentry support to entity registry (#128155) * Add config subentry support to entity registry * Update syrupy serializer * Update snapshots * Update snapshots * Accept suggested changes * Clean registries when removing subentry (#136671) * Clean up registries when removing subentry * Update tests * Clean up subentries from deleted devices when removing config entry (#136669) * Clean up subentries from deleted devices when removing config entry * Move * Add config subentry support to entity platform (#128161) * Add config subentry support to entity platform * Rename subentry_id to config_subentry_id * Store subentry type in subentry (#136687) * Add reconfigure support to config subentries (#133353) * Add reconfigure support to config subentries * Update test * Minor adjustment * Rename supported_subentry_flows to supported_subentry_types * Address review comments * Add subentry support to kitchen sink (#136755) * Add subentry support to kitchen sink * Add subentry reconfigure support to kitchen_sink * Update kitchen_sink tests with subentry type stored in config entry * Update kitchen_sink * Update kitchen_sink * Adjust kitchen sink tests * Fix hassfest * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Improve docstrings and strings.json --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-10 15:40:07 +00:00
@classmethod
@callback
def async_get_supported_subentry_types(
cls, config_entry: ConfigEntry
) -> dict[str, type[ConfigSubentryFlow]]:
"""Return subentries supported by this handler."""
return {"entity": SubentryFlowHandler}
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Set the config entry up from yaml."""
return self.async_create_entry(title="Kitchen Sink", data=import_data)
async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Reauth step."""
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Reauth confirm step."""
if user_input is None:
return self.async_show_form(step_id="reauth_confirm")
return self.async_abort(reason="reauth_successful")
class OptionsFlowHandler(OptionsFlow):
"""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:
return self.async_create_entry(data=self.config_entry.options | user_input)
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},
),
}
),
)
Merge config subentry feature branch to dev (#136121) * Reapply "Add support for subentries to config entries" (#133470) (#136061) * Reapply "Add support for subentries to config entries" (#133470) This reverts commit ecb3bf79f32a2e25d141ff467e5958826ed9fc3a. * Update test snapshot * Add config subentry support to device registry (#128157) * Add config subentry support to device registry * Apply suggestions from code review * Update syrupy serializer * Update snapshots * Address review comments * Allow a device to be connected to no or a single subentry of a config entry * Update snapshots * Revert "Allow a device to be connected to no or a single subentry of a config entry" This reverts commit ec6f613151cb4a806b7961033c004b71b76510c2. * Update test snapshots * Bump release version in comments * Rename config_subentries to config_entries_subentries * Add config subentry support to entity registry (#128155) * Add config subentry support to entity registry * Update syrupy serializer * Update snapshots * Update snapshots * Accept suggested changes * Clean registries when removing subentry (#136671) * Clean up registries when removing subentry * Update tests * Clean up subentries from deleted devices when removing config entry (#136669) * Clean up subentries from deleted devices when removing config entry * Move * Add config subentry support to entity platform (#128161) * Add config subentry support to entity platform * Rename subentry_id to config_subentry_id * Store subentry type in subentry (#136687) * Add reconfigure support to config subentries (#133353) * Add reconfigure support to config subentries * Update test * Minor adjustment * Rename supported_subentry_flows to supported_subentry_types * Address review comments * Add subentry support to kitchen sink (#136755) * Add subentry support to kitchen sink * Add subentry reconfigure support to kitchen_sink * Update kitchen_sink tests with subentry type stored in config entry * Update kitchen_sink * Update kitchen_sink * Adjust kitchen sink tests * Fix hassfest * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Improve docstrings and strings.json --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-10 15:40:07 +00:00
class SubentryFlowHandler(ConfigSubentryFlow):
"""Handle subentry flow."""
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> SubentryFlowResult:
"""User flow to create a sensor subentry."""
return await self.async_step_add_sensor()
async def async_step_add_sensor(
self, user_input: dict[str, Any] | None = None
) -> SubentryFlowResult:
"""Add a new sensor."""
if user_input is not None:
title = user_input.pop("name")
return self.async_create_entry(data=user_input, title=title)
return self.async_show_form(
step_id="add_sensor",
data_schema=vol.Schema(
{
vol.Required("name"): str,
vol.Required("state"): int,
}
),
)
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> SubentryFlowResult:
"""Reconfigure a sensor subentry."""
return await self.async_step_reconfigure_sensor()
async def async_step_reconfigure_sensor(
self, user_input: dict[str, Any] | None = None
) -> SubentryFlowResult:
"""Reconfigure a sensor."""
if user_input is not None:
title = user_input.pop("name")
return self.async_update_and_abort(
self._get_reconfigure_entry(),
self._get_reconfigure_subentry(),
data=user_input,
title=title,
)
return self.async_show_form(
step_id="reconfigure_sensor",
data_schema=vol.Schema(
{
vol.Required("name"): str,
vol.Required("state"): int,
}
),
)