8000 Improve typing for protocol class (#289) · allandaly/python-kasa@bcb9fe1 · GitHub
[go: up one dir, main page]

Skip to content

Commit bcb9fe1

Browse files
authored
Improve typing for protocol class (python-kasa#289)
1 parent b4036e5 commit bcb9fe1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kasa/protocol.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import logging
1616
import struct
1717
from pprint import pformat as pf
18-
from typing import Dict, Optional, Union
18+
from typing import Dict, Generator, Optional, Union
1919

2020
from .exceptions import SmartDeviceException
2121

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

108108
return json_payload
109109

110-
async def close(self):
110+
async def close(self) -> None:
111111
"""Close the connection."""
112112
writer = self.writer
113113
self.reader = self.writer = None
@@ -116,7 +116,7 @@ async def close(self):
116116
with contextlib.suppress(Exception):
117117
await writer.wait_closed()
118118

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

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

157-
def __del__(self):
157+
def __del__(self) -> None:
158158
if self.writer and self.loop and self.loop.is_running():
159159
self.writer.close()
160160
self._reset()
161161

162162
@staticmethod
163-
def _xor_payload(unencrypted):
163+
def _xor_payload(unencrypted: bytes) -> Generator[int, None, None]:
164164
key = TPLinkSmartHomeProtocol.INITIALIZATION_VECTOR
165165
for unencryptedbyte in unencrypted:
166166
key = key ^ unencryptedbyte
@@ -179,7 +179,7 @@ def encrypt(request: str) -> bytes:
179179
)
180180

181181
@staticmethod
182-
def _xor_encrypted_payload(ciphertext):
182+
def _xor_encrypted_payload(ciphertext: bytes) -> Generator[int, None, None]:
183183
key = TPLinkSmartHomeProtocol.INITIALIZATION_VECTOR
184184
for cipherbyte in ciphertext:
185185
plainbyte = key ^ cipherbyte

0 commit comments

Comments
 (0)
0