mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Backoff after xor timeout and improve error reporting (#1424)
This commit is contained in:
@@ -98,12 +98,26 @@ class IotProtocol(BaseProtocol):
|
||||
)
|
||||
raise auex
|
||||
except _RetryableError as ex:
|
||||
if retry == 0:
|
||||
_LOGGER.debug(
|
||||
"Device %s got a retryable error, will retry %s times: %s",
|
||||
self._host,
|
||||
retry_count,
|
||||
ex,
|
||||
)
|
||||
await self._transport.reset()
|
||||
if retry >= retry_count:
|
||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
||||
raise ex
|
||||
continue
|
||||
except TimeoutError as ex:
|
||||
if retry == 0:
|
||||
_LOGGER.debug(
|
||||
"Device %s got a timeout error, will retry %s times: %s",
|
||||
self._host,
|
||||
retry_count,
|
||||
ex,
|
||||
)
|
||||
await self._transport.reset()
|
||||
if retry >= retry_count:
|
||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
||||
|
@@ -23,6 +23,7 @@ from collections.abc import Generator
|
||||
|
||||
from kasa.deviceconfig import DeviceConfig
|
||||
from kasa.exceptions import KasaException, _RetryableError
|
||||
from kasa.exceptions import TimeoutError as KasaTimeoutError
|
||||
from kasa.json import loads as json_loads
|
||||
|
||||
from .basetransport import BaseTransport
|
||||
@@ -126,6 +127,12 @@ class XorTransport(BaseTransport):
|
||||
# This is especially import when there are multiple tplink devices being polled.
|
||||
try:
|
||||
await self._connect(self._timeout)
|
||||
except TimeoutError as ex:
|
||||
await self.reset()
|
||||
raise KasaTimeoutError(
|
||||
f"Timeout after {self._timeout} seconds connecting to the device:"
|
||||
f" {self._host}:{self._port}: {ex}"
|
||||
) from ex
|
||||
except ConnectionRefusedError as ex:
|
||||
await self.reset()
|
||||
raise KasaException(
|
||||
@@ -159,6 +166,12 @@ class XorTransport(BaseTransport):
|
||||
assert self.writer is not None # noqa: S101
|
||||
async with asyncio_timeout(self._timeout):
|
||||
return await self._execute_send(request)
|
||||
except TimeoutError as ex:
|
||||
await self.reset()
|
||||
raise KasaTimeoutError(
|
||||
f"Timeout after {self._timeout} seconds sending request to the device"
|
||||
f" {self._host}:{self._port}: {ex}"
|
||||
) from ex
|
||||
except Exception as ex:
|
||||
await self.reset()
|
||||
raise _RetryableError(
|
||||
|
Reference in New Issue
Block a user