From 4b5033d08fe37907b8a08bb69ef1c06fe9d489aa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 5 Apr 2022 13:38:55 -1000 Subject: [PATCH] Abort samsungtv discovery of legacy devices when unique id not available (#69376) --- .../components/samsungtv/config_flow.py | 7 +++++++ tests/components/samsungtv/test_config_flow.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/homeassistant/components/samsungtv/config_flow.py b/homeassistant/components/samsungtv/config_flow.py index be71519b0c2..f37020cb029 100644 --- a/homeassistant/components/samsungtv/config_flow.py +++ b/homeassistant/components/samsungtv/config_flow.py @@ -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() diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index ec4aa58d39d..19169c20dd3 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -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."""