From a5644c8ddb9d03f848e646afeddc178b35ec8017 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 27 May 2024 15:39:59 -1000 Subject: [PATCH] Rewrite flow handler to flow result conversion as a list comp (#118269) --- homeassistant/data_entry_flow.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 5a50e95d871..de45702ad95 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -608,19 +608,22 @@ class FlowManager(abc.ABC, Generic[_FlowResultT, _HandlerT]): include_uninitialized: bool, ) -> list[_FlowResultT]: """Convert a list of FlowHandler to a partial FlowResult that can be serialized.""" - results = [] - for flow in flows: - if not include_uninitialized and flow.cur_step is None: - continue - result = self._flow_result( + return [ + self._flow_result( + flow_id=flow.flow_id, + handler=flow.handler, + context=flow.context, + step_id=flow.cur_step["step_id"], + ) + if flow.cur_step + else self._flow_result( flow_id=flow.flow_id, handler=flow.handler, context=flow.context, ) - if flow.cur_step: - result["step_id"] = flow.cur_step["step_id"] - results.append(result) - return results + for flow in flows + if include_uninitialized or flow.cur_step is not None + ] class FlowHandler(Generic[_FlowResultT, _HandlerT]):