Improve handling of ignored entries (#42148)
parent
177bda01e8
commit
45345ddc05
|
@ -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")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue