Avoid reset for all connection errors

This commit is contained in:
sdb9696 2024-01-23 17:51:18 +00:00
parent 0e874a35f1
commit f68acb60e7
6 changed files with 6 additions and 30 deletions

View File

@ -42,10 +42,6 @@ class ConnectionException(SmartDeviceException):
"""Connection exception for device errors."""
class DisconnectedException(SmartDeviceException):
"""Disconnected exception for device errors."""
class SmartErrorCode(IntEnum):
"""Enum for SMART Error Codes."""

View File

@ -7,7 +7,6 @@ import aiohttp
from .deviceconfig import DeviceConfig
from .exceptions import (
ConnectionException,
DisconnectedException,
SmartDeviceException,
TimeoutException,
)
@ -81,13 +80,9 @@ class HttpClient:
if return_json:
response_data = json_loads(response_data.decode())
except aiohttp.ServerDisconnectedError as ex:
raise DisconnectedException(
f"Disconnected from the device: {self._config.host}: {ex}", ex
) from ex
except aiohttp.ClientOSError as ex:
except (aiohttp.ServerDisconnectedError, aiohttp.ClientOSError) as ex:
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
except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as ex:
raise TimeoutException(

View File

@ -6,7 +6,6 @@ from typing import Dict, Union
from .exceptions import (
AuthenticationException,
ConnectionException,
DisconnectedException,
RetryableException,
SmartDeviceException,
TimeoutException,
@ -45,13 +44,7 @@ class IotProtocol(BaseProtocol):
for retry in range(retry_count + 1):
try:
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:
await self._transport.reset()
if retry >= retry_count:
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise sdex

View File

@ -18,7 +18,6 @@ from .exceptions import (
SMART_TIMEOUT_ERRORS,
AuthenticationException,
ConnectionException,
DisconnectedException,
RetryableException,
SmartDeviceException,
SmartErrorCode,
@ -66,13 +65,7 @@ class SmartProtocol(BaseProtocol):
for retry in range(retry_count + 1):
try:
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:
await self._transport.reset()
if retry >= retry_count:
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise sdex

View File

@ -7,7 +7,6 @@ import pytest
from ..deviceconfig import DeviceConfig
from ..exceptions import (
ConnectionException,
DisconnectedException,
SmartDeviceException,
TimeoutException,
)
@ -19,13 +18,13 @@ from ..httpclient import HttpClient
[
(
aiohttp.ServerDisconnectedError(),
DisconnectedException,
"Disconnected from the device: ",
ConnectionException,
"Device connection error: ",
),
(
aiohttp.ClientOSError(),
ConnectionException,
"Unable to connect to the device: ",
"Device connection error: ",
),
(
aiohttp.ServerTimeoutError(),

View File

@ -57,7 +57,7 @@ class _mock_response:
(aiohttp.ServerDisconnectedError("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("protocol_class", [IotProtocol, SmartProtocol])