Use asyncio.timeout [core] (#98447)
This commit is contained in:
@@ -13,7 +13,6 @@ import aiohttp
|
||||
from aiohttp import web
|
||||
from aiohttp.hdrs import CONTENT_TYPE, USER_AGENT
|
||||
from aiohttp.web_exceptions import HTTPBadGateway, HTTPGatewayTimeout
|
||||
import async_timeout
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import APPLICATION_NAME, EVENT_HOMEASSISTANT_CLOSE, __version__
|
||||
@@ -170,7 +169,7 @@ async def async_aiohttp_proxy_web(
|
||||
) -> web.StreamResponse | None:
|
||||
"""Stream websession request to aiohttp web response."""
|
||||
try:
|
||||
async with async_timeout.timeout(timeout):
|
||||
async with asyncio.timeout(timeout):
|
||||
req = await web_coro
|
||||
|
||||
except asyncio.CancelledError:
|
||||
@@ -211,7 +210,7 @@ async def async_aiohttp_proxy_stream(
|
||||
# Suppressing something went wrong fetching data, closed connection
|
||||
with suppress(asyncio.TimeoutError, aiohttp.ClientError):
|
||||
while hass.is_running:
|
||||
async with async_timeout.timeout(timeout):
|
||||
async with asyncio.timeout(timeout):
|
||||
data = await stream.read(buffer_size)
|
||||
|
||||
if not data:
|
||||
|
||||
@@ -16,7 +16,6 @@ import time
|
||||
from typing import Any, cast
|
||||
|
||||
from aiohttp import client, web
|
||||
import async_timeout
|
||||
import jwt
|
||||
import voluptuous as vol
|
||||
from yarl import URL
|
||||
@@ -287,7 +286,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta):
|
||||
return self.async_external_step_done(next_step_id=next_step)
|
||||
|
||||
try:
|
||||
async with async_timeout.timeout(OAUTH_AUTHORIZE_URL_TIMEOUT_SEC):
|
||||
async with asyncio.timeout(OAUTH_AUTHORIZE_URL_TIMEOUT_SEC):
|
||||
url = await self.async_generate_authorize_url()
|
||||
except asyncio.TimeoutError as err:
|
||||
_LOGGER.error("Timeout generating authorize url: %s", err)
|
||||
@@ -311,7 +310,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta):
|
||||
_LOGGER.debug("Creating config entry from external data")
|
||||
|
||||
try:
|
||||
async with async_timeout.timeout(OAUTH_TOKEN_TIMEOUT_SEC):
|
||||
async with asyncio.timeout(OAUTH_TOKEN_TIMEOUT_SEC):
|
||||
token = await self.flow_impl.async_resolve_external_data(
|
||||
self.external_data
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ import logging
|
||||
from types import MappingProxyType
|
||||
from typing import Any, TypedDict, TypeVar, cast
|
||||
|
||||
import async_timeout
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import exceptions
|
||||
@@ -574,7 +573,7 @@ class _ScriptRun:
|
||||
self._changed()
|
||||
trace_set_result(delay=delay, done=False)
|
||||
try:
|
||||
async with async_timeout.timeout(delay):
|
||||
async with asyncio.timeout(delay):
|
||||
await self._stop.wait()
|
||||
except asyncio.TimeoutError:
|
||||
trace_set_result(delay=delay, done=True)
|
||||
@@ -602,9 +601,10 @@ class _ScriptRun:
|
||||
@callback
|
||||
def async_script_wait(entity_id, from_s, to_s):
|
||||
"""Handle script after template condition is true."""
|
||||
# pylint: disable=protected-access
|
||||
wait_var = self._variables["wait"]
|
||||
if to_context and to_context.deadline:
|
||||
wait_var["remaining"] = to_context.deadline - self._hass.loop.time()
|
||||
if to_context and to_context._when:
|
||||
wait_var["remaining"] = to_context._when - self._hass.loop.time()
|
||||
else:
|
||||
wait_var["remaining"] = timeout
|
||||
wait_var["completed"] = True
|
||||
@@ -621,7 +621,7 @@ class _ScriptRun:
|
||||
self._hass.async_create_task(flag.wait()) for flag in (self._stop, done)
|
||||
]
|
||||
try:
|
||||
async with async_timeout.timeout(timeout) as to_context:
|
||||
async with asyncio.timeout(timeout) as to_context:
|
||||
await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
||||
except asyncio.TimeoutError as ex:
|
||||
self._variables["wait"]["remaining"] = 0.0
|
||||
@@ -971,9 +971,10 @@ class _ScriptRun:
|
||||
done = asyncio.Event()
|
||||
|
||||
async def async_done(variables, context=None):
|
||||
# pylint: disable=protected-access
|
||||
wait_var = self._variables["wait"]
|
||||
if to_context and to_context.deadline:
|
||||
wait_var["remaining"] = to_context.deadline - self._hass.loop.time()
|
||||
if to_context and to_context._when:
|
||||
wait_var["remaining"] = to_context._when - self._hass.loop.time()
|
||||
else:
|
||||
wait_var["remaining"] = timeout
|
||||
wait_var["trigger"] = variables["trigger"]
|
||||
@@ -1000,7 +1001,7 @@ class _ScriptRun:
|
||||
self._hass.async_create_task(flag.wait()) for flag in (self._stop, done)
|
||||
]
|
||||
try:
|
||||
async with async_timeout.timeout(timeout) as to_context:
|
||||
async with asyncio.timeout(timeout) as to_context:
|
||||
await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
||||
except asyncio.TimeoutError as ex:
|
||||
self._variables["wait"]["remaining"] = 0.0
|
||||
|
||||
@@ -34,7 +34,6 @@ from typing import (
|
||||
from urllib.parse import urlencode as urllib_urlencode
|
||||
import weakref
|
||||
|
||||
import async_timeout
|
||||
from awesomeversion import AwesomeVersion
|
||||
import jinja2
|
||||
from jinja2 import pass_context, pass_environment, pass_eval_context
|
||||
@@ -651,7 +650,7 @@ class Template:
|
||||
try:
|
||||
template_render_thread = ThreadWithException(target=_render_template)
|
||||
template_render_thread.start()
|
||||
async with async_timeout.timeout(timeout):
|
||||
async with asyncio.timeout(timeout):
|
||||
await finish_event.wait()
|
||||
if self._exc_info:
|
||||
raise TemplateError(self._exc_info[1].with_traceback(self._exc_info[2]))
|
||||
|
||||
Reference in New Issue
Block a user