Allow finish_flow callback to change data entry result type (#16100)

* Allow finish_flow callback to change data entry result type

* Add unit test
This commit is contained in:
Jason Hu 2018-08-21 10:48:24 -07:00 committed by GitHub
parent b26506ad4a
commit 00c6f56cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 29 deletions

View file

@ -64,7 +64,7 @@ class FlowManager:
return await self._async_handle_step(flow, flow.init_step, data)
async def async_configure(
self, flow_id: str, user_input: Optional[str] = None) -> Any:
self, flow_id: str, user_input: Optional[Dict] = None) -> Any:
"""Continue a configuration flow."""
flow = self._progress.get(flow_id)
@ -86,7 +86,7 @@ class FlowManager:
raise UnknownFlow
async def _async_handle_step(self, flow: Any, step_id: str,
user_input: Optional[str]) -> Dict:
user_input: Optional[Dict]) -> Dict:
"""Handle a step of a flow."""
method = "async_step_{}".format(step_id)
@ -106,14 +106,17 @@ class FlowManager:
flow.cur_step = (result['step_id'], result['data_schema'])
return result
# We pass a copy of the result because we're mutating our version
result = await self._async_finish_flow(flow, dict(result))
# _async_finish_flow may change result type, check it again
if result['type'] == RESULT_TYPE_FORM:
flow.cur_step = (result['step_id'], result['data_schema'])
return result
# Abort and Success results both finish the flow
self._progress.pop(flow.flow_id)
# We pass a copy of the result because we're mutating our version
entry = await self._async_finish_flow(flow.context, dict(result))
if result['type'] == RESULT_TYPE_CREATE_ENTRY:
result['result'] = entry
return result