Use asyncio.timeout [core] (#98447)

This commit is contained in:
Marc Mueller 2023-08-15 15:36:05 +02:00 committed by GitHub
parent e2d2ec8817
commit a9ade1f84d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 77 additions and 96 deletions

View file

@ -10,7 +10,6 @@ from typing import Any, Concatenate, ParamSpec, TypeVar
import aiohttp
from aiohttp import web
import async_timeout
import attr
from hass_nabucasa import Cloud, auth, thingtalk
from hass_nabucasa.const import STATE_DISCONNECTED
@ -252,7 +251,7 @@ class CloudLogoutView(HomeAssistantView):
hass = request.app["hass"]
cloud = hass.data[DOMAIN]
async with async_timeout.timeout(REQUEST_TIMEOUT):
async with asyncio.timeout(REQUEST_TIMEOUT):
await cloud.logout()
return self.json_message("ok")
@ -292,7 +291,7 @@ class CloudRegisterView(HomeAssistantView):
if location_info.zip_code is not None:
client_metadata["NC_ZIP_CODE"] = location_info.zip_code
async with async_timeout.timeout(REQUEST_TIMEOUT):
async with asyncio.timeout(REQUEST_TIMEOUT):
await cloud.auth.async_register(
data["email"],
data["password"],
@ -316,7 +315,7 @@ class CloudResendConfirmView(HomeAssistantView):
hass = request.app["hass"]
cloud = hass.data[DOMAIN]
async with async_timeout.timeout(REQUEST_TIMEOUT):
async with asyncio.timeout(REQUEST_TIMEOUT):
await cloud.auth.async_resend_email_confirm(data["email"])
return self.json_message("ok")
@ -336,7 +335,7 @@ class CloudForgotPasswordView(HomeAssistantView):
hass = request.app["hass"]
cloud = hass.data[DOMAIN]
async with async_timeout.timeout(REQUEST_TIMEOUT):
async with asyncio.timeout(REQUEST_TIMEOUT):
await cloud.auth.async_forgot_password(data["email"])
return self.json_message("ok")
@ -439,7 +438,7 @@ async def websocket_update_prefs(
if changes.get(PREF_ALEXA_REPORT_STATE):
alexa_config = await cloud.client.get_alexa_config()
try:
async with async_timeout.timeout(10):
async with asyncio.timeout(10):
await alexa_config.async_get_access_token()
except asyncio.TimeoutError:
connection.send_error(
@ -779,7 +778,7 @@ async def alexa_sync(
cloud = hass.data[DOMAIN]
alexa_config = await cloud.client.get_alexa_config()
async with async_timeout.timeout(10):
async with asyncio.timeout(10):
try:
success = await alexa_config.async_sync_entities()
except alexa_errors.NoTokenAvailable:
@ -808,7 +807,7 @@ async def thingtalk_convert(
"""Convert a query."""
cloud = hass.data[DOMAIN]
async with async_timeout.timeout(10):
async with asyncio.timeout(10):
try:
connection.send_result(
msg["id"], await thingtalk.async_convert(cloud, msg["query"])