Fix async_timeout DeprecationWarnings (#97622)

This commit is contained in:
Marc Mueller 2023-08-02 20:29:03 +02:00 committed by GitHub
parent 1a77121c02
commit 0afa964724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 12 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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)