mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Store modern_forms flow data in flow handler attributes (#127175)
This commit is contained in:
parent
1dc1fd421b
commit
4c6ab3921a
@ -20,6 +20,10 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
host: str | None = None
|
||||||
|
mac: str | None = None
|
||||||
|
name: str | None = None
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -33,14 +37,10 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
host = discovery_info.hostname.rstrip(".")
|
host = discovery_info.hostname.rstrip(".")
|
||||||
name, _ = host.rsplit(".")
|
name, _ = host.rsplit(".")
|
||||||
|
|
||||||
self.context.update(
|
self.context["title_placeholders"] = {"name": name}
|
||||||
{
|
self.host = discovery_info.host
|
||||||
CONF_HOST: discovery_info.host,
|
self.mac = discovery_info.properties.get(CONF_MAC)
|
||||||
CONF_NAME: name,
|
self.name = name
|
||||||
CONF_MAC: discovery_info.properties.get(CONF_MAC),
|
|
||||||
"title_placeholders": {"name": name},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Prepare configuration flow
|
# Prepare configuration flow
|
||||||
return await self._handle_config_flow({}, True)
|
return await self._handle_config_flow({}, True)
|
||||||
@ -55,7 +55,7 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None, prepare: bool = False
|
self, user_input: dict[str, Any] | None = None, prepare: bool = False
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Config flow handler for ModernForms."""
|
"""Config flow handler for ModernForms."""
|
||||||
source = self.context.get("source")
|
source = self.context["source"]
|
||||||
|
|
||||||
# Request user input, unless we are preparing discovery flow
|
# Request user input, unless we are preparing discovery flow
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
@ -66,8 +66,8 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
return self._show_setup_form()
|
return self._show_setup_form()
|
||||||
|
|
||||||
if source == SOURCE_ZEROCONF:
|
if source == SOURCE_ZEROCONF:
|
||||||
user_input[CONF_HOST] = self.context.get(CONF_HOST)
|
user_input[CONF_HOST] = self.host
|
||||||
user_input[CONF_MAC] = self.context.get(CONF_MAC)
|
user_input[CONF_MAC] = self.mac
|
||||||
|
|
||||||
if user_input.get(CONF_MAC) is None or not prepare:
|
if user_input.get(CONF_MAC) is None or not prepare:
|
||||||
session = async_get_clientsession(self.hass)
|
session = async_get_clientsession(self.hass)
|
||||||
@ -87,7 +87,7 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
title = device.info.device_name
|
title = device.info.device_name
|
||||||
if source == SOURCE_ZEROCONF:
|
if source == SOURCE_ZEROCONF:
|
||||||
title = self.context.get(CONF_NAME)
|
title = self.name
|
||||||
|
|
||||||
if prepare:
|
if prepare:
|
||||||
return await self.async_step_zeroconf_confirm()
|
return await self.async_step_zeroconf_confirm()
|
||||||
@ -107,9 +107,8 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
def _show_confirm_dialog(self, errors: dict | None = None) -> ConfigFlowResult:
|
def _show_confirm_dialog(self, errors: dict | None = None) -> ConfigFlowResult:
|
||||||
"""Show the confirm dialog to the user."""
|
"""Show the confirm dialog to the user."""
|
||||||
name = self.context.get(CONF_NAME)
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="zeroconf_confirm",
|
step_id="zeroconf_confirm",
|
||||||
description_placeholders={"name": name},
|
description_placeholders={"name": self.name},
|
||||||
errors=errors or {},
|
errors=errors or {},
|
||||||
)
|
)
|
||||||
|
@ -84,10 +84,9 @@ async def test_full_zeroconf_flow_implementation(
|
|||||||
assert result.get("step_id") == "zeroconf_confirm"
|
assert result.get("step_id") == "zeroconf_confirm"
|
||||||
assert result.get("type") is FlowResultType.FORM
|
assert result.get("type") is FlowResultType.FORM
|
||||||
|
|
||||||
flow = flows[0]
|
flow = hass.config_entries.flow._progress[flows[0]["flow_id"]]
|
||||||
assert "context" in flow
|
assert flow.host == "192.168.1.123"
|
||||||
assert flow["context"][CONF_HOST] == "192.168.1.123"
|
assert flow.name == "example"
|
||||||
assert flow["context"][CONF_NAME] == "example"
|
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user