Skip to content

Commit

Permalink
chore: typing b4 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 authored Jun 3, 2024
1 parent 1a792de commit 12e8179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
11 changes: 6 additions & 5 deletions midealocal/devices/b4/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys
from typing import Any

from .message import MessageB4Response, MessageQuery

Expand All @@ -24,7 +25,7 @@ class DeviceAttributes(StrEnum):


class MideaB4Device(MideaDevice):
_status = {
_status: dict[int, str] = {
0x01: "Standby",
0x02: "Idle",
0x03: "Working",
Expand All @@ -45,7 +46,7 @@ def __init__(
model: str,
subtype: int,
customize: str,
):
) -> None:
super().__init__(
name=name,
device_id=device_id,
Expand All @@ -68,10 +69,10 @@ def __init__(
},
)

def build_query(self):
def build_query(self) -> list[MessageQuery]:
return [MessageQuery(self._protocol_version)]

def process_message(self, msg):
def process_message(self, msg: bytes) -> dict[str, Any]:
message = MessageB4Response(msg)
_LOGGER.debug(f"[{self.device_id}] Received: {message}")
new_status = {}
Expand All @@ -90,7 +91,7 @@ def process_message(self, msg):
new_status[str(status)] = self._attributes[status]
return new_status

def set_attribute(self, attr, value):
def set_attribute(self, attr: str, value: Any) -> None:
pass


Expand Down
16 changes: 9 additions & 7 deletions midealocal/devices/b4/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


class MessageB4Base(MessageRequest):
def __init__(self, protocol_version, message_type, body_type):
def __init__(
self, protocol_version: int, message_type: int, body_type: int
) -> None:
super().__init__(
device_type=0xB4,
protocol_version=protocol_version,
Expand All @@ -11,25 +13,25 @@ def __init__(self, protocol_version, message_type, body_type):
)

@property
def _body(self):
def _body(self) -> bytearray:
raise NotImplementedError


class MessageQuery(MessageB4Base):
def __init__(self, protocol_version):
def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=0x01,
)

@property
def _body(self):
def _body(self) -> bytearray:
return bytearray([])


class B4MessageBody(MessageBody):
def __init__(self, body):
def __init__(self, body: bytearray) -> None:
super().__init__(body)
self.time_remaining = (
(0 if body[22] == 0xFF else body[22]) * 3600
Expand All @@ -47,8 +49,8 @@ def __init__(self, body):


class MessageB4Response(MessageResponse):
def __init__(self, message):
super().__init__(message)
def __init__(self, message: bytes) -> None:
super().__init__(bytearray(message))
if self.message_type in [
MessageType.notify1,
MessageType.query,
Expand Down

0 comments on commit 12e8179

Please sign in to comment.