diff --git a/homeassistant/components/hue/config_flow.py b/homeassistant/components/hue/config_flow.py index f16d1f74cf6..ecb3fd8c489 100644 --- a/homeassistant/components/hue/config_flow.py +++ b/homeassistant/components/hue/config_flow.py @@ -122,7 +122,7 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): ) if any( - user_input["host"] == entry.data["host"] + user_input["host"] == entry.data.get("host") for entry in self._async_current_entries() ): return self.async_abort(reason="already_configured") @@ -216,7 +216,7 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """ # Check if host exists, abort if so. if any( - import_info["host"] == entry.data["host"] + import_info["host"] == entry.data.get("host") for entry in self._async_current_entries() ): return self.async_abort(reason="already_configured") diff --git a/homeassistant/components/progettihwsw/config_flow.py b/homeassistant/components/progettihwsw/config_flow.py index e65b58b370a..dca29668a84 100644 --- a/homeassistant/components/progettihwsw/config_flow.py +++ b/homeassistant/components/progettihwsw/config_flow.py @@ -19,7 +19,8 @@ async def validate_input(hass: core.HomeAssistant, data): same_entries = [ True for entry in confs - if entry.data["host"] == data["host"] and entry.data["port"] == data["port"] + if entry.data.get("host") == data["host"] + and entry.data.get("port") == data["port"] ] if same_entries: diff --git a/homeassistant/components/tradfri/__init__.py b/homeassistant/components/tradfri/__init__.py index 3a89852a55e..8d82df07bbb 100644 --- a/homeassistant/components/tradfri/__init__.py +++ b/homeassistant/components/tradfri/__init__.py @@ -64,7 +64,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType): return True configured_hosts = [ - entry.data["host"] for entry in hass.config_entries.async_entries(DOMAIN) + entry.data.get("host") for entry in hass.config_entries.async_entries(DOMAIN) ] legacy_hosts = await hass.async_add_executor_job( diff --git a/tests/components/hue/test_config_flow.py b/tests/components/hue/test_config_flow.py index 21bb489ffe7..a551e623e63 100644 --- a/tests/components/hue/test_config_flow.py +++ b/tests/components/hue/test_config_flow.py @@ -92,6 +92,10 @@ async def test_manual_flow_works(hass, aioclient_mock): """Test config flow discovers only already configured bridges.""" mock_bridge = get_mock_bridge() + MockConfigEntry( + domain="hue", source=config_entries.SOURCE_IGNORE, unique_id="bla" + ).add_to_hass(hass) + with patch( "homeassistant.components.hue.config_flow.discover_nupnp", return_value=[mock_bridge], @@ -137,7 +141,7 @@ async def test_manual_flow_works(hass, aioclient_mock): "username": "username-abc", } entries = hass.config_entries.async_entries("hue") - assert len(entries) == 1 + assert len(entries) == 2 entry = entries[-1] assert entry.unique_id == "id-1234"