mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Abort nexia import if the username is already configured (#34863)
This commit is contained in:
parent
6ce0819287
commit
97c82089b4
@ -88,6 +88,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_import(self, user_input):
|
async def async_step_import(self, user_input):
|
||||||
"""Handle import."""
|
"""Handle import."""
|
||||||
|
for entry in self._async_current_entries():
|
||||||
|
if entry.data[CONF_USERNAME] == user_input[CONF_USERNAME]:
|
||||||
|
return self.async_abort(reason="already_configured")
|
||||||
return await self.async_step_user(user_input)
|
return await self.async_step_user(user_input)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"domain": "nexia",
|
"domain": "nexia",
|
||||||
"name": "Nexia",
|
"name": "Nexia",
|
||||||
"requirements": ["nexia==0.9.2"],
|
"requirements": ["nexia==0.9.3"],
|
||||||
"codeowners": ["@ryannazaretian", "@bdraco"],
|
"codeowners": ["@ryannazaretian", "@bdraco"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/nexia",
|
"documentation": "https://www.home-assistant.io/integrations/nexia",
|
||||||
"config_flow": true
|
"config_flow": true
|
||||||
|
@ -931,7 +931,7 @@ netdisco==2.6.0
|
|||||||
neurio==0.3.1
|
neurio==0.3.1
|
||||||
|
|
||||||
# homeassistant.components.nexia
|
# homeassistant.components.nexia
|
||||||
nexia==0.9.2
|
nexia==0.9.3
|
||||||
|
|
||||||
# homeassistant.components.nextcloud
|
# homeassistant.components.nextcloud
|
||||||
nextcloudmonitor==1.1.0
|
nextcloudmonitor==1.1.0
|
||||||
|
@ -366,7 +366,7 @@ nessclient==0.9.15
|
|||||||
netdisco==2.6.0
|
netdisco==2.6.0
|
||||||
|
|
||||||
# homeassistant.components.nexia
|
# homeassistant.components.nexia
|
||||||
nexia==0.9.2
|
nexia==0.9.3
|
||||||
|
|
||||||
# homeassistant.components.nsw_fuel_station
|
# homeassistant.components.nsw_fuel_station
|
||||||
nsw-fuel-api-client==1.0.10
|
nsw-fuel-api-client==1.0.10
|
||||||
|
@ -74,3 +74,44 @@ async def test_form_cannot_connect(hass):
|
|||||||
|
|
||||||
assert result2["type"] == "form"
|
assert result2["type"] == "form"
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_import(hass):
|
||||||
|
"""Test we get the form with import source."""
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.nexia.config_flow.NexiaHome.get_name",
|
||||||
|
return_value="myhouse",
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.nexia.config_flow.NexiaHome.login",
|
||||||
|
side_effect=MagicMock(),
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.nexia.async_setup", return_value=True
|
||||||
|
) as mock_setup, patch(
|
||||||
|
"homeassistant.components.nexia.async_setup_entry", return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_IMPORT},
|
||||||
|
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "create_entry"
|
||||||
|
assert result["title"] == "myhouse"
|
||||||
|
assert result["data"] == {
|
||||||
|
CONF_USERNAME: "username",
|
||||||
|
CONF_PASSWORD: "password",
|
||||||
|
}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
result2 = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_IMPORT},
|
||||||
|
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result2["type"] == "abort"
|
||||||
|
assert result2["reason"] == "already_configured"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user