From a2255a3248978f402eac1461cc6b75d148dbfac3 Mon Sep 17 00:00:00 2001 From: Wentao Wu Date: Thu, 19 Dec 2024 06:37:07 +0000 Subject: [PATCH] feat(c3): add eco/install/hmipara query --- midealocal/devices/c3/__init__.py | 6 ++++ midealocal/devices/c3/message.py | 50 +++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/midealocal/devices/c3/__init__.py b/midealocal/devices/c3/__init__.py index dacf3d77..9c91eb80 100644 --- a/midealocal/devices/c3/__init__.py +++ b/midealocal/devices/c3/__init__.py @@ -13,6 +13,9 @@ MessageQuery, MessageQueryBasic, MessageQueryDisinfect, + MessageQueryECO, + MessageQueryHMIPara, + MessageQueryInstall, MessageQuerySilence, MessageQueryUnitPara, MessageSet, @@ -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]: diff --git a/midealocal/devices/c3/message.py b/midealocal/devices/c3/message.py index 294151af..ee6c2ce8 100644 --- a/midealocal/devices/c3/message.py +++ b/midealocal/devices/c3/message.py @@ -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.""" @@ -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.""" @@ -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.""" @@ -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: @@ -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: @@ -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: @@ -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: @@ -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()