Skip to content

Commit

Permalink
fix(a1): attribute with wrong default (#55)
Browse files Browse the repository at this point in the history
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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
  • Loading branch information
rokam and chemelli74 authored Jun 4, 2024
1 parent 739b1bc commit 7e66870
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MessageApplianceResponse,
MessageQueryAppliance,
MessageQuestCustom,
MessageRequest,
MessageType,
)
from .packet_builder import PacketBuilder
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions midealocal/devices/a1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import sys

from .message import MessageA1Response, MessageQuery, MessageSet

if sys.version_info < (3, 12):
from ...backports.enum import StrEnum
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions midealocal/devices/a1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7e66870

Please sign in to comment.