diff --git a/homeassistant/components/nut/config_flow.py b/homeassistant/components/nut/config_flow.py index 04889bb3f3f..0721ea10f94 100644 --- a/homeassistant/components/nut/config_flow.py +++ b/homeassistant/components/nut/config_flow.py @@ -99,7 +99,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): def _host_port_alias_already_configured(self, host, port, alias): """See if we already have a nut entry matching user input configured.""" existing_host_port_aliases = { - _format_host_port_alias(host, port, alias) + _format_host_port_alias( + entry.data[CONF_HOST], entry.data[CONF_PORT], entry.data.get(CONF_ALIAS) + ) for entry in self._async_current_entries() } return _format_host_port_alias(host, port, alias) in existing_host_port_aliases diff --git a/tests/components/nut/test_config_flow.py b/tests/components/nut/test_config_flow.py index 362f6c0b2ba..2ffc470ccf0 100644 --- a/tests/components/nut/test_config_flow.py +++ b/tests/components/nut/test_config_flow.py @@ -4,6 +4,8 @@ from asynctest import MagicMock, patch from homeassistant import config_entries, setup from homeassistant.components.nut.const import DOMAIN +from tests.common import MockConfigEntry + def _get_mock_pynutclient(list_vars=None): pynutclient = MagicMock() @@ -62,6 +64,12 @@ async def test_form_import(hass): """Test we get the form with import source.""" await setup.async_setup_component(hass, "persistent_notification", {}) + config_entry = MockConfigEntry( + domain=DOMAIN, + data={"host": "2.2.2.2", "port": 123, "resources": ["battery.charge"]}, + ) + config_entry.add_to_hass(hass) + mock_pynut = _get_mock_pynutclient(list_vars={"battery.voltage": "serial"}) with patch( @@ -92,7 +100,7 @@ async def test_form_import(hass): } await hass.async_block_till_done() assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 + assert len(mock_setup_entry.mock_calls) == 2 async def test_form_cannot_connect(hass):