Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup and complete body and subbody types lists #325

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions midealocal/devices/a1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from midealocal.const import DeviceType, ProtocolVersion
from midealocal.crc8 import calculate
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize message A1 base."""
super().__init__(
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X41,
body_type=ListTypes.X41,
)

@property
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.B1,
body_type=ListTypes.B1,
)

@property
Expand All @@ -125,7 +125,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.set,
body_type=BodyType.X48,
body_type=ListTypes.X48,
)
self.power = False
self.prompt_tone = False
Expand Down Expand Up @@ -190,7 +190,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.set,
body_type=BodyType.B0,
body_type=ListTypes.B0,
)
self.light: bool | None = None

Expand Down Expand Up @@ -253,10 +253,12 @@ def __init__(self, message: bytearray) -> None:
MessageType.set,
MessageType.notify1,
]:
if self.body_type in [BodyType.B0, BodyType.B1, BodyType.B5]:
if self.body_type in [ListTypes.B0, ListTypes.B1, ListTypes.B5]:
self.set_body(A1NewProtocolMessageBody(super().body, self.body_type))
else:
self.set_body(A1GeneralMessageBody(super().body))
elif self.message_type == MessageType.notify2 and self.body_type == BodyType.A0:
elif (
self.message_type == MessageType.notify2 and self.body_type == ListTypes.A0
):
self.set_body(A1GeneralMessageBody(super().body))
self.set_attr()
45 changes: 23 additions & 22 deletions midealocal/devices/ac/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from midealocal.const import MAX_BYTE_VALUE, DeviceType
from midealocal.crc8 import calculate
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
MessageType,
NewProtocolMessageBody,
SubBodyType,
)

BB_AC_MODES = [0, 3, 1, 2, 4, 5]
Expand Down Expand Up @@ -108,7 +107,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize AC message base."""
super().__init__(
Expand Down Expand Up @@ -142,7 +141,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X41,
body_type=ListTypes.X41,
)

@property
Expand Down Expand Up @@ -184,7 +183,7 @@ def __init__(
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.B5,
body_type=ListTypes.B5,
)
self._additional_capabilities = additional_capabilities

Expand All @@ -203,7 +202,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X41,
body_type=ListTypes.X41,
)

@property
Expand All @@ -226,7 +225,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X41,
body_type=ListTypes.X41,
)
self.prompt_tone = False

Expand Down Expand Up @@ -266,7 +265,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.B1,
body_type=ListTypes.B1,
)

@property
Expand Down Expand Up @@ -299,7 +298,7 @@ def __init__(
super().__init__(
protocol_version=protocol_version,
message_type=message_type,
body_type=BodyType.AA,
body_type=ListTypes.AA,
)
self._subprotocol_query_type = subprotocol_query_type

Expand Down Expand Up @@ -442,7 +441,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.set,
body_type=BodyType.X40,
body_type=ListTypes.X40,
)
self.power = False
self.prompt_tone = True
Expand Down Expand Up @@ -534,7 +533,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.set,
body_type=BodyType.B0,
body_type=ListTypes.B0,
)
self.indirect_wind: bytes | None = None
self.prompt_tone: bytes | None = None
Expand Down Expand Up @@ -852,7 +851,7 @@ def __init__(self, body: bytearray) -> None:
subprotocol_body = body[6:]
data_type = subprotocol_head[-1]
subprotocol_body_len = len(subprotocol_body)
if data_type in (SubBodyType.X11, SubBodyType.X20):
if data_type in (ListTypes.X11, ListTypes.X20):
self.power = (subprotocol_body[0] & 0x1) > 0
self.dry = (subprotocol_body[0] & 0x10) > 0
self.boost_mode = (subprotocol_body[0] & 0x20) > 0
Expand All @@ -874,7 +873,7 @@ def __init__(self, body: bytearray) -> None:
if subprotocol_body_len > ECO_MODE_MIN_SUBPROTOCOL_LENGTH
else False
)
elif data_type == SubBodyType.X10:
elif data_type == ListTypes.X10:
if subprotocol_body[8] & 0x80 == SUB_PROTOCOL_BODY_TEMP_CHECK:
self.indoor_temperature = (
0 - (~(subprotocol_body[7] + subprotocol_body[8] * 256) + 1)
Expand All @@ -886,9 +885,9 @@ def __init__(self, body: bytearray) -> None:
) / 100
self.indoor_humidity = subprotocol_body[30]
self.sn8_flag = subprotocol_body[80] == XBB_SN8_BYTE_FLAG
elif data_type == SubBodyType.X12:
elif data_type == ListTypes.X12:
pass
elif data_type == SubBodyType.X30:
elif data_type == ListTypes.X30:
if subprotocol_body[6] & 0x80 == SUB_PROTOCOL_BODY_TEMP_CHECK:
self.outdoor_temperature = (
0 - (~(subprotocol_body[5] + subprotocol_body[6] * 256) + 1)
Expand All @@ -898,7 +897,7 @@ def __init__(self, body: bytearray) -> None:
self.outdoor_temperature = (
subprotocol_body[5] + subprotocol_body[6] * 256
) / 100
elif data_type in (SubBodyType.X13, SubBodyType.X21):
elif data_type in (ListTypes.X13, ListTypes.X21):
pass


Expand All @@ -908,27 +907,29 @@ class MessageACResponse(MessageResponse):
def __init__(self, message: bytearray, power_analysis_method: int = 3) -> None:
"""Initialize AC message response."""
super().__init__(message)
if self.message_type == MessageType.notify2 and self.body_type == BodyType.A0:
if self.message_type == MessageType.notify2 and self.body_type == ListTypes.A0:
self.set_body(XA0MessageBody(super().body))
elif self.message_type == MessageType.notify1 and self.body_type == BodyType.A1:
elif (
self.message_type == MessageType.notify1 and self.body_type == ListTypes.A1
):
self.set_body(XA1MessageBody(super().body))
elif self.message_type in [
MessageType.query,
MessageType.set,
MessageType.notify2,
] and self.body_type in [BodyType.B0, BodyType.B1, BodyType.B5]:
] and self.body_type in [ListTypes.B0, ListTypes.B1, ListTypes.B5]:
self.set_body(XBXMessageBody(super().body, self.body_type))
elif (
self.message_type in [MessageType.query, MessageType.set]
and self.body_type == BodyType.C0
and self.body_type == ListTypes.C0
):
self.set_body(XC0MessageBody(super().body))
elif self.message_type == MessageType.query and self.body_type == BodyType.C1:
elif self.message_type == MessageType.query and self.body_type == ListTypes.C1:
self.set_body(XC1MessageBody(super().body, power_analysis_method))
elif (
self.message_type
in [MessageType.set, MessageType.query, MessageType.notify2]
and self.body_type == BodyType.BB
and self.body_type == ListTypes.BB
and len(super().body) >= BB_MIN_BODY_LENGTH
):
self.used_subprotocol = True
Expand Down
12 changes: 6 additions & 6 deletions midealocal/devices/b0/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from midealocal.const import MAX_BYTE_VALUE, DeviceType, ProtocolVersion
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
Expand All @@ -19,7 +19,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize B0 message base."""
super().__init__(
Expand All @@ -42,7 +42,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X00,
body_type=ListTypes.X00,
)

@property
Expand All @@ -58,7 +58,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X01,
body_type=ListTypes.X01,
)

@property
Expand Down Expand Up @@ -108,9 +108,9 @@ def __init__(self, message: bytearray) -> None:
"""Initialize B0 message response."""
super().__init__(message)
if self.message_type in [MessageType.notify1, MessageType.query]:
if self.body_type == BodyType.X01:
if self.body_type == ListTypes.X01:
self.set_body(B0Message01Body(super().body))
elif self.body_type == BodyType.X04:
elif self.body_type == ListTypes.X04:
pass
else:
self.set_body(B0MessageBody(super().body))
Expand Down
6 changes: 3 additions & 3 deletions midealocal/devices/b1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from midealocal.const import MAX_BYTE_VALUE, DeviceType
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
Expand All @@ -17,7 +17,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize B1 message base."""
super().__init__(
Expand All @@ -40,7 +40,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X00,
body_type=ListTypes.X00,
)

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

from midealocal.const import MAX_BYTE_VALUE, DeviceType
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
Expand All @@ -24,7 +24,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize B3 message base."""
super().__init__(
Expand All @@ -47,7 +47,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X31,
body_type=ListTypes.X31,
)

@property
Expand Down Expand Up @@ -218,16 +218,16 @@ def __init__(self, message: bytes) -> None:
super().__init__(bytearray(message))
if (
self.message_type == MessageType.query
and self.body_type == BodyType.X31
and self.body_type == ListTypes.X31
or self.message_type == MessageType.notify1
and self.body_type == BodyType.X41
and self.body_type == ListTypes.X41
):
self.set_body(B3MessageBody31(super().body))
elif (
self.message_type == MessageType.set
and self.body_type == BodyType.X21
and self.body_type == ListTypes.X21
or self.message_type == MessageType.set
and self.body_type == BodyType.X24
and self.body_type == ListTypes.X24
):
self.set_body(B3MessageBody21(super().body))
self.set_attr()
8 changes: 4 additions & 4 deletions midealocal/devices/b4/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from midealocal.const import MAX_BYTE_VALUE, DeviceType
from midealocal.message import (
BodyType,
ListTypes,
MessageBody,
MessageRequest,
MessageResponse,
Expand All @@ -17,7 +17,7 @@ def __init__(
self,
protocol_version: int,
message_type: MessageType,
body_type: BodyType,
body_type: ListTypes,
) -> None:
"""Initialize B4 message base."""
super().__init__(
Expand All @@ -40,7 +40,7 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=BodyType.X01,
body_type=ListTypes.X01,
)

@property
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, message: bytes) -> None:
MessageType.query,
MessageType.set,
]
and self.body_type == BodyType.X01
and self.body_type == ListTypes.X01
):
self.set_body(B4MessageBody(super().body))
self.set_attr()
Loading
Loading