Skip to content

Commit

Permalink
Fix duplicate check on onewire config flow (home-assistant#43590)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Nov 24, 2020
1 parent acb94b0 commit 48d9f1a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/onewire/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def is_duplicate_owserver_entry(hass: HomeAssistantType, user_input):
if (
config_entry.data[CONF_TYPE] == CONF_TYPE_OWSERVER
and config_entry.data[CONF_HOST] == user_input[CONF_HOST]
and config_entry.data[CONF_PORT] == str(user_input[CONF_PORT])
and config_entry.data[CONF_PORT] == user_input[CONF_PORT]
):
return True
return False
Expand Down
6 changes: 2 additions & 4 deletions tests/components/onewire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ async def setup_onewire_owserver_integration(hass):
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
CONF_PORT: 1234,
},
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
connection_class=CONN_CLASS_LOCAL_POLL,
options={},
entry_id="2",
Expand All @@ -74,12 +73,11 @@ async def setup_onewire_patched_owserver_integration(hass):
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
CONF_PORT: 1234,
CONF_NAMES: {
"10.111111111111": "My DS18B20",
},
},
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
connection_class=CONN_CLASS_LOCAL_POLL,
options={},
entry_id="2",
Expand Down
33 changes: 31 additions & 2 deletions tests/components/onewire/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,45 @@ async def test_import_owserver_with_port(hass):
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
CONF_PORT: 1234,
},
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "1.2.3.4"
assert result["data"] == {
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: "1234",
CONF_PORT: 1234,
}
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1


async def test_import_owserver_duplicate(hass):
"""Test OWServer flow."""
# Initialise with single entry
with patch(
"homeassistant.components.onewire.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.onewire.async_setup_entry",
return_value=True,
) as mock_setup_entry:
await setup_onewire_owserver_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1

# Import duplicate entry
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_TYPE: CONF_TYPE_OWSERVER,
CONF_HOST: "1.2.3.4",
CONF_PORT: 1234,
},
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1

0 comments on commit 48d9f1a

Please sign in to comment.