mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Improve handling of ignored entries (#42148)
This commit is contained in:
parent
177bda01e8
commit
45345ddc05
@ -122,7 +122,7 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if any(
|
if any(
|
||||||
user_input["host"] == entry.data["host"]
|
user_input["host"] == entry.data.get("host")
|
||||||
for entry in self._async_current_entries()
|
for entry in self._async_current_entries()
|
||||||
):
|
):
|
||||||
return self.async_abort(reason="already_configured")
|
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.
|
# Check if host exists, abort if so.
|
||||||
if any(
|
if any(
|
||||||
import_info["host"] == entry.data["host"]
|
import_info["host"] == entry.data.get("host")
|
||||||
for entry in self._async_current_entries()
|
for entry in self._async_current_entries()
|
||||||
):
|
):
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
@ -19,7 +19,8 @@ async def validate_input(hass: core.HomeAssistant, data):
|
|||||||
same_entries = [
|
same_entries = [
|
||||||
True
|
True
|
||||||
for entry in confs
|
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:
|
if same_entries:
|
||||||
|
@ -64,7 +64,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
configured_hosts = [
|
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(
|
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."""
|
"""Test config flow discovers only already configured bridges."""
|
||||||
mock_bridge = get_mock_bridge()
|
mock_bridge = get_mock_bridge()
|
||||||
|
|
||||||
|
MockConfigEntry(
|
||||||
|
domain="hue", source=config_entries.SOURCE_IGNORE, unique_id="bla"
|
||||||
|
).add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hue.config_flow.discover_nupnp",
|
"homeassistant.components.hue.config_flow.discover_nupnp",
|
||||||
return_value=[mock_bridge],
|
return_value=[mock_bridge],
|
||||||
@ -137,7 +141,7 @@ async def test_manual_flow_works(hass, aioclient_mock):
|
|||||||
"username": "username-abc",
|
"username": "username-abc",
|
||||||
}
|
}
|
||||||
entries = hass.config_entries.async_entries("hue")
|
entries = hass.config_entries.async_entries("hue")
|
||||||
assert len(entries) == 1
|
assert len(entries) == 2
|
||||||
entry = entries[-1]
|
entry = entries[-1]
|
||||||
assert entry.unique_id == "id-1234"
|
assert entry.unique_id == "id-1234"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user