Skip to content

Commit cad1f1d

Browse files
authored
Allow configuring ignored Elk-M1 devices (home-assistant#155631)
1 parent cd62bd8 commit cad1f1d

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

homeassistant/components/elkm1/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ async def async_step_user(
296296
return await self.async_step_discovered_connection()
297297
return await self.async_step_manual_connection()
298298

299-
current_unique_ids = self._async_current_ids()
299+
current_unique_ids = self._async_current_ids(include_ignore=False)
300300
current_hosts = {
301301
hostname_from_url(entry.data[CONF_HOST])
302302
for entry in self._async_current_entries(include_ignore=False)

tests/components/elkm1/test_config_flow.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from homeassistant import config_entries
1212
from homeassistant.components.elkm1.const import CONF_AUTO_CONFIGURE, DOMAIN
13+
from homeassistant.config_entries import SOURCE_IGNORE
1314
from homeassistant.const import (
1415
CONF_ADDRESS,
1516
CONF_HOST,
@@ -2338,3 +2339,51 @@ async def test_reconfigure_preserves_existing_config_entry_fields(
23382339
assert updated_entry.data[CONF_PREFIX] == "oldprefix"
23392340
assert updated_entry.data["extra_field"] == "should_be_preserved"
23402341
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

Comments
 (0)