mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-27 09:06:24 +00:00
Avoid reset for all connection errors
This commit is contained in:
parent
0e874a35f1
commit
f68acb60e7
@ -42,10 +42,6 @@ class ConnectionException(SmartDeviceException):
|
|||||||
"""Connection exception for device errors."""
|
"""Connection exception for device errors."""
|
||||||
|
|
||||||
|
|
||||||
class DisconnectedException(SmartDeviceException):
|
|
||||||
"""Disconnected exception for device errors."""
|
|
||||||
|
|
||||||
|
|
||||||
class SmartErrorCode(IntEnum):
|
class SmartErrorCode(IntEnum):
|
||||||
"""Enum for SMART Error Codes."""
|
"""Enum for SMART Error Codes."""
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import aiohttp
|
|||||||
from .deviceconfig import DeviceConfig
|
from .deviceconfig import DeviceConfig
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
ConnectionException,
|
ConnectionException,
|
||||||
DisconnectedException,
|
|
||||||
SmartDeviceException,
|
SmartDeviceException,
|
||||||
TimeoutException,
|
TimeoutException,
|
||||||
)
|
)
|
||||||
@ -81,13 +80,9 @@ class HttpClient:
|
|||||||
if return_json:
|
if return_json:
|
||||||
response_data = json_loads(response_data.decode())
|
response_data = json_loads(response_data.decode())
|
||||||
|
|
||||||
except aiohttp.ServerDisconnectedError as ex:
|
except (aiohttp.ServerDisconnectedError, aiohttp.ClientOSError) as ex:
|
||||||
raise DisconnectedException(
|
|
||||||
f"Disconnected from the device: {self._config.host}: {ex}", ex
|
|
||||||
) from ex
|
|
||||||
except aiohttp.ClientOSError as ex:
|
|
||||||
raise ConnectionException(
|
raise ConnectionException(
|
||||||
f"Unable to connect to the device: {self._config.host}: {ex}", ex
|
f"Device connection error: {self._config.host}: {ex}", ex
|
||||||
) from ex
|
) from ex
|
||||||
except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as ex:
|
except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as ex:
|
||||||
raise TimeoutException(
|
raise TimeoutException(
|
||||||
|
@ -6,7 +6,6 @@ from typing import Dict, Union
|
|||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
AuthenticationException,
|
AuthenticationException,
|
||||||
ConnectionException,
|
ConnectionException,
|
||||||
DisconnectedException,
|
|
||||||
RetryableException,
|
RetryableException,
|
||||||
SmartDeviceException,
|
SmartDeviceException,
|
||||||
TimeoutException,
|
TimeoutException,
|
||||||
@ -45,13 +44,7 @@ class IotProtocol(BaseProtocol):
|
|||||||
for retry in range(retry_count + 1):
|
for retry in range(retry_count + 1):
|
||||||
try:
|
try:
|
||||||
return await self._execute_query(request, retry)
|
return await self._execute_query(request, retry)
|
||||||
except DisconnectedException as sdex:
|
|
||||||
if retry >= retry_count:
|
|
||||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
|
||||||
raise sdex
|
|
||||||
continue
|
|
||||||
except ConnectionException as sdex:
|
except ConnectionException as sdex:
|
||||||
await self._transport.reset()
|
|
||||||
if retry >= retry_count:
|
if retry >= retry_count:
|
||||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
||||||
raise sdex
|
raise sdex
|
||||||
|
@ -18,7 +18,6 @@ from .exceptions import (
|
|||||||
SMART_TIMEOUT_ERRORS,
|
SMART_TIMEOUT_ERRORS,
|
||||||
AuthenticationException,
|
AuthenticationException,
|
||||||
ConnectionException,
|
ConnectionException,
|
||||||
DisconnectedException,
|
|
||||||
RetryableException,
|
RetryableException,
|
||||||
SmartDeviceException,
|
SmartDeviceException,
|
||||||
SmartErrorCode,
|
SmartErrorCode,
|
||||||
@ -66,13 +65,7 @@ class SmartProtocol(BaseProtocol):
|
|||||||
for retry in range(retry_count + 1):
|
for retry in range(retry_count + 1):
|
||||||
try:
|
try:
|
||||||
return await self._execute_query(request, retry)
|
return await self._execute_query(request, retry)
|
||||||
except DisconnectedException as sdex:
|
|
||||||
if retry >= retry_count:
|
|
||||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
|
||||||
raise sdex
|
|
||||||
continue
|
|
||||||
except ConnectionException as sdex:
|
except ConnectionException as sdex:
|
||||||
await self._transport.reset()
|
|
||||||
if retry >= retry_count:
|
if retry >= retry_count:
|
||||||
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
||||||
raise sdex
|
raise sdex
|
||||||
|
@ -7,7 +7,6 @@ import pytest
|
|||||||
from ..deviceconfig import DeviceConfig
|
from ..deviceconfig import DeviceConfig
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
ConnectionException,
|
ConnectionException,
|
||||||
DisconnectedException,
|
|
||||||
SmartDeviceException,
|
SmartDeviceException,
|
||||||
TimeoutException,
|
TimeoutException,
|
||||||
)
|
)
|
||||||
@ -19,13 +18,13 @@ from ..httpclient import HttpClient
|
|||||||
[
|
[
|
||||||
(
|
(
|
||||||
aiohttp.ServerDisconnectedError(),
|
aiohttp.ServerDisconnectedError(),
|
||||||
DisconnectedException,
|
ConnectionException,
|
||||||
"Disconnected from the device: ",
|
"Device connection error: ",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
aiohttp.ClientOSError(),
|
aiohttp.ClientOSError(),
|
||||||
ConnectionException,
|
ConnectionException,
|
||||||
"Unable to connect to the device: ",
|
"Device connection error: ",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
aiohttp.ServerTimeoutError(),
|
aiohttp.ServerTimeoutError(),
|
||||||
|
@ -57,7 +57,7 @@ class _mock_response:
|
|||||||
(aiohttp.ServerDisconnectedError("dummy exception"), True),
|
(aiohttp.ServerDisconnectedError("dummy exception"), True),
|
||||||
(aiohttp.ClientOSError("dummy exception"), True),
|
(aiohttp.ClientOSError("dummy exception"), True),
|
||||||
],
|
],
|
||||||
ids=("Exception", "SmartDeviceException", "DisconnectError", "ConnectError"),
|
ids=("Exception", "ServerTimeoutError", "ServerDisconnectedError", "ClientOSError"),
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize("transport_class", [AesTransport, KlapTransport])
|
@pytest.mark.parametrize("transport_class", [AesTransport, KlapTransport])
|
||||||
@pytest.mark.parametrize("protocol_class", [IotProtocol, SmartProtocol])
|
@pytest.mark.parametrize("protocol_class", [IotProtocol, SmartProtocol])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user