Skip to content

Commit 291331f

Browse files
FredrikM97epenet
andauthored
Fix is_matching in samsungtv config flow (home-assistant#156594)
Co-authored-by: epenet <[email protected]>
1 parent a13cdbd commit 291331f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

homeassistant/components/samsungtv/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def _async_abort_if_host_already_in_progress(self) -> None:
441441

442442
def is_matching(self, other_flow: Self) -> bool:
443443
"""Return True if other_flow is matching this flow."""
444-
return other_flow._host == self._host # noqa: SLF001
444+
return getattr(other_flow, "_host", None) == self._host
445445

446446
@callback
447447
def _abort_if_manufacturer_is_not_samsung(self) -> None:

tests/components/samsungtv/test_config_flow.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,3 +2143,39 @@ async def test_ssdp_update_mac(hass: HomeAssistant) -> None:
21432143
# ensure mac was updated with new wifiMac value
21442144
assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff"
21452145
assert entry.unique_id == "123"
2146+
2147+
2148+
@pytest.mark.usefixtures("remote_websocket")
2149+
async def test_dhcp_while_user_flow_pending(hass: HomeAssistant) -> None:
2150+
"""Simulate pending user flow, then trigger DHCP before submit.
2151+
2152+
Covers https://github.com/home-assistant/core/issues/156591.
2153+
"""
2154+
with patch(
2155+
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
2156+
return_value=None, # Simulate device not connectable
2157+
):
2158+
# Start user flow, which will show form (cannot connect)
2159+
result_user = await hass.config_entries.flow.async_init(
2160+
DOMAIN,
2161+
context={"source": config_entries.SOURCE_USER},
2162+
)
2163+
assert result_user["type"] == FlowResultType.FORM
2164+
assert result_user["step_id"] == "user"
2165+
2166+
# While user flow is pending (form shown), trigger DHCP flow
2167+
dhcp_data = DhcpServiceInfo(
2168+
ip="10.10.12.34", macaddress="aabbccddeeff", hostname="fake_hostname"
2169+
)
2170+
with patch(
2171+
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.async_device_info",
2172+
return_value={
2173+
"device": {"modelName": "fake_model", "wifiMac": "aa:bb:cc:dd:ee:ff"}
2174+
},
2175+
):
2176+
result_dhcp = await hass.config_entries.flow.async_init(
2177+
DOMAIN,
2178+
context={"source": config_entries.SOURCE_DHCP},
2179+
data=dhcp_data,
2180+
)
2181+
assert result_dhcp["type"] == FlowResultType.ABORT

0 commit comments

Comments
 (0)