diff --git a/homeassistant/components/kulersky/config_flow.py b/homeassistant/components/kulersky/config_flow.py index f27d2ef0ea0..6400b7f8556 100644 --- a/homeassistant/components/kulersky/config_flow.py +++ b/homeassistant/components/kulersky/config_flow.py @@ -106,7 +106,7 @@ class KulerskyConfigFlow(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 diff --git a/tests/components/kulersky/test_config_flow.py b/tests/components/kulersky/test_config_flow.py index 7615e94d2f0..115f6c4dc24 100644 --- a/tests/components/kulersky/test_config_flow.py +++ b/tests/components/kulersky/test_config_flow.py @@ -8,6 +8,7 @@ from homeassistant.components.bluetooth import BluetoothServiceInfoBleak from homeassistant.components.kulersky.config_flow import DOMAIN from homeassistant.config_entries import ( SOURCE_BLUETOOTH, + SOURCE_IGNORE, SOURCE_INTEGRATION_DISCOVERY, SOURCE_USER, ) @@ -15,6 +16,7 @@ from homeassistant.const import CONF_ADDRESS from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from tests.common import MockConfigEntry from tests.components.bluetooth import generate_advertisement_data, generate_ble_device KULERSKY_SERVICE_INFO = BluetoothServiceInfoBleak( @@ -180,3 +182,44 @@ async def test_unexpected_error(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.FORM assert result["errors"]["base"] == "unknown" + + +async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None: + """Test the user flow 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.kulersky.config_flow.async_discovered_service_info", + return_value=[KULERSKY_SERVICE_INFO], + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_USER}, + ) + await hass.async_block_till_done() + + 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[CONF_ADDRESS].container + + with patch("pykulersky.Light", Mock(return_value=AsyncMock())): + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + {CONF_ADDRESS: "AA:BB:CC:DD:EE:FF"}, + ) + await hass.async_block_till_done() + + assert result2["type"] is FlowResultType.CREATE_ENTRY + assert result2["title"] == "KulerLight (EEFF)" + assert result2["data"] == { + CONF_ADDRESS: "AA:BB:CC:DD:EE:FF", + } + assert result2["result"].unique_id == "AA:BB:CC:DD:EE:FF"