mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-02-04 18:10:02 +00:00
add typing hints to make it easier for 3rd party developers to use the library (#90)
* add typing hints to make it easier for 3rd party developers to use the library * remove unused devicetype enum to support python3.3 * add python 3.3 to travis and tox, install typing module in setup.py
This commit is contained in:
@@ -2,6 +2,7 @@ import json
|
||||
import socket
|
||||
import struct
|
||||
import logging
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -24,7 +25,9 @@ class TPLinkSmartHomeProtocol:
|
||||
DEFAULT_TIMEOUT = 5
|
||||
|
||||
@staticmethod
|
||||
def query(host, request, port=DEFAULT_PORT):
|
||||
def query(host: str,
|
||||
request: Union[str, Dict],
|
||||
port: int = DEFAULT_PORT) -> Any:
|
||||
"""
|
||||
Request information from a TP-Link SmartHome Device and return the
|
||||
response.
|
||||
@@ -76,7 +79,7 @@ class TPLinkSmartHomeProtocol:
|
||||
return json.loads(response)
|
||||
|
||||
@staticmethod
|
||||
def encrypt(request):
|
||||
def encrypt(request: str) -> bytearray:
|
||||
"""
|
||||
Encrypt a request for a TP-Link Smart Home Device.
|
||||
|
||||
@@ -94,7 +97,7 @@ class TPLinkSmartHomeProtocol:
|
||||
return buffer
|
||||
|
||||
@staticmethod
|
||||
def decrypt(ciphertext):
|
||||
def decrypt(ciphertext: bytes) -> str:
|
||||
"""
|
||||
Decrypt a response of a TP-Link Smart Home Device.
|
||||
|
||||
@@ -104,9 +107,9 @@ class TPLinkSmartHomeProtocol:
|
||||
key = TPLinkSmartHomeProtocol.INITIALIZATION_VECTOR
|
||||
buffer = []
|
||||
|
||||
ciphertext = ciphertext.decode('latin-1')
|
||||
ciphertext_str = ciphertext.decode('latin-1')
|
||||
|
||||
for char in ciphertext:
|
||||
for char in ciphertext_str:
|
||||
plain = key ^ ord(char)
|
||||
key = ord(char)
|
||||
buffer.append(chr(plain))
|
||||
|
||||
Reference in New Issue
Block a user