Skip to content

Commit

Permalink
feat(c3): add eco/install/hmipara query
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed Dec 19, 2024
1 parent 6016aaa commit a2255a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
6 changes: 6 additions & 0 deletions midealocal/devices/c3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
MessageQuery,
MessageQueryBasic,
MessageQueryDisinfect,
MessageQueryECO,
MessageQueryHMIPara,
MessageQueryInstall,
MessageQuerySilence,
MessageQueryUnitPara,
MessageSet,
Expand Down Expand Up @@ -122,7 +125,10 @@ def build_query(self) -> list[MessageQuery]:
MessageQueryBasic(self._message_protocol_version),
MessageQueryDisinfect(self._message_protocol_version),
MessageQuerySilence(self._message_protocol_version),
MessageQueryECO(self._message_protocol_version),
MessageQueryUnitPara(self._message_protocol_version),
MessageQueryHMIPara(self._message_protocol_version),
MessageQueryInstall(self._message_protocol_version),
]

def process_message(self, msg: bytes) -> dict[str, Any]:
Expand Down
50 changes: 37 additions & 13 deletions midealocal/devices/c3/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(protocol_version, ListTypes.X05)


class MessageQueryECO(MessageQuery):
"""C3 Message query ECO."""

def __init__(self, protocol_version: int) -> None:
"""Initialize C3 message query silence."""
super().__init__(protocol_version, ListTypes.X07)


class MessageQueryInstall(MessageQuery):
"""C3 Message query INSTALL."""

def __init__(self, protocol_version: int) -> None:
"""Initialize C3 message query silence."""
super().__init__(protocol_version, ListTypes.X08)


class MessageQueryDisinfect(MessageQuery):
"""C3 Message query Disinfect."""

Expand All @@ -84,6 +100,14 @@ def __init__(self, protocol_version: int) -> None:
super().__init__(protocol_version, ListTypes.X10)


class MessageQueryHMIPara(MessageQuery):
"""C3 Message query HMIPARA."""

def __init__(self, protocol_version: int) -> None:
"""Initialize C3 message query silence."""
super().__init__(protocol_version, ListTypes.X0A)


class MessageSet(MessageC3Base):
"""C3 message set."""

Expand Down Expand Up @@ -202,8 +226,8 @@ def _body(self) -> bytearray:
return bytearray([disinfect, 0x00, 0x00, 0x00])


class C3MessageBody(MessageBody):
"""C3 message body."""
class C3BasicBody(MessageBody):
"""C3 Basic message body."""

def __init__(self, body: bytearray, data_offset: int = 0) -> None:
"""Initialize C3 message body."""
Expand Down Expand Up @@ -255,7 +279,7 @@ def __init__(self, body: bytearray, data_offset: int = 0) -> None:
self.tbh_control = body[data_offset + 23] & 0x80 > 0


class C3EnergyMessageBody(MessageBody):
class C3EnergyBody(MessageBody):
"""C3 Energy MSG_TYPE_UP_POWER4 message body."""

def __init__(self, body: bytearray, data_offset: int = 0) -> None:
Expand Down Expand Up @@ -297,7 +321,7 @@ def __init__(self, body: bytearray, data_offset: int = 0) -> None:
self.tas = body[data_offset + 13]


class C3SilenceMessageBody(MessageBody):
class C3SilenceBody(MessageBody):
"""C3 Silence message body."""

def __init__(self, body: bytearray, data_offset: int = 0) -> None:
Expand All @@ -324,7 +348,7 @@ def __init__(self, body: bytearray, data_offset: int = 0) -> None:
# silence_timer2_endmin: Byte 9


class C3DisinfectMessageBody(MessageBody):
class C3DisinfectBody(MessageBody):
"""C3 Disinfect message body."""

def __init__(self, body: bytearray, data_offset: int = 0) -> None:
Expand All @@ -337,7 +361,7 @@ def __init__(self, body: bytearray, data_offset: int = 0) -> None:
self.disinfect_start_minutes = body[data_offset + 3]


class C3UnitParaMessageBody(MessageBody):
class C3UnitParaBody(MessageBody):
"""C3 UnitPara message body."""

def __init__(self, body: bytearray, data_offset: int = 0) -> None:
Expand Down Expand Up @@ -432,15 +456,15 @@ def __init__(self, message: bytes) -> None:
in [MessageType.set, MessageType.notify1, MessageType.query]
and self.body_type == ListTypes.X01
) or self.message_type == MessageType.notify2:
self.set_body(C3MessageBody(super().body, data_offset=1))
self.set_body(C3BasicBody(super().body, data_offset=1))
elif (
self.message_type == MessageType.notify1 and self.body_type == ListTypes.X04
):
self.set_body(C3EnergyMessageBody(super().body, data_offset=1))
self.set_body(C3EnergyBody(super().body, data_offset=1))
elif self.message_type == MessageType.query and self.body_type == ListTypes.X05:
self.set_body(C3SilenceMessageBody(super().body, data_offset=1))
elif self.message_type == MessageType.query and self.body_type == ListTypes.X09:
self.set_body(C3DisinfectMessageBody(super().body, data_offset=1))
elif self.message_type == MessageType.query and self.body_type == ListTypes.X10:
self.set_body(C3UnitParaMessageBody(super().body, data_offset=1))
self.set_body(C3SilenceBody(super().body, data_offset=1))
elif self.body_type == ListTypes.X09:
self.set_body(C3DisinfectBody(super().body, data_offset=1))
elif self.body_type == ListTypes.X10:
self.set_body(C3UnitParaBody(super().body, data_offset=1))
self.set_attr()

0 comments on commit a2255a3

Please sign in to comment.