Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix remaining typing #31

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _make_general_data(self) -> dict[Any, Any]:
return {}

async def _api_request(
self, endpoint: str, data: dict, header: dict[Any, Any] | None = None
self, endpoint: str, data: dict[str, Any], header: dict[str, Any] | None = None
) -> dict | None:
header = header or {}
if not data.get("reqId"):
Expand Down Expand Up @@ -249,7 +249,7 @@ async def login(self) -> bool:
):
self._access_token = response["mdata"]["accessToken"]
self._security.set_aes_keys(
self._security.aes_decrypt_with_fixed_key(response["key"]), None
self._security.aes_decrypt_with_fixed_key(response["key"]), b"0"
)

return True
Expand Down Expand Up @@ -319,11 +319,7 @@ async def get_device_info(self, device_id: str) -> dict[str, Any] | None:
device_info = {
"name": response.get("name"),
"type": int(model_type, 16) if model_type else 0,
"sn": (
self._security.aes_decrypt(response.get("sn"))
if response.get("sn")
else ""
),
"sn": (self._security.aes_decrypt(response.get("sn") or "")),
"sn8": response.get("sn8", "00000000"),
"model_number": model_number,
"manufacturer_code": response.get("enterpriseCode", "0000"),
Expand Down Expand Up @@ -413,7 +409,7 @@ def _make_general_data(self) -> dict[str, Any]:
}

async def _api_request(
self, endpoint: str, data: dict, header: dict | None = None
self, endpoint: str, data: dict[str, Any], header: dict[str, Any] | None = None
) -> dict[str, Any] | None:
header = header or {}
header.update(
Expand Down Expand Up @@ -582,7 +578,7 @@ def _make_general_data(self) -> dict[str, Any]:
return data

async def _api_request(
self, endpoint: str, data: dict, header: dict[str, Any] | None = None
self, endpoint: str, data: dict[str, Any], header: dict[str, Any] | None = None
) -> dict[str, Any] | None:
header = header or {}
if not data.get("reqId"):
Expand Down
2 changes: 1 addition & 1 deletion midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def refresh_status(self, wait_response: bool = False) -> None:
if error_count == len(cmds):
raise RefreshFailed

def pre_process_message(self, msg: bytes) -> bool:
def pre_process_message(self, msg: bytearray) -> bool:
if msg[9] == MessageType.query_appliance:
message = MessageApplianceResponse(msg)
self._appliance_query = False
Expand Down
10 changes: 5 additions & 5 deletions midealocal/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def __init__(
self._fixed_key = format(fixed_key, "x").encode("ascii") if fixed_key else None
self._fixed_iv = format(fixed_iv, "x").encode("ascii") if fixed_iv else None

def sign(self, url: str, data: str, random: str) -> str | None:
def sign(self, url: str, data: dict[str, Any] | str, random: str) -> str | None:
msg: str = self._iot_key or ""
msg += data
msg += str(data)
msg += random
if not self._hmac_key:
return None
Expand Down Expand Up @@ -80,7 +80,7 @@ def set_aes_keys(self, key: bytes | str, iv: bytes | str) -> None:
self._aes_key = key
self._aes_iv = iv

def aes_encrypt_with_fixed_key(self, data: str) -> bytes:
def aes_encrypt_with_fixed_key(self, data: bytes) -> bytes:
rokam marked this conversation as resolved.
Show resolved Hide resolved
return self.aes_encrypt(data, self._fixed_key, self._fixed_iv)

def aes_decrypt_with_fixed_key(self, data: str) -> str:
Expand Down Expand Up @@ -205,10 +205,10 @@ def __init__(self) -> None:
self._request_count = 0
self._response_count = 0

def aes_decrypt(self, raw: bytes) -> bytes:
def aes_decrypt(self, raw: bytes) -> bytearray:
try:
return cast(
bytes,
bytearray,
unpad(AES.new(self.aes_key, AES.MODE_ECB).decrypt(bytearray(raw)), 16),
)
except ValueError:
Expand Down
Loading