|
10 | 10 |
|
11 | 11 | from homeassistant import config_entries |
12 | 12 | from homeassistant.components.elkm1.const import CONF_AUTO_CONFIGURE, DOMAIN |
| 13 | +from homeassistant.config_entries import SOURCE_IGNORE |
13 | 14 | from homeassistant.const import ( |
14 | 15 | CONF_ADDRESS, |
15 | 16 | CONF_HOST, |
@@ -2338,3 +2339,51 @@ async def test_reconfigure_preserves_existing_config_entry_fields( |
2338 | 2339 | assert updated_entry.data[CONF_PREFIX] == "oldprefix" |
2339 | 2340 | assert updated_entry.data["extra_field"] == "should_be_preserved" |
2340 | 2341 | assert updated_entry.data["another_field"] == 42 |
| 2342 | + |
| 2343 | + |
| 2344 | +async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None: |
| 2345 | + """Test the user flow can replace an ignored device.""" |
| 2346 | + entry = MockConfigEntry( |
| 2347 | + domain=DOMAIN, |
| 2348 | + unique_id=dr.format_mac(MOCK_MAC), |
| 2349 | + source=SOURCE_IGNORE, |
| 2350 | + data={}, |
| 2351 | + ) |
| 2352 | + entry.add_to_hass(hass) |
| 2353 | + |
| 2354 | + with _patch_discovery(): |
| 2355 | + result = await hass.config_entries.flow.async_init( |
| 2356 | + DOMAIN, context={"source": config_entries.SOURCE_USER} |
| 2357 | + ) |
| 2358 | + await hass.async_block_till_done() |
| 2359 | + |
| 2360 | + assert result["type"] is FlowResultType.FORM |
| 2361 | + assert result["step_id"] == "user" |
| 2362 | + |
| 2363 | + # Verify the ignored device is in the dropdown |
| 2364 | + assert dr.format_mac(MOCK_MAC) in result["data_schema"].schema["device"].container |
| 2365 | + |
| 2366 | + mocked_elk = mock_elk(invalid_auth=False, sync_complete=True) |
| 2367 | + with ( |
| 2368 | + _patch_discovery(), |
| 2369 | + _patch_elk(mocked_elk), |
| 2370 | + patch(f"{MODULE}.async_setup", return_value=True), |
| 2371 | + patch(f"{MODULE}.async_setup_entry", return_value=True), |
| 2372 | + ): |
| 2373 | + result2 = await hass.config_entries.flow.async_configure( |
| 2374 | + result["flow_id"], |
| 2375 | + {"device": dr.format_mac(MOCK_MAC)}, |
| 2376 | + ) |
| 2377 | + await hass.async_block_till_done() |
| 2378 | + result3 = await hass.config_entries.flow.async_configure( |
| 2379 | + result2["flow_id"], |
| 2380 | + { |
| 2381 | + CONF_USERNAME: "test", |
| 2382 | + CONF_PASSWORD: "test", |
| 2383 | + CONF_PROTOCOL: "secure", |
| 2384 | + }, |
| 2385 | + ) |
| 2386 | + await hass.async_block_till_done() |
| 2387 | + |
| 2388 | + assert result3["type"] is FlowResultType.CREATE_ENTRY |
| 2389 | + assert result3["result"].unique_id == dr.format_mac(MOCK_MAC) |
0 commit comments