Use builtin TimeoutError [t-z] (#109683)

This commit is contained in:
Marc Mueller 2024-02-05 12:20:36 +01:00 committed by GitHub
parent 438d3b01b9
commit 8b0c9d3d18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
63 changed files with 88 additions and 122 deletions

View file

@ -1,7 +1,6 @@
"""Connection session."""
from __future__ import annotations
import asyncio
from collections.abc import Callable, Hashable
from contextvars import ContextVar
from typing import TYPE_CHECKING, Any
@ -266,7 +265,7 @@ class ActiveConnection:
elif isinstance(err, vol.Invalid):
code = const.ERR_INVALID_FORMAT
err_message = vol.humanize.humanize_error(msg, err)
elif isinstance(err, asyncio.TimeoutError):
elif isinstance(err, TimeoutError):
code = const.ERR_TIMEOUT
err_message = "Timeout"
elif isinstance(err, HomeAssistantError):

View file

@ -282,7 +282,7 @@ class WebSocketHandler:
try:
async with asyncio.timeout(10):
await wsock.prepare(request)
except asyncio.TimeoutError:
except TimeoutError:
self._logger.warning("Timeout preparing request from %s", request.remote)
return wsock
@ -310,7 +310,7 @@ class WebSocketHandler:
# Auth Phase
try:
msg = await wsock.receive(10)
except asyncio.TimeoutError as err:
except TimeoutError as err:
disconnect_warn = "Did not receive auth message within 10 seconds"
raise Disconnect from err