diff --git a/homeassistant/components/flux_led/config_flow.py b/homeassistant/components/flux_led/config_flow.py index 61395d744b3..b245c0c2bc2 100644 --- a/homeassistant/components/flux_led/config_flow.py +++ b/homeassistant/components/flux_led/config_flow.py @@ -105,27 +105,33 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): assert mac_address is not None mac = dr.format_mac(mac_address) await self.async_set_unique_id(mac) - for entry in self._async_current_entries(include_ignore=False): - if entry.data[CONF_HOST] == device[ATTR_IPADDR] or ( - entry.unique_id - and ":" in entry.unique_id - and mac_matches_by_one(entry.unique_id, mac) + for entry in self._async_current_entries(include_ignore=True): + if not ( + entry.data.get(CONF_HOST) == device[ATTR_IPADDR] + or ( + entry.unique_id + and ":" in entry.unique_id + and mac_matches_by_one(entry.unique_id, mac) + ) ): - if ( - async_update_entry_from_discovery( - self.hass, entry, device, None, allow_update_mac - ) - or entry.state == config_entries.ConfigEntryState.SETUP_RETRY - ): - self.hass.async_create_task( - self.hass.config_entries.async_reload(entry.entry_id) - ) - else: - async_dispatcher_send( - self.hass, - FLUX_LED_DISCOVERY_SIGNAL.format(entry_id=entry.entry_id), - ) + continue + if entry.source == config_entries.SOURCE_IGNORE: raise AbortFlow("already_configured") + if ( + async_update_entry_from_discovery( + self.hass, entry, device, None, allow_update_mac + ) + or entry.state == config_entries.ConfigEntryState.SETUP_RETRY + ): + self.hass.async_create_task( + self.hass.config_entries.async_reload(entry.entry_id) + ) + else: + async_dispatcher_send( + self.hass, + FLUX_LED_DISCOVERY_SIGNAL.format(entry_id=entry.entry_id), + ) + raise AbortFlow("already_configured") async def _async_handle_discovery(self) -> FlowResult: """Handle any discovery.""" diff --git a/tests/components/flux_led/test_config_flow.py b/tests/components/flux_led/test_config_flow.py index 8abdb8e955b..3f1704f7e8c 100644 --- a/tests/components/flux_led/test_config_flow.py +++ b/tests/components/flux_led/test_config_flow.py @@ -695,3 +695,30 @@ async def test_options(hass: HomeAssistant): assert result2["data"] == user_input assert result2["data"] == config_entry.options assert hass.states.get("light.bulb_rgbcw_ddeeff") is not None + + +@pytest.mark.parametrize( + "source, data", + [ + (config_entries.SOURCE_DHCP, DHCP_DISCOVERY), + (config_entries.SOURCE_INTEGRATION_DISCOVERY, FLUX_DISCOVERY), + ], +) +async def test_discovered_can_be_ignored(hass, source, data): + """Test we abort if the mac was already ignored.""" + config_entry = MockConfigEntry( + domain=DOMAIN, + data={}, + unique_id=MAC_ADDRESS, + source=config_entries.SOURCE_IGNORE, + ) + config_entry.add_to_hass(hass) + + with _patch_discovery(), _patch_wifibulb(): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": source}, data=data + ) + await hass.async_block_till_done() + + assert result["type"] == FlowResultType.ABORT + assert result["reason"] == "already_configured"