mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Fix duplicate check on onewire config flow (#43590)
This commit is contained in:
parent
acb94b0b59
commit
48d9f1a61b
@ -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
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
|
@ -318,7 +318,7 @@ 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
|
||||
@ -326,8 +326,37 @@ async def test_import_owserver_with_port(hass):
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user