Update transport close/reset behaviour (#689)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Steven B
2024-01-23 22:15:18 +00:00
committed by GitHub
parent e576fcdb46
commit 1788c50146
13 changed files with 66 additions and 43 deletions

View File

@@ -66,32 +66,31 @@ class SmartProtocol(BaseProtocol):
try:
return await self._execute_query(request, retry)
except ConnectionException as sdex:
await self.close()
if retry >= retry_count:
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise sdex
continue
except AuthenticationException as auex:
await self.close()
await self._transport.reset()
_LOGGER.debug(
"Unable to authenticate with %s, not retrying", self._host
)
raise auex
except RetryableException as ex:
await self.close()
await self._transport.reset()
if retry >= retry_count:
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise ex
continue
except TimeoutException as ex:
await self.close()
await self._transport.reset()
if retry >= retry_count:
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise ex
await asyncio.sleep(self.BACKOFF_SECONDS_AFTER_TIMEOUT)
continue
except SmartDeviceException as ex:
await self.close()
await self._transport.reset()
_LOGGER.debug(
"Unable to query the device: %s, not retrying: %s",
self._host,
@@ -167,12 +166,7 @@ class SmartProtocol(BaseProtocol):
raise SmartDeviceException(msg, error_code=error_code)
async def close(self) -> None:
"""Close the underlying transport.
Some transports may close the connection, and some may
use this as a hint that they need to reconnect, or
reauthenticate.
"""
"""Close the underlying transport."""
await self._transport.close()