Abort keenetic SSDP discovery if the unique id is already setup or ignored (#58009)
parent
c1d671b817
commit
a824fa9a7b
|
@ -118,6 +118,7 @@ class KeeneticFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
host = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]).hostname
|
||||
await self.async_set_unique_id(discovery_info[ssdp.ATTR_UPNP_UDN])
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
|
||||
|
|
|
@ -211,6 +211,56 @@ async def test_ssdp_already_configured(hass: HomeAssistant) -> None:
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_ssdp_ignored(hass: HomeAssistant) -> None:
|
||||
"""Test unique ID ignored and discovered."""
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=keenetic.DOMAIN,
|
||||
source=config_entries.SOURCE_IGNORE,
|
||||
unique_id=MOCK_SSDP_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
discovery_info = MOCK_SSDP_DISCOVERY_INFO.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
keenetic.DOMAIN,
|
||||
context={CONF_SOURCE: config_entries.SOURCE_SSDP},
|
||||
data=discovery_info,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_ssdp_update_host(hass: HomeAssistant) -> None:
|
||||
"""Test unique ID configured and discovered with the new host."""
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=keenetic.DOMAIN,
|
||||
data=MOCK_DATA,
|
||||
options=MOCK_OPTIONS,
|
||||
unique_id=MOCK_SSDP_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
new_ip = "10.10.10.10"
|
||||
|
||||
discovery_info = {
|
||||
**MOCK_SSDP_DISCOVERY_INFO,
|
||||
ssdp.ATTR_SSDP_LOCATION: f"http://{new_ip}/",
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
keenetic.DOMAIN,
|
||||
context={CONF_SOURCE: config_entries.SOURCE_SSDP},
|
||||
data=discovery_info,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data[CONF_HOST] == new_ip
|
||||
|
||||
|
||||
async def test_ssdp_reject_no_udn(hass: HomeAssistant) -> None:
|
||||
"""Discovered device has no UDN."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue