diff --git a/homeassistant/components/samsungtv/config_flow.py b/homeassistant/components/samsungtv/config_flow.py index e2b9f8631d8..f268044c103 100644 --- a/homeassistant/components/samsungtv/config_flow.py +++ b/homeassistant/components/samsungtv/config_flow.py @@ -441,7 +441,7 @@ class SamsungTVConfigFlow(ConfigFlow, domain=DOMAIN): def is_matching(self, other_flow: Self) -> bool: """Return True if other_flow is matching this flow.""" - return other_flow._host == self._host # noqa: SLF001 + return getattr(other_flow, "_host", None) == self._host @callback def _abort_if_manufacturer_is_not_samsung(self) -> None: diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index dd6b21ab5e5..08189a125e9 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -2143,3 +2143,39 @@ async def test_ssdp_update_mac(hass: HomeAssistant) -> None: # ensure mac was updated with new wifiMac value assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff" assert entry.unique_id == "123" + + +@pytest.mark.usefixtures("remote_websocket") +async def test_dhcp_while_user_flow_pending(hass: HomeAssistant) -> None: + """Simulate pending user flow, then trigger DHCP before submit. + + Covers https://github.com/home-assistant/core/issues/156591. + """ + with patch( + "homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info", + return_value=None, # Simulate device not connectable + ): + # Start user flow, which will show form (cannot connect) + result_user = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_USER}, + ) + assert result_user["type"] == FlowResultType.FORM + assert result_user["step_id"] == "user" + + # While user flow is pending (form shown), trigger DHCP flow + dhcp_data = DhcpServiceInfo( + ip="10.10.12.34", macaddress="aabbccddeeff", hostname="fake_hostname" + ) + with patch( + "homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info", + return_value={ + "device": {"modelName": "fake_model", "wifiMac": "aa:bb:cc:dd:ee:ff"} + }, + ): + result_dhcp = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data=dhcp_data, + ) + assert result_dhcp["type"] == FlowResultType.ABORT