Skip to content

Commit

Permalink
Fix flux_led discovery running at shutdown (home-assistant#88817)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored and balloob committed Feb 27, 2023
1 parent 2fff836 commit ab6bd75
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions homeassistant/components/flux_led/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ab6bd75

Please sign in to comment.