mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Teach _async_abort_entries_match about entry options (#66662)
This commit is contained in:
parent
65999227ae
commit
0ec89ae5da
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from collections import ChainMap
|
||||||
from collections.abc import Awaitable, Callable, Iterable, Mapping
|
from collections.abc import Awaitable, Callable, Iterable, Mapping
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
import dataclasses
|
import dataclasses
|
||||||
@ -1211,7 +1212,10 @@ class ConfigFlow(data_entry_flow.FlowHandler):
|
|||||||
if match_dict is None:
|
if match_dict is None:
|
||||||
match_dict = {} # Match any entry
|
match_dict = {} # Match any entry
|
||||||
for entry in self._async_current_entries(include_ignore=False):
|
for entry in self._async_current_entries(include_ignore=False):
|
||||||
if all(item in entry.data.items() for item in match_dict.items()):
|
if all(
|
||||||
|
item in ChainMap(entry.options, entry.data).items() # type: ignore
|
||||||
|
for item in match_dict.items()
|
||||||
|
):
|
||||||
raise data_entry_flow.AbortFlow("already_configured")
|
raise data_entry_flow.AbortFlow("already_configured")
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -2893,12 +2893,23 @@ async def test_setup_retrying_during_shutdown(hass):
|
|||||||
[
|
[
|
||||||
({}, "already_configured"),
|
({}, "already_configured"),
|
||||||
({"host": "3.3.3.3"}, "no_match"),
|
({"host": "3.3.3.3"}, "no_match"),
|
||||||
|
({"vendor": "no_match"}, "no_match"),
|
||||||
({"host": "3.4.5.6"}, "already_configured"),
|
({"host": "3.4.5.6"}, "already_configured"),
|
||||||
({"host": "3.4.5.6", "ip": "3.4.5.6"}, "no_match"),
|
({"host": "3.4.5.6", "ip": "3.4.5.6"}, "no_match"),
|
||||||
({"host": "3.4.5.6", "ip": "1.2.3.4"}, "already_configured"),
|
({"host": "3.4.5.6", "ip": "1.2.3.4"}, "already_configured"),
|
||||||
({"host": "3.4.5.6", "ip": "1.2.3.4", "port": 23}, "already_configured"),
|
({"host": "3.4.5.6", "ip": "1.2.3.4", "port": 23}, "already_configured"),
|
||||||
|
(
|
||||||
|
{"host": "9.9.9.9", "ip": "6.6.6.6", "port": 12, "vendor": "zoo"},
|
||||||
|
"already_configured",
|
||||||
|
),
|
||||||
|
({"vendor": "zoo"}, "already_configured"),
|
||||||
({"ip": "9.9.9.9"}, "already_configured"),
|
({"ip": "9.9.9.9"}, "already_configured"),
|
||||||
({"ip": "7.7.7.7"}, "no_match"), # ignored
|
({"ip": "7.7.7.7"}, "no_match"), # ignored
|
||||||
|
({"vendor": "data"}, "no_match"),
|
||||||
|
(
|
||||||
|
{"vendor": "options"},
|
||||||
|
"already_configured",
|
||||||
|
), # ensure options takes precedence over data
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test__async_abort_entries_match(hass, manager, matchers, reason):
|
async def test__async_abort_entries_match(hass, manager, matchers, reason):
|
||||||
@ -2917,6 +2928,16 @@ async def test__async_abort_entries_match(hass, manager, matchers, reason):
|
|||||||
source=config_entries.SOURCE_IGNORE,
|
source=config_entries.SOURCE_IGNORE,
|
||||||
data={"ip": "7.7.7.7", "host": "4.5.6.7", "port": 23},
|
data={"ip": "7.7.7.7", "host": "4.5.6.7", "port": 23},
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
MockConfigEntry(
|
||||||
|
domain="comp",
|
||||||
|
data={"ip": "6.6.6.6", "host": "9.9.9.9", "port": 12},
|
||||||
|
options={"vendor": "zoo"},
|
||||||
|
).add_to_hass(hass)
|
||||||
|
MockConfigEntry(
|
||||||
|
domain="comp",
|
||||||
|
data={"vendor": "data"},
|
||||||
|
options={"vendor": "options"},
|
||||||
|
).add_to_hass(hass)
|
||||||
|
|
||||||
mock_setup_entry = AsyncMock(return_value=True)
|
mock_setup_entry = AsyncMock(return_value=True)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user