mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Skip check for entry updated by current flow in _async_abort_entries_match (#141003)
* Ignore entries with source reconfigure in _async_abort_entries_match * Exclude reconfigure and reauth entry from match check * Add tests * Fix tests for other components * Revert unrelated changes * Update docstring * Make test more realistic * Change name and docstring for sabnzbd test --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
3e0e807c96
commit
b6c4b06fc7
@ -2839,10 +2839,16 @@ class ConfigFlow(ConfigEntryBaseFlow):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Abort if current entries match all data.
|
"""Abort if current entries match all data.
|
||||||
|
|
||||||
|
Do not abort for the entry that is being updated by the current flow.
|
||||||
Requires `already_configured` in strings.json in user visible flows.
|
Requires `already_configured` in strings.json in user visible flows.
|
||||||
"""
|
"""
|
||||||
_async_abort_entries_match(
|
_async_abort_entries_match(
|
||||||
self._async_current_entries(include_ignore=False), match_dict
|
[
|
||||||
|
entry
|
||||||
|
for entry in self._async_current_entries(include_ignore=False)
|
||||||
|
if entry.entry_id != self.context.get("entry_id")
|
||||||
|
],
|
||||||
|
match_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -217,7 +217,7 @@ async def test_reauth_with_existing_config(hass: HomeAssistant) -> None:
|
|||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_API_KEY: "MYAPIKEY2",
|
CONF_API_KEY: MOCK_CONFIG[CONF_API_KEY],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -153,10 +153,10 @@ async def test_abort_already_configured(
|
|||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_reconfigure_already_configured(
|
async def test_abort_reconfigure_successful(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that the reconfigure flow aborts if SABnzbd instance is already configured."""
|
"""Test that the reconfigure flow aborts successfully if SABnzbd instance is already configured."""
|
||||||
result = await config_entry.start_reconfigure_flow(hass)
|
result = await config_entry.start_reconfigure_flow(hass)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
@ -166,4 +166,4 @@ async def test_abort_reconfigure_already_configured(
|
|||||||
VALID_CONFIG,
|
VALID_CONFIG,
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
@ -5268,6 +5268,52 @@ async def test_async_abort_entries_match(
|
|||||||
assert result["reason"] == reason
|
assert result["reason"] == reason
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("matchers", "reason"),
|
||||||
|
[
|
||||||
|
({"host": "3.4.5.6", "ip": "1.2.3.4", "port": 23}, "no_match"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_async_abort_entries_match_context(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
manager: config_entries.ConfigEntries,
|
||||||
|
matchers: dict[str, str],
|
||||||
|
reason: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test aborting if matching config entries exist."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain="comp", data={"ip": "1.2.3.4", "host": "3.4.5.6", "port": 23}
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
mock_setup_entry = AsyncMock(return_value=True)
|
||||||
|
mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry))
|
||||||
|
mock_platform(hass, "comp.config_flow", None)
|
||||||
|
|
||||||
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
|
"""Test flow."""
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
|
||||||
|
async def async_step_reconfigure(self, user_input=None):
|
||||||
|
"""Test user step."""
|
||||||
|
self._async_abort_entries_match(matchers)
|
||||||
|
return self.async_abort(reason="no_match")
|
||||||
|
|
||||||
|
with mock_config_flow("comp", TestFlow), mock_config_flow("invalid_flow", 5):
|
||||||
|
result = await manager.flow.async_init(
|
||||||
|
"comp",
|
||||||
|
context={
|
||||||
|
"source": config_entries.SOURCE_RECONFIGURE,
|
||||||
|
"entry_id": entry.entry_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.ABORT
|
||||||
|
assert result["reason"] == reason
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("matchers", "reason"),
|
("matchers", "reason"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user