Improve timeout error reporting

This commit is contained in:
J. Nick Koston 2025-01-05 13:33:32 -10:00
parent 1f45f425a0
commit c5bf1ccc4e
No known key found for this signature in database

View File

@ -126,6 +126,12 @@ class XorTransport(BaseTransport):
# This is especially import when there are multiple tplink devices being polled. # This is especially import when there are multiple tplink devices being polled.
try: try:
await self._connect(self._timeout) await self._connect(self._timeout)
except TimeoutError as ex:
await self.reset()
raise _RetryableError(
f"Timeout after {self._timeout} seconds connecting to the device:"
f" {self._host}:{self._port}: {ex}"
) from ex
except ConnectionRefusedError as ex: except ConnectionRefusedError as ex:
await self.reset() await self.reset()
raise KasaException( raise KasaException(
@ -159,6 +165,12 @@ class XorTransport(BaseTransport):
assert self.writer is not None # noqa: S101 assert self.writer is not None # noqa: S101
async with asyncio_timeout(self._timeout): async with asyncio_timeout(self._timeout):
return await self._execute_send(request) return await self._execute_send(request)
except TimeoutError as ex:
await self.reset()
raise _RetryableError(
f"Timeout after {self._timeout} seconds sending request to the device"
f" {self._host}:{self._port}: {ex}"
) from ex
except Exception as ex: except Exception as ex:
await self.reset() await self.reset()
raise _RetryableError( raise _RetryableError(