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