diff --git a/homeassistant/components/ruuvitag_ble/config_flow.py b/homeassistant/components/ruuvitag_ble/config_flow.py index 564f3c9d0e2f..1d71eaf28c07 100644 --- a/homeassistant/components/ruuvitag_ble/config_flow.py +++ b/homeassistant/components/ruuvitag_ble/config_flow.py @@ -72,7 +72,7 @@ class RuuvitagConfigFlow(ConfigFlow, domain=DOMAIN): title=self._discovered_devices[address], data={} ) - current_addresses = self._async_current_ids() + current_addresses = self._async_current_ids(include_ignore=False) for discovery_info in async_discovered_service_info(self.hass, False): address = discovery_info.address if address in current_addresses or address in self._discovered_devices: diff --git a/tests/components/ruuvitag_ble/test_config_flow.py b/tests/components/ruuvitag_ble/test_config_flow.py index 5259511fc0f1..add4b6682a9b 100644 --- a/tests/components/ruuvitag_ble/test_config_flow.py +++ b/tests/components/ruuvitag_ble/test_config_flow.py @@ -6,6 +6,7 @@ import pytest from homeassistant import config_entries from homeassistant.components.ruuvitag_ble.const import DOMAIN +from homeassistant.config_entries import SOURCE_IGNORE from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -205,3 +206,42 @@ async def test_async_step_user_takes_precedence_over_discovery( assert result2["title"] == CONFIGURED_NAME assert result2["data"] == {} assert result2["result"].unique_id == RUUVI_V5_SERVICE_INFO.address + + +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=RUUVI_V5_SERVICE_INFO.address, + source=SOURCE_IGNORE, + data={}, + ) + entry.add_to_hass(hass) + + with patch( + "homeassistant.components.ruuvitag_ble.config_flow.async_discovered_service_info", + return_value=[RUUVI_V5_SERVICE_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 ( + RUUVI_V5_SERVICE_INFO.address + in result["data_schema"].schema["address"].container + ) + + with patch( + "homeassistant.components.ruuvitag_ble.async_setup_entry", return_value=True + ): + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={"address": RUUVI_V5_SERVICE_INFO.address}, + ) + assert result2["type"] is FlowResultType.CREATE_ENTRY + assert result2["title"] == CONFIGURED_NAME + assert result2["data"] == {} + assert result2["result"].unique_id == RUUVI_V5_SERVICE_INFO.address