From 0afa9647248b8eb0eff3b42ac99c7964381fe0f9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 2 Aug 2023 20:29:03 +0200 Subject: [PATCH] Fix async_timeout DeprecationWarnings (#97622) --- homeassistant/components/media_player/__init__.py | 13 +++++++------ homeassistant/components/upb/config_flow.py | 5 +++-- homeassistant/components/webostv/media_player.py | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 39b67477f97..501fa5c3fb8 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -1258,12 +1258,13 @@ async def async_fetch_image( """Retrieve an image.""" content, content_type = (None, None) websession = async_get_clientsession(hass) - with suppress(asyncio.TimeoutError), async_timeout.timeout(10): - response = await websession.get(url) - if response.status == HTTPStatus.OK: - content = await response.read() - if content_type := response.headers.get(CONTENT_TYPE): - content_type = content_type.split(";")[0] + with suppress(asyncio.TimeoutError): + async with async_timeout.timeout(10): + response = await websession.get(url) + if response.status == HTTPStatus.OK: + content = await response.read() + if content_type := response.headers.get(CONTENT_TYPE): + content_type = content_type.split(";")[0] if content is None: url_parts = URL(url) diff --git a/homeassistant/components/upb/config_flow.py b/homeassistant/components/upb/config_flow.py index 4a3d970a068..728d46acd76 100644 --- a/homeassistant/components/upb/config_flow.py +++ b/homeassistant/components/upb/config_flow.py @@ -44,8 +44,9 @@ async def _validate_input(data): upb.connect(_connected_callback) - with suppress(asyncio.TimeoutError), async_timeout.timeout(VALIDATE_TIMEOUT): - await connected_event.wait() + with suppress(asyncio.TimeoutError): + async with async_timeout.timeout(VALIDATE_TIMEOUT): + await connected_event.wait() upb.disconnect() diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index c2851cb4c6e..664b45e92cb 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -479,10 +479,11 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): ssl_context = SSLContext() websession = async_get_clientsession(self.hass) - with suppress(asyncio.TimeoutError), async_timeout.timeout(10): - response = await websession.get(url, ssl=ssl_context) - if response.status == HTTPStatus.OK: - content = await response.read() + with suppress(asyncio.TimeoutError): + async with async_timeout.timeout(10): + response = await websession.get(url, ssl=ssl_context) + if response.status == HTTPStatus.OK: + content = await response.read() if content is None: _LOGGER.warning("Error retrieving proxied image from %s", url)