diff --git a/midealocal/devices/bf/__init__.py b/midealocal/devices/bf/__init__.py index c5d3a78d..a84f7f27 100644 --- a/midealocal/devices/bf/__init__.py +++ b/midealocal/devices/bf/__init__.py @@ -1,5 +1,6 @@ import logging import sys +from typing import Any from .message import MessageBFResponse, MessageQuery @@ -24,7 +25,7 @@ class DeviceAttributes(StrEnum): class MideaBFDevice(MideaDevice): - _status = { + _status: dict[int, str] = { 0x01: "PowerSave", 0x02: "Standby", 0x03: "Working", @@ -45,7 +46,7 @@ def __init__( model: str, subtype: int, customize: str, - ): + ) -> None: super().__init__( name=name, device_id=device_id, @@ -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 = MessageBFResponse(msg) _LOGGER.debug(f"[{self.device_id}] Received: {message}") new_status = {} @@ -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 diff --git a/midealocal/devices/bf/message.py b/midealocal/devices/bf/message.py index 73e80d53..75b11220 100644 --- a/midealocal/devices/bf/message.py +++ b/midealocal/devices/bf/message.py @@ -2,7 +2,9 @@ class MessageBFBase(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=0xBF, protocol_version=protocol_version, @@ -11,12 +13,12 @@ def __init__(self, protocol_version, message_type, body_type): ) @property - def _body(self): + def _body(self) -> bytearray: raise NotImplementedError class MessageQuery(MessageBFBase): - def __init__(self, protocol_version): + def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, @@ -24,12 +26,12 @@ def __init__(self, protocol_version): ) @property - def _body(self): + def _body(self) -> bytearray: return bytearray([]) class MessageSet(MessageBFBase): - def __init__(self, protocol_version): + def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, @@ -39,7 +41,7 @@ def __init__(self, protocol_version): self.child_lock = None @property - def _body(self): + def _body(self) -> bytearray: power = 0xFF if self.power is None else 0x11 if self.power else 0x01 child_lock = ( 0xFF if self.child_lock is None else 0x01 if self.child_lock else 0x00 @@ -48,7 +50,7 @@ def _body(self): class MessageBFBody(MessageBody): - def __init__(self, body): + def __init__(self, body: bytearray) -> None: super().__init__(body) self.status = body[31] self.time_remaining = ( @@ -68,8 +70,8 @@ def __init__(self, body): class MessageBFResponse(MessageResponse): - def __init__(self, message): - super().__init__(message) + def __init__(self, message: bytes) -> None: + super().__init__(bytearray(message)) if ( self.message_type in [MessageType.set, MessageType.notify1, MessageType.query]