This commit is contained in:
J. Nick Koston
2025-10-13 12:48:53 -10:00
parent efc1df4945
commit b2ed6895f7
2 changed files with 34 additions and 13 deletions

View File

@@ -301,6 +301,7 @@ class ConfigFlowResult(FlowResult[ConfigFlowContext, str], total=False):
# Extra keys, only present if type is CREATE_ENTRY
minor_version: int
next_flow: tuple[FlowType, str]
options: Mapping[str, Any]
result: ConfigEntry
subentries: Iterable[ConfigSubentryData]
@@ -3167,6 +3168,37 @@ class ConfigFlow(ConfigEntryBaseFlow):
"""Handle a flow initialized by Zeroconf discovery."""
return await self._async_step_discovery_without_unique_id()
def _async_set_next_flow_if_valid(
self,
result: ConfigFlowResult,
next_flow: tuple[FlowType, str] | None,
) -> None:
"""Validate and set next_flow in result if provided."""
if next_flow is None:
return
flow_type, flow_id = next_flow
if flow_type != FlowType.CONFIG_FLOW:
raise HomeAssistantError("Invalid next_flow type")
# Raises UnknownFlow if the flow does not exist.
self.hass.config_entries.flow.async_get(flow_id)
result["next_flow"] = next_flow
@callback
def async_abort(
self,
*,
reason: str,
description_placeholders: Mapping[str, str] | None = None,
next_flow: tuple[FlowType, str] | None = None,
) -> ConfigFlowResult:
"""Abort the config flow."""
result = super().async_abort(
reason=reason,
description_placeholders=description_placeholders,
)
self._async_set_next_flow_if_valid(result, next_flow)
return result
@callback
def async_create_entry( # type: ignore[override]
self,
@@ -3196,13 +3228,7 @@ class ConfigFlow(ConfigEntryBaseFlow):
)
result["minor_version"] = self.MINOR_VERSION
if next_flow is not None:
flow_type, flow_id = next_flow
if flow_type != FlowType.CONFIG_FLOW:
raise HomeAssistantError("Invalid next_flow type")
# Raises UnknownFlow if the flow does not exist.
self.hass.config_entries.flow.async_get(flow_id)
result["next_flow"] = next_flow
self._async_set_next_flow_if_valid(result, next_flow)
result["options"] = options or {}
result["subentries"] = subentries or ()
result["version"] = self.VERSION

View File

@@ -138,7 +138,6 @@ class FlowResult(TypedDict, Generic[_FlowContextT, _HandlerT], total=False):
handler: Required[_HandlerT]
last_step: bool | None
menu_options: Container[str]
next_flow: tuple[FlowType, str] # (flow type from FlowType, flow id)
preview: str | None
progress_action: str
progress_task: asyncio.Task[Any] | None
@@ -764,19 +763,15 @@ class FlowHandler(Generic[_FlowContextT, _FlowResultT, _HandlerT]):
*,
reason: str,
description_placeholders: Mapping[str, str] | None = None,
next_flow: tuple[str, str] | None = None,
) -> _FlowResultT:
"""Abort the flow."""
result = self._flow_result(
return self._flow_result(
type=FlowResultType.ABORT,
flow_id=self.flow_id,
handler=self.handler,
reason=reason,
description_placeholders=description_placeholders,
)
if next_flow is not None:
result["next_flow"] = next_flow
return result
async def async_step__progress_step_abort(
self, user_input: dict[str, Any] | None = None