Use async_timeout instead of asyncio.wait_for (#90496)

* Use async_timeout instead of asyncio.wait_for

* fix imports

* fix imports

* break out Event.wait patch

* Update tests/components/reolink/conftest.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Simplify

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
starkillerOG 2023-04-01 17:47:31 +02:00 committed by GitHub
parent 9cab05c4b9
commit b47ac524ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 14 deletions

View file

@ -8,6 +8,7 @@ from typing import Any
import aiohttp
from aiohttp.web import Request
import async_timeout
from reolink_aio.api import Host
from reolink_aio.exceptions import ReolinkError, SubscriptionError
@ -23,6 +24,7 @@ from .const import CONF_PROTOCOL, CONF_USE_HTTPS, DOMAIN
from .exceptions import ReolinkSetupException, ReolinkWebhookException, UserNotAdmin
DEFAULT_TIMEOUT = 60
FIRST_ONVIF_TIMEOUT = 15
SUBSCRIPTION_RENEW_THRESHOLD = 300
_LOGGER = logging.getLogger(__name__)
@ -146,11 +148,13 @@ class ReolinkHost:
"Waiting for initial ONVIF state on webhook '%s'", self._webhook_url
)
try:
await asyncio.wait_for(self._webhook_reachable.wait(), timeout=15)
async with async_timeout.timeout(FIRST_ONVIF_TIMEOUT):
await self._webhook_reachable.wait()
except asyncio.TimeoutError:
_LOGGER.debug(
"Did not receive initial ONVIF state on webhook '%s' after 15 seconds",
"Did not receive initial ONVIF state on webhook '%s' after %i seconds",
self._webhook_url,
FIRST_ONVIF_TIMEOUT,
)
ir.async_create_issue(
self._hass,