Allow ignored idasen_desk devices to be set up from the user flow (#137253)

This commit is contained in:
Abílio Costa 2025-02-03 19:54:09 +00:00 committed by Franck Nijhof
parent 455af9179b
commit 1e1069b647
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 44 additions and 1 deletions

View File

@ -87,7 +87,7 @@ class IdasenDeskConfigFlow(ConfigFlow, domain=DOMAIN):
if discovery := self._discovery_info:
self._discovered_devices[discovery.address] = discovery
else:
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

@ -50,6 +50,49 @@ async def test_user_step_success(hass: HomeAssistant, mock_desk_api: MagicMock)
assert len(mock_setup_entry.mock_calls) == 1
async def test_user_step_replaces_ignored_device(
hass: HomeAssistant, mock_desk_api: MagicMock
) -> None:
"""Test user step replaces ignored devices."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=IDASEN_DISCOVERY_INFO.address,
source=config_entries.SOURCE_IGNORE,
data={CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.idasen_desk.config_flow.async_discovered_service_info",
return_value=[NOT_IDASEN_DISCOVERY_INFO, IDASEN_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"] == {}
with patch(
"homeassistant.components.idasen_desk.async_setup_entry", return_value=True
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address,
},
)
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == IDASEN_DISCOVERY_INFO.name
assert result2["data"] == {
CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address,
}
assert result2["result"].unique_id == IDASEN_DISCOVERY_INFO.address
assert len(mock_setup_entry.mock_calls) == 1
async def test_user_step_no_devices_found(hass: HomeAssistant) -> None:
"""Test user step with no devices found."""
with patch(