Abort samsungtv discovery of legacy devices when unique id not available (#69376)

This commit is contained in:
J. Nick Koston 2022-04-05 13:38:55 -10:00 committed by GitHub
parent f31d1164e5
commit 4b5033d08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -469,6 +469,13 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
await self._async_set_unique_id_from_udn()
self._async_update_and_abort_for_matching_unique_id()
self._async_abort_if_host_already_in_progress()
if self._method == METHOD_LEGACY and discovery_info.ssdp_st in (
UPNP_SVC_RENDERING_CONTROL,
UPNP_SVC_MAIN_TV_AGENT,
):
# The UDN we use for the unique id cannot be determined
# from device_info for legacy devices
return self.async_abort(reason="not_supported")
self.context["title_placeholders"] = {"device": self._title}
return await self.async_step_confirm()

View File

@ -43,6 +43,7 @@ from homeassistant.components.ssdp import (
ATTR_UPNP_MANUFACTURER,
ATTR_UPNP_MODEL_NAME,
ATTR_UPNP_UDN,
SsdpServiceInfo,
)
from homeassistant.const import (
CONF_HOST,
@ -524,6 +525,21 @@ async def test_ssdp(hass: HomeAssistant) -> None:
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
@pytest.mark.parametrize(
"data", [MOCK_SSDP_DATA_MAIN_TV_AGENT_ST, MOCK_SSDP_DATA_RENDERING_CONTROL_ST]
)
@pytest.mark.usefixtures("remote", "rest_api_failing")
async def test_ssdp_legacy_not_remote_control_receiver_udn(
hass: HomeAssistant, data: SsdpServiceInfo
) -> None:
"""Test we abort if the st is not usable for legacy discovery since it will have a different UDN."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=data
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == RESULT_NOT_SUPPORTED
@pytest.mark.usefixtures("remote", "rest_api_failing")
async def test_ssdp_noprefix(hass: HomeAssistant) -> None:
"""Test starting a flow from discovery without prefixes."""