mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Fix dangling task for cast (#88285)
This commit is contained in:
parent
da046f93f4
commit
f465561536
@ -1,7 +1,6 @@
|
||||
"""Provide functionality to interact with Cast devices on the network."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
from contextlib import suppress
|
||||
from datetime import datetime
|
||||
@ -186,10 +185,11 @@ class CastDevice:
|
||||
self.hass, SIGNAL_CAST_REMOVED, self._async_cast_removed
|
||||
)
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_stop)
|
||||
# asyncio.create_task is used to avoid delaying startup wrapup if the device
|
||||
# async_create_background_task is used to avoid delaying startup wrapup if the device
|
||||
# is discovered already during startup but then fails to respond
|
||||
asyncio.create_task(
|
||||
async_create_catching_coro(self._async_connect_to_chromecast())
|
||||
self.hass.async_create_background_task(
|
||||
async_create_catching_coro(self._async_connect_to_chromecast()),
|
||||
"cast-connect",
|
||||
)
|
||||
|
||||
async def _async_tear_down(self) -> None:
|
||||
|
@ -579,15 +579,16 @@ async def test_discover_dynamic_group(
|
||||
tasks = []
|
||||
real_create_task = asyncio.create_task
|
||||
|
||||
def create_task(*args, **kwargs):
|
||||
tasks.append(real_create_task(*args, **kwargs))
|
||||
def create_task(coroutine, name):
|
||||
tasks.append(real_create_task(coroutine))
|
||||
|
||||
# Discover cast service
|
||||
with patch(
|
||||
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
|
||||
return_value=zconf_1,
|
||||
), patch(
|
||||
"homeassistant.components.cast.media_player.asyncio.create_task",
|
||||
), patch.object(
|
||||
hass,
|
||||
"async_create_background_task",
|
||||
wraps=create_task,
|
||||
):
|
||||
discover_cast(
|
||||
@ -611,8 +612,9 @@ async def test_discover_dynamic_group(
|
||||
with patch(
|
||||
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
|
||||
return_value=zconf_2,
|
||||
), patch(
|
||||
"homeassistant.components.cast.media_player.asyncio.create_task",
|
||||
), patch.object(
|
||||
hass,
|
||||
"async_create_background_task",
|
||||
wraps=create_task,
|
||||
):
|
||||
discover_cast(
|
||||
@ -636,8 +638,9 @@ async def test_discover_dynamic_group(
|
||||
with patch(
|
||||
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
|
||||
return_value=zconf_1,
|
||||
), patch(
|
||||
"homeassistant.components.cast.media_player.asyncio.create_task",
|
||||
), patch.object(
|
||||
hass,
|
||||
"async_create_background_task",
|
||||
wraps=create_task,
|
||||
):
|
||||
discover_cast(
|
||||
|
Loading…
x
Reference in New Issue
Block a user