diff --git a/homeassistant/components/onewire/config_flow.py b/homeassistant/components/onewire/config_flow.py index f83431111d843..9ad4d5347f0cc 100644 --- a/homeassistant/components/onewire/config_flow.py +++ b/homeassistant/components/onewire/config_flow.py @@ -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 diff --git a/tests/components/onewire/__init__.py b/tests/components/onewire/__init__.py index eb9b42ea996b5..39a3c438cf92f 100644 --- a/tests/components/onewire/__init__.py +++ b/tests/components/onewire/__init__.py @@ -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", diff --git a/tests/components/onewire/test_config_flow.py b/tests/components/onewire/test_config_flow.py index dfb64a3846ed9..ba0ae090ed2ac 100644 --- a/tests/components/onewire/test_config_flow.py +++ b/tests/components/onewire/test_config_flow.py @@ -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