Switch samsungtv to use async_timeout to avoid task creation (#88679)

wait_for creates a task, async_timeout does the same work
and avoids the task creation
pull/88681/head^2
J. Nick Koston 2023-02-23 22:00:08 -06:00 committed by GitHub
parent d90ee85118
commit 0ae2fdc08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from collections.abc import Coroutine, Sequence
from datetime import datetime, timedelta
from typing import Any
import async_timeout
from async_upnp_client.aiohttp import AiohttpNotifyServer, AiohttpSessionRequester
from async_upnp_client.client import UpnpDevice, UpnpService, UpnpStateVariable
from async_upnp_client.client_factory import UpnpFactory
@ -250,7 +251,8 @@ class SamsungTVDevice(MediaPlayerEntity):
# enter it unless we have to (Python 3.11 will have zero cost try)
return
try:
await asyncio.wait_for(self._app_list_event.wait(), APP_LIST_DELAY)
async with async_timeout.timeout(APP_LIST_DELAY):
await self._app_list_event.wait()
except asyncio.TimeoutError as err:
# No need to try again
self._app_list_event.set()