8000 Abort keenetic SSDP discovery if the unique id is already setup or ignored by foxel · Pull Request #58009 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Abort keenetic SSDP discovery if the unique id is already setup or ignored #58009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/keenetic_ndms2/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async def async_step_ssdp(self, discovery_info: DiscoveryInfoType) -> FlowResult

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})

Expand Down
50 changes: 50 additions & 0 deletions tests/components/keenetic_ndms2/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
0