diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 63ba565582a..c017744689c 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -201,11 +201,13 @@ class FlowManager(abc.ABC): If match_context is passed, only return flows with a context that is a superset of match_context. """ - return any( - flow - for flow in self._async_progress_by_handler(handler, match_context) - if flow.init_data == data - ) + if not (flows := self._handler_progress_index.get(handler)): + return False + match_items = match_context.items() + for progress in flows: + if match_items <= progress.context.items() and progress.init_data == data: + return True + return False @callback def async_get(self, flow_id: str) -> FlowResult: @@ -265,11 +267,11 @@ class FlowManager(abc.ABC): is a superset of match_context. """ if not match_context: - return list(self._handler_progress_index.get(handler, [])) + return list(self._handler_progress_index.get(handler, ())) match_context_items = match_context.items() return [ progress - for progress in self._handler_progress_index.get(handler, set()) + for progress in self._handler_progress_index.get(handler, ()) if match_context_items <= progress.context.items() ] diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 602b21c15bc..155d78e2c64 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -546,6 +546,14 @@ async def test_async_has_matching_flow( ) -> None: """Test we can check for matching flows.""" manager.hass = hass + assert ( + manager.async_has_matching_flow( + "test", + {"source": config_entries.SOURCE_HOMEKIT}, + {"properties": {"id": "aa:bb:cc:dd:ee:ff"}}, + ) + is False + ) @manager.mock_reg_handler("test") class TestFlow(data_entry_flow.FlowHandler):