Adjust FlowResult construction in data entry flow (#72884)

This commit is contained in:
epenet 2022-06-16 12:57:41 +02:00 committed by GitHub
parent c2b484e38b
commit 67b0354632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,12 +109,12 @@ def _async_flow_handler_to_flow_result(
) -> list[FlowResult]: ) -> list[FlowResult]:
"""Convert a list of FlowHandler to a partial FlowResult that can be serialized.""" """Convert a list of FlowHandler to a partial FlowResult that can be serialized."""
return [ return [
{ FlowResult(
"flow_id": flow.flow_id, flow_id=flow.flow_id,
"handler": flow.handler, handler=flow.handler,
"context": flow.context, context=flow.context,
"step_id": flow.cur_step["step_id"] if flow.cur_step else None, step_id=flow.cur_step["step_id"] if flow.cur_step else None,
} )
for flow in flows for flow in flows
if include_uninitialized or flow.cur_step is not None if include_uninitialized or flow.cur_step is not None
] ]
@ -446,16 +446,16 @@ class FlowHandler:
last_step: bool | None = None, last_step: bool | None = None,
) -> FlowResult: ) -> FlowResult:
"""Return the definition of a form to gather user input.""" """Return the definition of a form to gather user input."""
return { return FlowResult(
"type": FlowResultType.FORM, type=FlowResultType.FORM,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": step_id, step_id=step_id,
"data_schema": data_schema, data_schema=data_schema,
"errors": errors, errors=errors,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
"last_step": last_step, # Display next or submit button in frontend last_step=last_step, # Display next or submit button in frontend
} )
@callback @callback
def async_create_entry( def async_create_entry(
@ -467,16 +467,16 @@ class FlowHandler:
description_placeholders: Mapping[str, str] | None = None, description_placeholders: Mapping[str, str] | None = None,
) -> FlowResult: ) -> FlowResult:
"""Finish config flow and create a config entry.""" """Finish config flow and create a config entry."""
return { return FlowResult(
"version": self.VERSION, version=self.VERSION,
"type": FlowResultType.CREATE_ENTRY, type=FlowResultType.CREATE_ENTRY,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"title": title, title=title,
"data": data, data=data,
"description": description, description=description,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
} )
@callback @callback
def async_abort( def async_abort(
@ -499,24 +499,24 @@ class FlowHandler:
description_placeholders: Mapping[str, str] | None = None, description_placeholders: Mapping[str, str] | None = None,
) -> FlowResult: ) -> FlowResult:
"""Return the definition of an external step for the user to take.""" """Return the definition of an external step for the user to take."""
return { return FlowResult(
"type": FlowResultType.EXTERNAL_STEP, type=FlowResultType.EXTERNAL_STEP,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": step_id, step_id=step_id,
"url": url, url=url,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
} )
@callback @callback
def async_external_step_done(self, *, next_step_id: str) -> FlowResult: def async_external_step_done(self, *, next_step_id: str) -> FlowResult:
"""Return the definition of an external step for the user to take.""" """Return the definition of an external step for the user to take."""
return { return FlowResult(
"type": FlowResultType.EXTERNAL_STEP_DONE, type=FlowResultType.EXTERNAL_STEP_DONE,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": next_step_id, step_id=next_step_id,
} )
@callback @callback
def async_show_progress( def async_show_progress(
@ -527,24 +527,24 @@ class FlowHandler:
description_placeholders: Mapping[str, str] | None = None, description_placeholders: Mapping[str, str] | None = None,
) -> FlowResult: ) -> FlowResult:
"""Show a progress message to the user, without user input allowed.""" """Show a progress message to the user, without user input allowed."""
return { return FlowResult(
"type": FlowResultType.SHOW_PROGRESS, type=FlowResultType.SHOW_PROGRESS,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": step_id, step_id=step_id,
"progress_action": progress_action, progress_action=progress_action,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
} )
@callback @callback
def async_show_progress_done(self, *, next_step_id: str) -> FlowResult: def async_show_progress_done(self, *, next_step_id: str) -> FlowResult:
"""Mark the progress done.""" """Mark the progress done."""
return { return FlowResult(
"type": FlowResultType.SHOW_PROGRESS_DONE, type=FlowResultType.SHOW_PROGRESS_DONE,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": next_step_id, step_id=next_step_id,
} )
@callback @callback
def async_show_menu( def async_show_menu(
@ -558,15 +558,15 @@ class FlowHandler:
Options dict maps step_id => i18n label Options dict maps step_id => i18n label
""" """
return { return FlowResult(
"type": FlowResultType.MENU, type=FlowResultType.MENU,
"flow_id": self.flow_id, flow_id=self.flow_id,
"handler": self.handler, handler=self.handler,
"step_id": step_id, step_id=step_id,
"data_schema": vol.Schema({"next_step_id": vol.In(menu_options)}), data_schema=vol.Schema({"next_step_id": vol.In(menu_options)}),
"menu_options": menu_options, menu_options=menu_options,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
} )
@callback @callback
@ -577,10 +577,10 @@ def _create_abort_data(
description_placeholders: Mapping[str, str] | None = None, description_placeholders: Mapping[str, str] | None = None,
) -> FlowResult: ) -> FlowResult:
"""Return the definition of an external step for the user to take.""" """Return the definition of an external step for the user to take."""
return { return FlowResult(
"type": FlowResultType.ABORT, type=FlowResultType.ABORT,
"flow_id": flow_id, flow_id=flow_id,
"handler": handler, handler=handler,
"reason": reason, reason=reason,
"description_placeholders": description_placeholders, description_placeholders=description_placeholders,
} )