From ab6bd75b700ae34675ba6d830565b27142286f18 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 26 Feb 2023 20:14:54 -0600 Subject: [PATCH] Fix flux_led discovery running at shutdown (#88817) --- homeassistant/components/flux_led/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/flux_led/__init__.py b/homeassistant/components/flux_led/__init__.py index 7d7ef2d42bf..86b73c762fb 100644 --- a/homeassistant/components/flux_led/__init__.py +++ b/homeassistant/components/flux_led/__init__.py @@ -87,14 +87,23 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass, STARTUP_SCAN_TIMEOUT ) + @callback + def _async_start_background_discovery(*_: Any) -> None: + """Run discovery in the background.""" + hass.async_create_background_task(_async_discovery(), "flux_led-discovery") + async def _async_discovery(*_: Any) -> None: async_trigger_discovery( hass, await async_discover_devices(hass, DISCOVER_SCAN_TIMEOUT) ) async_trigger_discovery(hass, domain_data[FLUX_LED_DISCOVERY]) - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _async_discovery) - async_track_time_interval(hass, _async_discovery, DISCOVERY_INTERVAL) + hass.bus.async_listen_once( + EVENT_HOMEASSISTANT_STARTED, _async_start_background_discovery + ) + async_track_time_interval( + hass, _async_start_background_discovery, DISCOVERY_INTERVAL + ) return True