Fix flux_led ignored entries not being respected (#76173)

This commit is contained in:
J. Nick Koston 2022-08-04 07:44:22 -10:00 committed by GitHub
parent b2dc810ea4
commit 02ad4843b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 19 deletions

View file

@ -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."""