Improve and document close behavior (#654)

* Close connection on smartprotocol timeout

* tweaks
This commit is contained in:
J. Nick Koston
2024-01-19 10:30:01 -10:00
committed by GitHub
parent 38159140fb
commit d62b5a55cc
3 changed files with 16 additions and 12 deletions

View File

@@ -84,8 +84,8 @@ class SmartProtocol(TPLinkProtocol):
raise ex
continue
except TimeoutException as ex:
await self.close()
if retry >= retry_count:
await self.close()
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
raise ex
await asyncio.sleep(self.BACKOFF_SECONDS_AFTER_TIMEOUT)
@@ -167,7 +167,12 @@ class SmartProtocol(TPLinkProtocol):
raise SmartDeviceException(msg, error_code=error_code)
async def close(self) -> None:
"""Close the protocol."""
"""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.
"""
await self._transport.close()