mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Abort SABnzbd config flow when instance already configured (#131607)
This commit is contained in:
parent
1539558935
commit
b800db9f52
@ -64,6 +64,13 @@ class SABnzbdConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if not sab_api:
|
if not sab_api:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
else:
|
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:
|
if self.source == SOURCE_RECONFIGURE:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._get_reconfigure_entry(), data_updates=user_input
|
self._get_reconfigure_entry(), data_updates=user_input
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]"
|
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -132,3 +132,38 @@ async def test_reconfigure_error(
|
|||||||
CONF_URL: "http://10.10.10.10:8080",
|
CONF_URL: "http://10.10.10.10:8080",
|
||||||
CONF_API_KEY: "new_key",
|
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user