Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/components/nexia/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ async def async_step_user(self, user_input=None):

async def async_step_import(self, user_input):
"""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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want this gate in the user step? That way it's covered by import and user.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, on line 82 there is self._abort_if_unique_id_configured(), which should be the same unique ID for old + new config entry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I do think that we might actually want to drop it from line 82, in case someone has changed their auth and needs to re-authenticate. Now that's not possible.

return await self.async_step_user(user_input)


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/nexia/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "nexia",
"name": "Nexia",
"requirements": ["nexia==0.9.2"],
"requirements": ["nexia==0.9.3"],
"codeowners": ["@ryannazaretian", "@bdraco"],
"documentation": "https://www.home-assistant.io/integrations/nexia",
"config_flow": true
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ netdisco==2.6.0
neurio==0.3.1

# homeassistant.components.nexia
nexia==0.9.2
nexia==0.9.3

# homeassistant.components.nextcloud
nextcloudmonitor==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ nessclient==0.9.15
netdisco==2.6.0

# homeassistant.components.nexia
nexia==0.9.2
nexia==0.9.3

# homeassistant.components.nsw_fuel_station
nsw-fuel-api-client==1.0.10
Expand Down
41 changes: 41 additions & 0 deletions tests/components/nexia/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,44 @@ async def test_form_cannot_connect(hass):

assert result2["type"] == "form"
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"