|
10 | 10 |
|
11 | 11 | from homeassistant import config_entries |
12 | 12 | from homeassistant.components.nanoleaf.const import DOMAIN |
| 13 | +from homeassistant.config_entries import SOURCE_USER |
13 | 14 | from homeassistant.const import CONF_HOST, CONF_TOKEN |
14 | 15 | from homeassistant.core import HomeAssistant |
15 | 16 | from homeassistant.data_entry_flow import FlowResultType |
@@ -463,3 +464,59 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None: |
463 | 464 | } |
464 | 465 |
|
465 | 466 | assert len(mock_setup_entry.mock_calls) == 1 |
| 467 | + |
| 468 | + |
| 469 | +async def test_abort_discovery_flow_with_user_flow(hass: HomeAssistant) -> None: |
| 470 | + """Test abort discovery flow if user flow is already in progress.""" |
| 471 | + with ( |
| 472 | + patch( |
| 473 | + "homeassistant.components.nanoleaf.config_flow.load_json_object", |
| 474 | + return_value={}, |
| 475 | + ), |
| 476 | + patch( |
| 477 | + "homeassistant.components.nanoleaf.config_flow.Nanoleaf", |
| 478 | + return_value=_mock_nanoleaf(TEST_HOST, TEST_TOKEN), |
| 479 | + ), |
| 480 | + patch( |
| 481 | + "homeassistant.components.nanoleaf.async_setup_entry", |
| 482 | + return_value=True, |
| 483 | + ), |
| 484 | + ): |
| 485 | + result = await hass.config_entries.flow.async_init( |
| 486 | + DOMAIN, |
| 487 | + context={"source": config_entries.SOURCE_SSDP}, |
| 488 | + data=SsdpServiceInfo( |
| 489 | + ssdp_usn="mock_usn", |
| 490 | + ssdp_st="mock_st", |
| 491 | + upnp={}, |
| 492 | + ssdp_headers={ |
| 493 | + "_host": TEST_HOST, |
| 494 | + "nl-devicename": TEST_NAME, |
| 495 | + "nl-deviceid": TEST_DEVICE_ID, |
| 496 | + }, |
| 497 | + ), |
| 498 | + ) |
| 499 | + |
| 500 | + assert result["type"] is FlowResultType.FORM |
| 501 | + assert result["errors"] is None |
| 502 | + assert result["step_id"] == "link" |
| 503 | + |
| 504 | + result = await hass.config_entries.flow.async_init( |
| 505 | + DOMAIN, |
| 506 | + context={"source": SOURCE_USER}, |
| 507 | + ) |
| 508 | + assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 2 |
| 509 | + assert result["type"] is FlowResultType.FORM |
| 510 | + assert result["step_id"] == "user" |
| 511 | + |
| 512 | + result = await hass.config_entries.flow.async_configure( |
| 513 | + result["flow_id"], {CONF_HOST: TEST_HOST} |
| 514 | + ) |
| 515 | + assert result["type"] is FlowResultType.FORM |
| 516 | + assert result["step_id"] == "link" |
| 517 | + |
| 518 | + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) |
| 519 | + assert result["type"] is FlowResultType.CREATE_ENTRY |
| 520 | + |
| 521 | + # Verify the discovery flow was aborted |
| 522 | + assert not hass.config_entries.flow.async_progress(DOMAIN) |
0 commit comments