Allow ignored ld2410_ble devices to be set up from the user flow (#155618)

This commit is contained in:
J. Nick Koston
2025-11-01 10:54:01 -05:00
committed by GitHub
parent 93415175bb
commit 32cc5123f5
2 changed files with 51 additions and 14 deletions

View File

@@ -79,7 +79,7 @@ class Ld2410BleConfigFlow(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

@@ -6,6 +6,7 @@ from bleak import BleakError
from homeassistant import config_entries
from homeassistant.components.ld2410_ble.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 FlowResultType
@@ -54,19 +55,6 @@ async def test_user_step_success(hass: HomeAssistant) -> None:
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(
"homeassistant.components.ld2410_ble.config_flow.async_discovered_service_info",
return_value=[NOT_LD2410_BLE_DISCOVERY_INFO],
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "no_devices_found"
async def test_user_step_no_new_devices_found(hass: HomeAssistant) -> None:
"""Test user step with only existing devices found."""
entry = MockConfigEntry(
@@ -233,3 +221,52 @@ async def test_bluetooth_step_success(hass: HomeAssistant) -> None:
}
assert result2["result"].unique_id == LD2410_BLE_DISCOVERY_INFO.address
assert len(mock_setup_entry.mock_calls) == 1
async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None:
"""Test the user initiated form can replace an ignored device."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="AA:BB:CC:DD:EE:FF",
source=SOURCE_IGNORE,
data={},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.ld2410_ble.config_flow.async_discovered_service_info",
return_value=[LD2410_BLE_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"
# Verify the ignored device is in the dropdown
assert "AA:BB:CC:DD:EE:FF" in result["data_schema"].schema["address"].container
with (
patch(
"homeassistant.components.ld2410_ble.config_flow.LD2410BLE.initialise",
),
patch(
"homeassistant.components.ld2410_ble.async_setup_entry",
return_value=True,
) as mock_setup_entry,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_ADDRESS: LD2410_BLE_DISCOVERY_INFO.address,
},
)
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == LD2410_BLE_DISCOVERY_INFO.name
assert result2["data"] == {
CONF_ADDRESS: LD2410_BLE_DISCOVERY_INFO.address,
}
assert result2["result"].unique_id == LD2410_BLE_DISCOVERY_INFO.address
assert len(mock_setup_entry.mock_calls) == 1