Skip to content

Commit

Permalink
Fix lock being unexpectedly reset on close (#218)
Browse files Browse the repository at this point in the history
* Implement a backoff for legacy devices

* do not clear self.query_lock at close()

* revert backoff
  • Loading branch information
bdraco committed Sep 26, 2021
1 parent 3cf549e commit 33bc38b
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions kasa/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class TPLinkSmartHomeProtocol:
INITIALIZATION_VECTOR = 171
DEFAULT_PORT = 9999
DEFAULT_TIMEOUT = 5

BLOCK_SIZE = 4

def __init__(self, host: str) -> None:
Expand Down Expand Up @@ -111,18 +110,15 @@ async def _execute_query(self, request: str) -> Dict:
async def close(self):
"""Close the connection."""
writer = self.writer
self._reset()
self.reader = self.writer = None
if writer:
writer.close()
with contextlib.suppress(Exception):
await writer.wait_closed()

def _reset(self):
"""Clear any varibles that should not survive between loops."""
self.writer = None
self.reader = None
self.query_lock = None
self.loop = None
self.reader = self.writer = self.loop = self.query_lock = None

async def _query(self, request: str, retry_count: int, timeout: int) -> Dict:
"""Try to query a device."""
Expand Down

0 comments on commit 33bc38b

Please sign in to comment.