diff --git a/homeassistant/components/roomba/config_flow.py b/homeassistant/components/roomba/config_flow.py index 8cee43ab4aa..d690bcce978 100644 --- a/homeassistant/components/roomba/config_flow.py +++ b/homeassistant/components/roomba/config_flow.py @@ -130,7 +130,9 @@ class RoombaConfigFlow(ConfigFlow, domain=DOMAIN): # going for a longer hostname we abort so the user # does not see two flows if discovery fails. for progress in self._async_in_progress(): - flow_unique_id: str = progress["context"]["unique_id"] + flow_unique_id = progress["context"].get("unique_id") + if not flow_unique_id: + continue if flow_unique_id.startswith(self.blid): return self.async_abort(reason="short_blid") if self.blid.startswith(flow_unique_id): diff --git a/tests/components/roomba/test_config_flow.py b/tests/components/roomba/test_config_flow.py index e5f882afa36..8139e42d43d 100644 --- a/tests/components/roomba/test_config_flow.py +++ b/tests/components/roomba/test_config_flow.py @@ -1055,6 +1055,43 @@ async def test_dhcp_discovery_partial_hostname(hass: HomeAssistant) -> None: assert current_flows[0]["flow_id"] == result2["flow_id"] +async def test_dhcp_discovery_when_user_flow_in_progress(hass: HomeAssistant) -> None: + """Test discovery flow when user flow is in progress.""" + + # Start a DHCP flow + with patch( + "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + # Start a user flow - unique ID not set + with patch( + "homeassistant.components.roomba.config_flow.RoombaDiscovery", _mocked_discovery + ): + result2 = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_DHCP}, + data=dhcp.DhcpServiceInfo( + ip=MOCK_IP, + macaddress="aabbccddeeff", + hostname="irobot-blidthatislonger", + ), + ) + await hass.async_block_till_done() + + assert result2["type"] is FlowResultType.FORM + assert result2["step_id"] == "link" + + current_flows = hass.config_entries.flow.async_progress() + assert len(current_flows) == 2 + + async def test_options_flow( hass: HomeAssistant, ) -> None: