Fix mysensors connection task blocking setup (#15938)
* Fix mysensors connection task blocking setup * Schedule the connection task without having the core track the task to avoid blocking setup. * Cancel the connection task, if not cancelled already, when home assistant stops. * Use done instead of cancelledpull/16027/head
parent
11eb29f520
commit
d540a084dd
|
@ -186,12 +186,16 @@ def _discover_mysensors_platform(hass, platform, new_devices):
|
|||
|
||||
async def _gw_start(hass, gateway):
|
||||
"""Start the gateway."""
|
||||
# Don't use hass.async_create_task to avoid holding up setup indefinitely.
|
||||
connect_task = hass.loop.create_task(gateway.start())
|
||||
|
||||
@callback
|
||||
def gw_stop(event):
|
||||
"""Trigger to stop the gateway."""
|
||||
hass.async_add_job(gateway.stop())
|
||||
if not connect_task.done():
|
||||
connect_task.cancel()
|
||||
|
||||
await gateway.start()
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, gw_stop)
|
||||
if gateway.device == 'mqtt':
|
||||
# Gatways connected via mqtt doesn't send gateway ready message.
|
||||
|
|
Loading…
Reference in New Issue