FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve typing for protocol class by rytilahti · Pull Request #289 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 6 additions & 6 deletions kasa/protocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import logging
import struct
from pprint import pformat as pf
from typing import Dict, Optional, Union
from typing import Dict, Generator, Optional, Union

from .exceptions import SmartDeviceException

Expand Down Expand Up @@ -107,7 +107,7 @@ async def _execute_query(self, request: str) -> Dict:

return json_payload

async def close(self):
async def close(self) -> None:
"""Close the connection."""
writer = self.writer
self.reader = self.writer = None
Expand All @@ -116,7 +116,7 @@ async def close(self):
with contextlib.suppress(Exception):
await writer.wait_closed()

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

Expand Down Expand Up @@ -154,13 +154,13 @@ async def _query(self, request: str, retry_count: int, timeout: int) -> Dict:
await self.close()
raise SmartDeviceException("Query reached somehow to unreachable")

def __del__(self):
def __del__(self) -> None:
if self.writer and self.loop and self.loop.is_running():
self.writer.close()
self._reset()

@staticmethod
def _xor_payload(unencrypted):
def _xor_payload(unencrypted: bytes) -> Generator[int, None, None]:
key = TPLinkSmartHomeProtocol.INITIALIZATION_VECTOR
for unencryptedbyte in unencrypted:
key = key ^ unencryptedbyte
Expand All @@ -179,7 +179,7 @@ def encrypt(request: str) -> bytes:
)

@staticmethod
def _xor_encrypted_payload(ciphertext):
def _xor_encrypted_payload(ciphertext: bytes) -> Generator[int, None, None]:
key = TPLinkSmartHomeProtocol.INITIALIZATION_VECTOR
for cipherbyte in ciphertext:
plainbyte = key ^ cipherbyte
Expand Down

Back | FazBrowse Home | New Git URL