Allow configuring ignored devices from dormakaba_dkey user flow (#140596)

This commit is contained in:
Erik Montnemery 2025-03-14 15:01:43 +01:00 committed by GitHub
parent 1bd8ff884e
commit 96a6d88dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -57,7 +57,7 @@ class DormkabaConfigFlow(ConfigFlow, domain=DOMAIN):
self._discovery_info = self._discovered_devices[address]
return await self.async_step_associate()
current_addresses = self._async_current_ids()
current_addresses = self._async_current_ids(include_ignore=False)
for discovery in async_discovered_service_info(self.hass):
if (
discovery.address in current_addresses

View File

@ -9,6 +9,7 @@ import pytest
from homeassistant import config_entries
from homeassistant.components.dormakaba_dkey.const import DOMAIN
from homeassistant.config_entries import SOURCE_IGNORE
from homeassistant.const import CONF_ADDRESS
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult, FlowResultType
@ -143,6 +144,43 @@ async def test_async_step_user_takes_precedence_over_discovery(
assert not hass.config_entries.flow.async_progress(DOMAIN)
async def test_user_setup_removes_ignored_entry(hass: HomeAssistant) -> None:
"""Test the user initiated form can replace an ignored device."""
ignored_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=DKEY_DISCOVERY_INFO.address,
source=SOURCE_IGNORE,
)
ignored_entry.add_to_hass(hass)
assert hass.config_entries.async_entries(DOMAIN) == [ignored_entry]
with patch(
"homeassistant.components.dormakaba_dkey.config_flow.async_discovered_service_info",
return_value=[NOT_DKEY_DISCOVERY_INFO, DKEY_DISCOVERY_INFO],
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_ADDRESS: DKEY_DISCOVERY_INFO.address,
},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "associate"
assert result["errors"] is None
await _test_common_success(hass, result)
# Check the ignored entry is removed
assert ignored_entry not in hass.config_entries.async_entries(DOMAIN)
async def test_bluetooth_step_success(hass: HomeAssistant) -> None:
"""Test bluetooth step success path."""
result = await hass.config_entries.flow.async_init(