From c74958dd3622a159c66e5a2e9ece5177093558ce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 19 Feb 2024 02:57:39 -0600 Subject: [PATCH] Reduce one iteration of pending flows in the discovery flow helper (#110918) --- homeassistant/helpers/discovery_flow.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/homeassistant/helpers/discovery_flow.py b/homeassistant/helpers/discovery_flow.py index 7ad9caa5a93..d3e65851deb 100644 --- a/homeassistant/helpers/discovery_flow.py +++ b/homeassistant/helpers/discovery_flow.py @@ -86,17 +86,20 @@ class FlowDispatcher: pending_flows = self.pending_flows self.pending_flows = {} self.started = True - init_coros = [ - _async_init_flow( - self.hass, flow_key.domain, flow_values.context, flow_values.data - ) + init_coros = ( + init_coro for flow_key, flows in pending_flows.items() for flow_values in flows - ] - await gather_with_limited_concurrency( - FLOW_INIT_LIMIT, - *[init_coro for init_coro in init_coros if init_coro is not None], + if ( + init_coro := _async_init_flow( + self.hass, + flow_key.domain, + flow_values.context, + flow_values.data, + ) + ) ) + await gather_with_limited_concurrency(FLOW_INIT_LIMIT, *init_coros) @callback def async_create(self, domain: str, context: dict[str, Any], data: Any) -> None: