mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Use a background task for LIFX discovery (#88820)
This commit is contained in:
parent
b5223e1196
commit
0d25eef19c
@ -17,10 +17,9 @@ from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import async_call_later, async_track_time_interval
|
||||
@ -167,15 +166,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
We do not want the discovery task to block startup.
|
||||
"""
|
||||
task = asyncio.create_task(discovery_manager.async_discovery())
|
||||
|
||||
@callback
|
||||
def _async_stop(_: Event) -> None:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
# Task must be shut down when home assistant is closing
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop)
|
||||
hass.async_create_background_task(
|
||||
discovery_manager.async_discovery(), "lifx-discovery"
|
||||
)
|
||||
|
||||
# Let the system settle a bit before starting discovery
|
||||
# to reduce the risk we miss devices because the event
|
||||
|
Loading…
x
Reference in New Issue
Block a user