diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 78b54929015..a3b03407a14 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -from collections import ChainMap from collections.abc import Callable, Coroutine, Generator, Iterable, Mapping from contextvars import ContextVar from copy import deepcopy @@ -1465,14 +1464,12 @@ def _async_abort_entries_match( if match_dict is None: match_dict = {} # Match any entry for entry in other_entries: - if all( - item - in ChainMap( - entry.options, # type: ignore[arg-type] - entry.data, # type: ignore[arg-type] - ).items() - for item in match_dict.items() - ): + options_items = entry.options.items() + data_items = entry.data.items() + for kv in match_dict.items(): + if kv not in options_items and kv not in data_items: + break + else: raise data_entry_flow.AbortFlow("already_configured") diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 680adcf1202..75b6377973b 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -3379,11 +3379,13 @@ async def test_setup_retrying_during_shutdown(hass: HomeAssistant) -> None: ({"vendor": "zoo"}, "already_configured"), ({"ip": "9.9.9.9"}, "already_configured"), ({"ip": "7.7.7.7"}, "no_match"), # ignored - ({"vendor": "data"}, "no_match"), + # The next two data sets ensure options or data match + # as options previously shadowed data when matching. + ({"vendor": "data"}, "already_configured"), ( {"vendor": "options"}, "already_configured", - ), # ensure options takes precedence over data + ), ], ) async def test__async_abort_entries_match( @@ -3460,11 +3462,13 @@ async def test__async_abort_entries_match( ({"vendor": "zoo"}, "already_configured"), ({"ip": "9.9.9.9"}, "already_configured"), ({"ip": "7.7.7.7"}, "no_match"), # ignored - ({"vendor": "data"}, "no_match"), + # The next two data sets ensure options or data match + # as options previously shadowed data when matching. + ({"vendor": "data"}, "already_configured"), ( {"vendor": "options"}, "already_configured", - ), # ensure options takes precedence over data + ), ], ) async def test__async_abort_entries_match_options_flow(