Skip to content

Commit

Permalink
feat(ed): add all query msg for 0xED device (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao authored Dec 24, 2024
1 parent 2ab6b67 commit 30ba082
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 8 deletions.
38 changes: 35 additions & 3 deletions midealocal/devices/ed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
from midealocal.device import MideaDevice
from midealocal.message import ListTypes

from .message import MessageEDResponse, MessageNewSet, MessageOldSet, MessageQuery
from .message import (
MessageEDResponse,
MessageNewSet,
MessageOldSet,
MessageQuery,
MessageQuery01,
MessageQuery03,
MessageQuery04,
MessageQuery05,
MessageQuery06,
MessageQuery07,
MessageQueryFF,
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,9 +89,29 @@ def _use_new_set(self) -> bool:
# if (self.sub_type > 342 or self.sub_type == 340) else False
return True

def build_query(self) -> list[MessageQuery]:
def build_query(
self,
) -> list[
MessageQuery
| MessageQuery01
| MessageQuery03
| MessageQuery04
| MessageQuery05
| MessageQuery06
| MessageQuery07
| MessageQueryFF
]:
"""Midea ED device build query."""
return [MessageQuery(self._message_protocol_version, self._device_class)]
return [
MessageQuery(self._message_protocol_version),
MessageQuery01(self._message_protocol_version),
MessageQuery03(self._message_protocol_version),
MessageQuery04(self._message_protocol_version),
MessageQuery05(self._message_protocol_version),
MessageQuery06(self._message_protocol_version),
MessageQuery07(self._message_protocol_version),
MessageQueryFF(self._message_protocol_version),
]

def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea ED device process message."""
Expand Down
146 changes: 145 additions & 1 deletion midealocal/devices/ed/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def _body(self) -> bytearray:
class MessageQuery(MessageEDBase):
"""ED message query."""

def __init__(self, protocol_version: int, body_type: ListTypes) -> None:
def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X00,
) -> None:
"""Initialize ED message query."""
super().__init__(
protocol_version=protocol_version,
Expand All @@ -77,6 +81,146 @@ def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery01(MessageEDBase):
"""ED message query01."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X01,
) -> None:
"""Initialize ED message query01."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery03(MessageEDBase):
"""ED message query03."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X03,
) -> None:
"""Initialize ED message query03."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery04(MessageEDBase):
"""ED message query04."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X04,
) -> None:
"""Initialize ED message query04."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery05(MessageEDBase):
"""ED message query05."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X05,
) -> None:
"""Initialize ED message query05."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery06(MessageEDBase):
"""ED message query06."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X06,
) -> None:
"""Initialize ED message query06."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQuery07(MessageEDBase):
"""ED message query07."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.X07,
) -> None:
"""Initialize ED message query07."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageQueryFF(MessageEDBase):
"""ED message queryFF."""

def __init__(
self,
protocol_version: int,
body_type: ListTypes = ListTypes.FF,
) -> None:
"""Initialize ED message queryFF."""
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
body_type=body_type,
)

@property
def _body(self) -> bytearray:
return bytearray([0x01])


class MessageNewSet(MessageEDBase):
"""ED message new set."""

Expand Down
20 changes: 18 additions & 2 deletions tests/devices/ed/device_ed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@

from midealocal.const import ProtocolVersion
from midealocal.devices.ed import DeviceAttributes, MideaEDDevice
from midealocal.devices.ed.message import MessageQuery
from midealocal.devices.ed.message import (
MessageQuery,
MessageQuery01,
MessageQuery03,
MessageQuery04,
MessageQuery05,
MessageQuery06,
MessageQuery07,
MessageQueryFF,
)


class TestMideaEDDevice:
Expand Down Expand Up @@ -89,8 +98,15 @@ def test_process_message(self) -> None:
def test_build_query(self) -> None:
"""Test build query."""
queries = self.device.build_query()
assert len(queries) == 1
assert len(queries) == 8
assert isinstance(queries[0], MessageQuery)
assert isinstance(queries[1], MessageQuery01)
assert isinstance(queries[2], MessageQuery03)
assert isinstance(queries[3], MessageQuery04)
assert isinstance(queries[4], MessageQuery05)
assert isinstance(queries[5], MessageQuery06)
assert isinstance(queries[6], MessageQuery07)
assert isinstance(queries[7], MessageQueryFF)

def test_set_attribute(self) -> None:
"""Test set attribute."""
Expand Down
94 changes: 92 additions & 2 deletions tests/devices/ed/message_ed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
MessageEDResponse,
MessageNewSet,
MessageQuery,
MessageQuery01,
MessageQuery03,
MessageQuery04,
MessageQuery05,
MessageQuery06,
MessageQuery07,
MessageQueryFF,
)
from midealocal.message import ListTypes, MessageType

Expand All @@ -39,9 +46,92 @@ def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery(
protocol_version=ProtocolVersion.V1,
body_type=ListTypes.X02,
)
expected_body = bytearray([0x02, 0x01])
expected_body = bytearray([0x00, 0x01])
assert query.body == expected_body


class TestMessageQuery01:
"""Test Message Query01."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery01(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x01, 0x01])
assert query.body == expected_body


class TestMessageQuery03:
"""Test Message Query03."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery03(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x03, 0x01])
assert query.body == expected_body


class TestMessageQuery04:
"""Test Message Query04."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery04(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x04, 0x01])
assert query.body == expected_body


class TestMessageQuery05:
"""Test Message Query05."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery05(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x05, 0x01])
assert query.body == expected_body


class TestMessageQuery06:
"""Test Message Query06."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery06(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x06, 0x01])
assert query.body == expected_body


class TestMessageQuery07:
"""Test Message Query07."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQuery07(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0x07, 0x01])
assert query.body == expected_body


class TestMessageQueryFF:
"""Test Message QueryFF."""

def test_query_body(self) -> None:
"""Test query body."""
query = MessageQueryFF(
protocol_version=ProtocolVersion.V1,
)
expected_body = bytearray([0xFF, 0x01])
assert query.body == expected_body


Expand Down

0 comments on commit 30ba082

Please sign in to comment.