From 7e66870df5b0003a55b26932bdb343db58395931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Mind=C3=AAllo=20de=20Andrade?= Date: Tue, 4 Jun 2024 05:03:54 -0300 Subject: [PATCH] fix(a1): attribute with wrong default (#55) Here it saves the string value instead of the index. The index is used only inside the message: ``` elif status == DeviceAttributes.fan_speed: if value in MideaA1Device._speeds.keys(): self._attributes[status] = MideaA1Device._speeds.get(value) else: self._attributes[status] = None ``` That's why fan_speed should be a string ## Summary by CodeRabbit - **Bug Fixes** - Corrected the `fan_speed` attribute to display string values instead of integers. - **New Features** - Enhanced type safety with added type annotations in various methods and attributes. --------- Co-authored-by: Simone Chemelli --- midealocal/device.py | 3 ++- midealocal/devices/a1/__init__.py | 3 +-- midealocal/devices/a1/message.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/midealocal/device.py b/midealocal/device.py index 7e6741ba..1bc2a564 100644 --- a/midealocal/device.py +++ b/midealocal/device.py @@ -10,6 +10,7 @@ MessageApplianceResponse, MessageQueryAppliance, MessageQuestCustom, + MessageRequest, MessageType, ) from .packet_builder import PacketBuilder @@ -196,7 +197,7 @@ def send_message_v3( data = self._security.encode_8370(data, msg_type) self.send_message_v2(data) - def build_send(self, cmd: MessageQuestCustom) -> None: + def build_send(self, cmd: MessageRequest) -> None: data = cmd.serialize() _LOGGER.debug("[%s] Sending: %s", self._device_id, cmd) msg = PacketBuilder(self._device_id, data).finalize() diff --git a/midealocal/devices/a1/__init__.py b/midealocal/devices/a1/__init__.py index daa542b0..966a7e1c 100644 --- a/midealocal/devices/a1/__init__.py +++ b/midealocal/devices/a1/__init__.py @@ -4,7 +4,6 @@ import sys -from .message import MessageA1Response, MessageQuery, MessageSet if sys.version_info < (3, 12): from ...backports.enum import StrEnum @@ -73,7 +72,7 @@ def __init__( DeviceAttributes.prompt_tone: True, DeviceAttributes.child_lock: False, DeviceAttributes.mode: None, - DeviceAttributes.fan_speed: 60, + DeviceAttributes.fan_speed: "Medium", DeviceAttributes.swing: False, DeviceAttributes.target_humidity: 35, DeviceAttributes.anion: False, diff --git a/midealocal/devices/a1/message.py b/midealocal/devices/a1/message.py index a5139dba..4a2548e1 100644 --- a/midealocal/devices/a1/message.py +++ b/midealocal/devices/a1/message.py @@ -32,11 +32,11 @@ def __init__( self._message_id = MessageA1Base._message_serial @property - def _body(self): + def _body(self) -> bytearray: raise NotImplementedError @property - def body(self): + def body(self) -> bytearray: body = bytearray([self.body_type]) + self._body + bytearray([self._message_id]) body.append(calculate(body)) return body @@ -163,7 +163,7 @@ def __init__(self, protocol_version: int) -> None: message_type=MessageType.set, body_type=0xB0, ) - self.light = None + self.light: bool | None = None @property def _body(self) -> bytearray: @@ -200,7 +200,7 @@ def __init__(self, body: bytearray) -> None: class A1NewProtocolMessageBody(NewProtocolMessageBody): - def __init__(self, body: bytearray, bt) -> None: + def __init__(self, body: bytearray, bt: int) -> None: super().__init__(body, bt) params = self.parse() if NewProtocolTags.light in params: