Fix duplicate check on onewire config flow (#43590)
This commit is contained in:
parent
94f7f70f2d
commit
44c8fce33b
3 changed files with 34 additions and 7 deletions
|
@ -56,7 +56,7 @@ def is_duplicate_owserver_entry(hass: HomeAssistantType, user_input):
|
||||||
if (
|
if (
|
||||||
config_entry.data[CONF_TYPE] == CONF_TYPE_OWSERVER
|
config_entry.data[CONF_TYPE] == CONF_TYPE_OWSERVER
|
||||||
and config_entry.data[CONF_HOST] == user_input[CONF_HOST]
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -48,9 +48,8 @@ async def setup_onewire_owserver_integration(hass):
|
||||||
data={
|
data={
|
||||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||||
CONF_HOST: "1.2.3.4",
|
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,
|
connection_class=CONN_CLASS_LOCAL_POLL,
|
||||||
options={},
|
options={},
|
||||||
entry_id="2",
|
entry_id="2",
|
||||||
|
@ -74,12 +73,11 @@ async def setup_onewire_patched_owserver_integration(hass):
|
||||||
data={
|
data={
|
||||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_PORT: "1234",
|
CONF_PORT: 1234,
|
||||||
CONF_NAMES: {
|
CONF_NAMES: {
|
||||||
"10.111111111111": "My DS18B20",
|
"10.111111111111": "My DS18B20",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
|
|
||||||
connection_class=CONN_CLASS_LOCAL_POLL,
|
connection_class=CONN_CLASS_LOCAL_POLL,
|
||||||
options={},
|
options={},
|
||||||
entry_id="2",
|
entry_id="2",
|
||||||
|
|
|
@ -318,7 +318,7 @@ async def test_import_owserver_with_port(hass):
|
||||||
data={
|
data={
|
||||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_PORT: "1234",
|
CONF_PORT: 1234,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
|
@ -326,8 +326,37 @@ async def test_import_owserver_with_port(hass):
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_PORT: "1234",
|
CONF_PORT: 1234,
|
||||||
}
|
}
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
assert len(mock_setup_entry.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
|
||||||
|
|
Loading…
Add table
Reference in a new issue