Abort SABnzbd config flow when instance already configured (#131607)

This commit is contained in:
Jan-Philipp Benecke 2024-11-26 10:33:01 +01:00 committed by GitHub
parent 1539558935
commit b800db9f52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 0 deletions

View File

@ -64,6 +64,13 @@ class SABnzbdConfigFlow(ConfigFlow, domain=DOMAIN):
if not sab_api:
errors["base"] = "cannot_connect"
else:
self._async_abort_entries_match(
{
CONF_URL: user_input[CONF_URL],
CONF_API_KEY: user_input[CONF_API_KEY],
}
)
if self.source == SOURCE_RECONFIGURE:
return self.async_update_reload_and_abort(
self._get_reconfigure_entry(), data_updates=user_input

View File

@ -17,6 +17,7 @@
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
}
},

View File

@ -132,3 +132,38 @@ async def test_reconfigure_error(
CONF_URL: "http://10.10.10.10:8080",
CONF_API_KEY: "new_key",
}
async def test_abort_already_configured(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test that the flow aborts if SABnzbd instance is already configured."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
VALID_CONFIG,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
async def test_abort_reconfigure_already_configured(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test that the reconfigure flow aborts if SABnzbd instance is already configured."""
result = await config_entry.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
VALID_CONFIG,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"