Fix lock being unexpectedly reset on close (#218)

* Implement a backoff for legacy devices

* do not clear self.query_lock at close()

* revert backoff
This commit is contained in:
J. Nick Koston 2021-09-26 12:38:33 -05:00 committed by GitHub
parent 3cf549e32e
commit 33bc38b57f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,7 +28,6 @@ class TPLinkSmartHomeProtocol:
INITIALIZATION_VECTOR = 171 INITIALIZATION_VECTOR = 171
DEFAULT_PORT = 9999 DEFAULT_PORT = 9999
DEFAULT_TIMEOUT = 5 DEFAULT_TIMEOUT = 5
BLOCK_SIZE = 4 BLOCK_SIZE = 4
def __init__(self, host: str) -> None: def __init__(self, host: str) -> None:
@ -111,7 +110,7 @@ class TPLinkSmartHomeProtocol:
async def close(self): async def close(self):
"""Close the connection.""" """Close the connection."""
writer = self.writer writer = self.writer
self._reset() self.reader = self.writer = None
if writer: if writer:
writer.close() writer.close()
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
@ -119,10 +118,7 @@ class TPLinkSmartHomeProtocol:
def _reset(self): def _reset(self):
"""Clear any varibles that should not survive between loops.""" """Clear any varibles that should not survive between loops."""
self.writer = None self.reader = self.writer = self.loop = self.query_lock = None
self.reader = None
self.query_lock = None
self.loop = None
async def _query(self, request: str, retry_count: int, timeout: int) -> Dict: async def _query(self, request: str, retry_count: int, timeout: int) -> Dict:
"""Try to query a device.""" """Try to query a device."""