diff --git a/midealocal/devices/cf/__init__.py b/midealocal/devices/cf/__init__.py index 3715701e..739c6140 100644 --- a/midealocal/devices/cf/__init__.py +++ b/midealocal/devices/cf/__init__.py @@ -1,5 +1,6 @@ import logging import sys +from typing import Any from .message import MessageCFResponse, MessageQuery, MessageSet @@ -36,7 +37,7 @@ def __init__( model: str, subtype: int, customize: str, - ): + ) -> None: super().__init__( name=name, device_id=device_id, @@ -59,10 +60,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 = MessageCFResponse(msg) _LOGGER.debug(f"[{self.device_id}] Received: {message}") new_status = {} @@ -72,7 +73,7 @@ def process_message(self, msg): new_status[str(status)] = getattr(message, str(status)) return new_status - def set_target_temperature(self, target_temperature, mode): + def set_target_temperature(self, target_temperature: int, mode: int) -> None: message = MessageSet(self._protocol_version) message.power = True message.mode = self._attributes[DeviceAttributes.mode] @@ -81,7 +82,7 @@ def set_target_temperature(self, target_temperature, mode): message.mode = mode self.build_send(message) - def set_attribute(self, attr, value): + def set_attribute(self, attr: str, value: Any) -> None: message = MessageSet(self._protocol_version) message.power = True message.mode = self._attributes[DeviceAttributes.mode] diff --git a/midealocal/devices/cf/message.py b/midealocal/devices/cf/message.py index 7c3ade08..fd8f61d8 100644 --- a/midealocal/devices/cf/message.py +++ b/midealocal/devices/cf/message.py @@ -7,7 +7,9 @@ class MessageCFBase(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=0xCF, protocol_version=protocol_version, @@ -16,12 +18,12 @@ def __init__(self, protocol_version, message_type, body_type): ) @property - def _body(self): + def _body(self) -> bytearray: raise NotImplementedError class MessageQuery(MessageCFBase): - def __init__(self, protocol_version): + def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, @@ -29,12 +31,12 @@ def __init__(self, protocol_version): ) @property - def _body(self): + def _body(self) -> bytearray: return bytearray([]) class MessageSet(MessageCFBase): - def __init__(self, protocol_version): + def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, @@ -42,11 +44,11 @@ def __init__(self, protocol_version): ) self.power = False self.mode = 0 # 1 自动 2 制冷 3 制热 - self.target_temperature = None - self.aux_heating = None + self.target_temperature: int | None = None + self.aux_heating: bool | None = None @property - def _body(self): + def _body(self) -> bytearray: power = 0x01 if self.power else 0x00 mode = self.mode target_temperature = ( @@ -61,7 +63,7 @@ def _body(self): class CFMessageBody(MessageBody): - def __init__(self, body, data_offset=0): + def __init__(self, body: bytearray, data_offset: int = 0) -> None: super().__init__(body) self.power = (body[data_offset + 0] & 0x01) > 0 self.aux_heating = (body[data_offset + 0] & 0x02) > 0 @@ -81,8 +83,8 @@ def __init__(self, body, data_offset=0): class MessageCFResponse(MessageResponse): - def __init__(self, message): - super().__init__(message) + def __init__(self, message: bytes) -> None: + super().__init__(bytearray(message)) if ( self.message_type in [MessageType.query, MessageType.set] and self.body_type == 0x01