diff --git a/.commitlint.config.mjs b/.commitlint.config.mjs deleted file mode 100644 index f2606949..00000000 --- a/.commitlint.config.mjs +++ /dev/null @@ -1,17 +0,0 @@ -import { RuleConfigSeverity } from "@commitlint/types"; - -const Configuration = { - /* - * Resolve and load @commitlint/config-conventional from node_modules. - * Referenced packages must be installed - */ - extends: ["@commitlint/config-conventional"], - /* - * Any rules defined here will override rules from @commitlint/config-conventional - */ - rules: { - "body-max-line-length": [RuleConfigSeverity.Error, "always", 300], - }, -}; - -export default Configuration; diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 720431a5..e714dec3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,9 @@ FROM mcr.microsoft.com/devcontainers/python:1-3.11 +# [Option] Install Node.js +ARG INSTALL_NODE="true" +ARG NODE_VERSION="lts/*" +RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi # Install Python dependencies from requirements COPY requirements*.txt /tmp/pip-tmp/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 640e8d69..4f5b9168 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks exclude: "CHANGELOG.md|.copier-answers.yml" -default_stages: [commit] +default_stages: [pre-commit] ci: autofix_commit_msg: "chore(pre-commit.ci): auto fixes" @@ -11,12 +11,17 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: no-commit-to-branch args: ["--branch", "main"] + - id: check-json + - id: check-toml + - id: check-xml + - id: check-yaml + - id: detect-private-key - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.8 + rev: v0.6.9 hooks: - id: ruff args: @@ -27,21 +32,18 @@ repos: hooks: - id: commitizen stages: [commit-msg] - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v9.18.0 hooks: - - id: check-json - - id: check-toml - - id: check-xml - - id: check-yaml - - id: detect-private-key + - id: commitlint + stages: [commit-msg] - repo: https://github.com/pre-commit/mirrors-prettier rev: v4.0.0-alpha.8 hooks: - id: prettier args: ["--tab-width", "2"] - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.18.0 hooks: - id: pyupgrade args: [--py37-plus] diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c5ff5cb..c0877cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [6.0.3](https://github.com/rokam/midea-local/compare/v6.0.2...v6.0.3) (2024-10-15) + + +### Bug Fixes + +* cleanup and complete body and subbody types lists ([#325](https://github.com/rokam/midea-local/issues/325)) ([914dcb8](https://github.com/rokam/midea-local/commit/914dcb8098efe50cc1583ad81fd22b49e9e2536b)) + +## [6.0.2](https://github.com/rokam/midea-local/compare/v6.0.1...v6.0.2) (2024-10-08) + + +### Bug Fixes + +* add more BodyType ([#321](https://github.com/rokam/midea-local/issues/321)) ([a1b4ac8](https://github.com/rokam/midea-local/commit/a1b4ac807e3b475f0a32f44c0f1d7af980d7a486)) + ## [6.0.1](https://github.com/rokam/midea-local/compare/v6.0.0...v6.0.1) (2024-10-06) diff --git a/commitlint.config.mjs b/commitlint.config.mjs new file mode 100644 index 00000000..be77cf6e --- /dev/null +++ b/commitlint.config.mjs @@ -0,0 +1,6 @@ +export default { + extends: ["@commitlint/config-conventional"], + rules: { + "body-max-line-length": [2, "always", 300], + }, +}; diff --git a/midealocal/devices/a1/message.py b/midealocal/devices/a1/message.py index 4d31f89d..dd0722a2 100644 --- a/midealocal/devices/a1/message.py +++ b/midealocal/devices/a1/message.py @@ -5,7 +5,7 @@ from midealocal.const import DeviceType, ProtocolVersion from midealocal.crc8 import calculate from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -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__( @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/midealocal/devices/ac/message.py b/midealocal/devices/ac/message.py index 1086fcb0..347efe21 100644 --- a/midealocal/devices/ac/message.py +++ b/midealocal/devices/ac/message.py @@ -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] @@ -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__( @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/midealocal/devices/b0/message.py b/midealocal/devices/b0/message.py index ab024f9b..a1f42465 100644 --- a/midealocal/devices/b0/message.py +++ b/midealocal/devices/b0/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType, ProtocolVersion from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -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__( @@ -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 @@ -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 @@ -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)) diff --git a/midealocal/devices/b1/message.py b/midealocal/devices/b1/message.py index eec137d5..5b18d98a 100644 --- a/midealocal/devices/b1/message.py +++ b/midealocal/devices/b1/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -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__( @@ -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 diff --git a/midealocal/devices/b3/message.py b/midealocal/devices/b3/message.py index ac1d4d40..a302b9c1 100644 --- a/midealocal/devices/b3/message.py +++ b/midealocal/devices/b3/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -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__( @@ -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 @@ -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() diff --git a/midealocal/devices/b4/message.py b/midealocal/devices/b4/message.py index 507928c3..0cb3bf3e 100644 --- a/midealocal/devices/b4/message.py +++ b/midealocal/devices/b4/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -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__( @@ -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 @@ -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() diff --git a/midealocal/devices/b6/message.py b/midealocal/devices/b6/message.py index 58898403..f0e25140 100644 --- a/midealocal/devices/b6/message.py +++ b/midealocal/devices/b6/message.py @@ -2,12 +2,11 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType, ProtocolVersion from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, MessageType, - SubBodyType, ) FAN_LEVEL_RANGE_1 = 130 @@ -25,7 +24,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize B6 message base.""" super().__init__( @@ -48,9 +47,9 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X11 + body_type=ListTypes.X11 if protocol_version == MESSAGE_PROTOCOL_VERSION - else BodyType.X31, + else ListTypes.X31, ) @property @@ -66,7 +65,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) @property @@ -82,9 +81,9 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X22 + body_type=ListTypes.X22 if protocol_version in [0x00, 0x01] - else BodyType.X11, + else ListTypes.X11, ) self.light: int | None = None self.power: bool | None = None @@ -222,40 +221,40 @@ def __init__(self, message: bytes) -> None: super().__init__(bytearray(message)) if ( self.message_type == MessageType.set - and self.body_type == BodyType.X22 - and super().body[1] == SubBodyType.X01 + and self.body_type == ListTypes.X22 + and super().body[1] == ListTypes.X01 ): self.set_body(B6SpecialBody(super().body)) elif ( self.message_type == MessageType.set - and self.body_type == BodyType.X11 - and super().body[1] == SubBodyType.X01 + and self.body_type == ListTypes.X11 + and super().body[1] == ListTypes.X01 ): ############################# pass elif self.message_type == MessageType.query: - if self.body_type in [BodyType.X11, BodyType.X31]: + if self.body_type in [ListTypes.X11, ListTypes.X31]: if self.protocol_version in [0, 1]: self.set_body(B6GeneralBody(super().body)) else: self.set_body(B6NewProtocolBody(super().body)) - elif self.body_type == BodyType.X32 and super().body[1] == 0x01: + elif self.body_type == ListTypes.X32 and super().body[1] == 0x01: self.set_body(B6ExceptionBody(super().body)) elif self.message_type == MessageType.notify1: - if self.body_type in [BodyType.X11, BodyType.X41]: + if self.body_type in [ListTypes.X11, ListTypes.X41]: if self.protocol_version in [0, 1]: self.set_body(B6GeneralBody(super().body)) else: self.set_body(B6NewProtocolBody(super().body)) - elif self.body_type == BodyType.X0A: - if super().body[1] == SubBodyType.A1: + elif self.body_type == ListTypes.X0A: + if super().body[1] == ListTypes.A1: self.set_body(B6ExceptionBody(super().body)) - elif super().body[1] == SubBodyType.A2: + elif super().body[1] == ListTypes.A2: self.oilcup_full = (super().body[2] & 0x01) > 0 self.cleaning_reminder = (super().body[2] & 0x02) > 0 elif ( self.message_type == MessageType.exception2 - and self.body_type == BodyType.A1 + and self.body_type == ListTypes.A1 ): pass diff --git a/midealocal/devices/b8/message.py b/midealocal/devices/b8/message.py index 488731cf..db5beb70 100644 --- a/midealocal/devices/b8/message.py +++ b/midealocal/devices/b8/message.py @@ -2,10 +2,10 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, BoolParser, IntEnumParser, IntParser, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -39,7 +39,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize B8 message base.""" super().__init__( @@ -62,7 +62,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X32, + body_type=ListTypes.X32, ) @property @@ -78,7 +78,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X22, + body_type=ListTypes.X22, ) self.clean_mode = B8CleanMode.AUTO self.fan_level = B8FanLevel.NORMAL @@ -114,7 +114,7 @@ def __init__( super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X22, + body_type=ListTypes.X22, ) self.work_mode = work_mode @@ -279,10 +279,10 @@ def parse_body(message_type: MessageType, body: bytearray) -> MessageBody | None status_type = body[1] if ( message_type == MessageType.query - and body_type == BodyType.X32 + and body_type == ListTypes.X32 and status_type == B8StatusType.X01 ): return MessageB8WorkStatusBody(body) - if message_type == MessageType.notify1 and body_type == BodyType.X42: + if message_type == MessageType.notify1 and body_type == ListTypes.X42: return MessageB8NotifyBody(body) return None diff --git a/midealocal/devices/bf/message.py b/midealocal/devices/bf/message.py index 2548d18f..c2b701e6 100644 --- a/midealocal/devices/bf/message.py +++ b/midealocal/devices/bf/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType, ProtocolVersion from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -17,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize BF message base.""" super().__init__( @@ -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 @@ -56,7 +56,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = None self.child_lock = None diff --git a/midealocal/devices/c2/message.py b/midealocal/devices/c2/message.py index 8376b6af..876bb722 100644 --- a/midealocal/devices/c2/message.py +++ b/midealocal/devices/c2/message.py @@ -5,7 +5,7 @@ from midealocal.const import DeviceType, ProtocolVersion from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -56,7 +56,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize C2 message base.""" super().__init__( @@ -79,7 +79,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 @@ -95,16 +95,16 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self.power = False @property def _body(self) -> bytearray: if self.power: - self.body_type = BodyType.X01 + self.body_type = ListTypes.X01 else: - self.body_type = BodyType.X02 + self.body_type = ListTypes.X02 return bytearray([0x01]) @@ -116,7 +116,7 @@ def __init__(self, protocol_version: ProtocolVersion) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) @property @@ -132,7 +132,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self.child_lock: bool | None = None @@ -144,7 +144,7 @@ def __init__(self, protocol_version: int) -> None: @property def _body(self) -> bytearray: - self.body_type = BodyType.X14 + self.body_type = ListTypes.X14 key = C2MessageEnum.none value: int | bool = 0x00 if self.child_lock is not None: diff --git a/midealocal/devices/c3/message.py b/midealocal/devices/c3/message.py index b8aa6f96..204f44d4 100644 --- a/midealocal/devices/c3/message.py +++ b/midealocal/devices/c3/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -21,7 +21,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize C3 message base.""" super().__init__( @@ -39,7 +39,7 @@ def _body(self) -> bytearray: class MessageQuery(MessageC3Base): """C3 message query.""" - def __init__(self, protocol_version: int, body_type: BodyType) -> None: + def __init__(self, protocol_version: int, body_type: ListTypes) -> None: """Initialize C3 message query.""" super().__init__( protocol_version=protocol_version, @@ -57,7 +57,7 @@ class MessageQueryBasic(MessageQuery): def __init__(self, protocol_version: int) -> None: """Initialize C3 message query basic.""" - super().__init__(protocol_version, BodyType.X01) + super().__init__(protocol_version, ListTypes.X01) class MessageQuerySilence(MessageQuery): @@ -65,7 +65,7 @@ class MessageQuerySilence(MessageQuery): def __init__(self, protocol_version: int) -> None: """Initialize C3 message query silence.""" - super().__init__(protocol_version, BodyType.X05) + super().__init__(protocol_version, ListTypes.X05) class MessageSet(MessageC3Base): @@ -76,7 +76,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.zone1_power = False self.zone2_power = False @@ -127,7 +127,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X05, + body_type=ListTypes.X05, ) self.silent_mode = False self.silent_level = C3SilentLevel.OFF @@ -157,7 +157,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X07, + body_type=ListTypes.X07, ) self.eco_mode = False @@ -272,13 +272,13 @@ def __init__(self, message: bytes) -> None: if ( self.message_type in [MessageType.set, MessageType.notify1, MessageType.query] - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ) or self.message_type == MessageType.notify2: self.set_body(C3MessageBody(super().body, data_offset=1)) elif ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X04 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X04 ): self.set_body(C3Notify1MessageBody(super().body, data_offset=1)) - elif self.message_type == MessageType.query and self.body_type == BodyType.X05: + elif self.message_type == MessageType.query and self.body_type == ListTypes.X05: self.set_body(C3QuerySilenceMessageBody(super().body, data_offset=1)) self.set_attr() diff --git a/midealocal/devices/ca/message.py b/midealocal/devices/ca/message.py index 0f4e4c8e..3af950ea 100644 --- a/midealocal/devices/ca/message.py +++ b/midealocal/devices/ca/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -23,7 +23,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize CA message base.""" super().__init__( @@ -46,7 +46,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 @@ -147,28 +147,28 @@ def __init__(self, message: bytes) -> None: if ( ( self.message_type in [MessageType.query, MessageType.set] - and self.body_type == BodyType.X00 + and self.body_type == ListTypes.X00 ) or ( self.message_type == MessageType.notify1 - and self.body_type == BodyType.X02 + and self.body_type == ListTypes.X02 ) ) and len(super().body) > MIN_CA_GENERAL_BODY_LENGTH: self.set_body(CAGeneralMessageBody(super().body)) elif ( self.message_type == MessageType.exception - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ) or ( - self.message_type == MessageType.query and self.body_type == BodyType.X02 + self.message_type == MessageType.query and self.body_type == ListTypes.X02 ): self.set_body(CAExceptionMessageBody(super().body)) elif ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X00 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X00 ): self.set_body(CANotify00MessageBody(super().body)) elif ( self.message_type in [MessageType.query, MessageType.notify1] - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ): self.set_body(CANotify01MessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/cc/message.py b/midealocal/devices/cc/message.py index 3d133c3f..08c826af 100644 --- a/midealocal/devices/cc/message.py +++ b/midealocal/devices/cc/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -26,7 +26,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize CC message base.""" super().__init__( @@ -49,7 +49,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 @@ -65,7 +65,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.C3, + body_type=ListTypes.C3, ) self.power = False self.mode = 4 @@ -170,12 +170,12 @@ def __init__(self, message: bytes) -> None: """Initialize CC message response.""" super().__init__(bytearray(message)) if ( - (self.message_type == MessageType.query and self.body_type == BodyType.X01) + (self.message_type == MessageType.query and self.body_type == ListTypes.X01) or ( self.message_type in [MessageType.notify1, MessageType.notify2] - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ) - or (self.message_type == MessageType.set and self.body_type == BodyType.C3) + or (self.message_type == MessageType.set and self.body_type == ListTypes.C3) ): self.set_body(CCGeneralMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/cd/message.py b/midealocal/devices/cd/message.py index 67408d25..e3d2f1fc 100644 --- a/midealocal/devices/cd/message.py +++ b/midealocal/devices/cd/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -19,7 +19,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize CD message base.""" super().__init__( @@ -42,7 +42,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 @@ -58,7 +58,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.power = False self.target_temperature = 0 diff --git a/midealocal/devices/ce/message.py b/midealocal/devices/ce/message.py index 7f6a26e5..113be0ba 100644 --- a/midealocal/devices/ce/message.py +++ b/midealocal/devices/ce/message.py @@ -2,7 +2,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -17,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize CE message base.""" super().__init__( @@ -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 @@ -56,7 +56,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.power = False @@ -154,13 +154,13 @@ def __init__(self, message: bytes) -> None: super().__init__(bytearray(message)) if ( self.message_type in [MessageType.query, MessageType.set] - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ) or ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X02 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X02 ): self.set_body(CEGeneralMessageBody(super().body)) elif ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X01 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X01 ): self.set_body(CENotifyMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/cf/message.py b/midealocal/devices/cf/message.py index 934dc990..eb4bbf2d 100644 --- a/midealocal/devices/cf/message.py +++ b/midealocal/devices/cf/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -28,7 +28,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize CF message base.""" super().__init__( @@ -51,7 +51,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 @@ -67,7 +67,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.power = False self.mode = 0 # 1 自动 2 制冷 3 制热 @@ -120,7 +120,7 @@ def __init__(self, message: bytes) -> None: super().__init__(bytearray(message)) if ( self.message_type in [MessageType.query, MessageType.set] - and self.body_type == BodyType.X01 + and self.body_type == ListTypes.X01 ): self.set_body(CFMessageBody(super().body, data_offset=1)) elif self.message_type in [MessageType.notify1, MessageType.notify2]: diff --git a/midealocal/devices/da/message.py b/midealocal/devices/da/message.py index 493474cc..3074bc5f 100644 --- a/midealocal/devices/da/message.py +++ b/midealocal/devices/da/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -17,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize DA message base.""" super().__init__( @@ -40,7 +40,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X03, + body_type=ListTypes.X03, ) @property @@ -56,7 +56,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = False @@ -74,7 +74,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.start = False self.washing_data = bytearray([]) @@ -125,7 +125,7 @@ def __init__(self, message: bytes) -> None: """Initialize DA message response.""" super().__init__(bytearray(message)) if self.message_type in [MessageType.query, MessageType.set] or ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X04 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X04 ): self.set_body(DAGeneralMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/db/message.py b/midealocal/devices/db/message.py index 93fb820d..6a724a85 100644 --- a/midealocal/devices/db/message.py +++ b/midealocal/devices/db/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -17,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize DB message base.""" super().__init__( @@ -40,7 +40,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X03, + body_type=ListTypes.X03, ) @property @@ -56,7 +56,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = False @@ -98,7 +98,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.start = False self.washing_data = bytearray([]) @@ -137,7 +137,7 @@ def __init__(self, message: bytes) -> None: """Initialize DB message response.""" super().__init__(bytearray(message)) if self.message_type in [MessageType.query, MessageType.set] or ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X04 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X04 ): self.set_body(DBGeneralMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/dc/message.py b/midealocal/devices/dc/message.py index ce8e7d75..9fc83aa8 100644 --- a/midealocal/devices/dc/message.py +++ b/midealocal/devices/dc/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -17,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize DC message base.""" super().__init__( @@ -40,7 +40,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X03, + body_type=ListTypes.X03, ) @property @@ -56,7 +56,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = False @@ -74,7 +74,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.start = False self.washing_data = bytearray([]) @@ -113,7 +113,7 @@ def __init__(self, message: bytes) -> None: """Initialize DC message response.""" super().__init__(bytearray(message)) if self.message_type in [MessageType.query, MessageType.set] or ( - self.message_type == MessageType.notify1 and self.body_type == BodyType.X04 + self.message_type == MessageType.notify1 and self.body_type == ListTypes.X04 ): self.set_body(DCGeneralMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/e1/message.py b/midealocal/devices/e1/message.py index b124d011..76bb2fe4 100644 --- a/midealocal/devices/e1/message.py +++ b/midealocal/devices/e1/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -21,7 +21,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize E1 message base.""" super().__init__( @@ -44,7 +44,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X08, + body_type=ListTypes.X08, ) self.power = False @@ -62,7 +62,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X83, + body_type=ListTypes.X83, ) self.lock = False @@ -80,7 +80,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X81, + body_type=ListTypes.X81, ) self.storage = False @@ -102,7 +102,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 @@ -156,7 +156,8 @@ def __init__(self, message: bytes) -> None: """Initialize E1 message response.""" super().__init__(bytearray(message)) if ( - self.message_type == MessageType.set and 0 <= self.body_type <= BodyType.X07 + self.message_type == MessageType.set + and 0 <= self.body_type <= ListTypes.X07 ) or ( self.message_type in [MessageType.query, MessageType.notify1] and self.body_type == 0 diff --git a/midealocal/devices/e2/message.py b/midealocal/devices/e2/message.py index 0f520e1c..9d145f43 100644 --- a/midealocal/devices/e2/message.py +++ b/midealocal/devices/e2/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -21,7 +21,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize E2 message base.""" super().__init__( @@ -44,7 +44,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 @@ -60,16 +60,16 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = False @property def _body(self) -> bytearray: if self.power: - self.body_type = BodyType.X01 + self.body_type = ListTypes.X01 else: - self.body_type = BodyType.X02 + self.body_type = ListTypes.X02 return bytearray([0x01]) @@ -81,7 +81,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X14, + body_type=ListTypes.X14, ) self.target_temperature: int | None = None self.variable_heating: bool | None = None @@ -111,7 +111,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X04, + body_type=ListTypes.X04, ) self.target_temperature = 0 self.variable_heating = False diff --git a/midealocal/devices/e3/message.py b/midealocal/devices/e3/message.py index 4a8cd9be..ba42041e 100644 --- a/midealocal/devices/e3/message.py +++ b/midealocal/devices/e3/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -29,7 +29,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize E3 message base.""" super().__init__( @@ -52,7 +52,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 @@ -68,16 +68,16 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) self.power = False @property def _body(self) -> bytearray: if self.power: - self.body_type = BodyType.X01 + self.body_type = ListTypes.X01 else: - self.body_type = BodyType.X02 + self.body_type = ListTypes.X02 return bytearray([0x01]) @@ -89,7 +89,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X04, + body_type=ListTypes.X04, ) self.target_temperature = 0 @@ -138,7 +138,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X14, + body_type=ListTypes.X14, ) self.key = "none" self.value: Any = None diff --git a/midealocal/devices/e6/message.py b/midealocal/devices/e6/message.py index d492949a..e685b70d 100644 --- a/midealocal/devices/e6/message.py +++ b/midealocal/devices/e6/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -23,7 +23,7 @@ def __init__( device_type=DeviceType.E6, protocol_version=protocol_version, message_type=message_type, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) @property diff --git a/midealocal/devices/e8/message.py b/midealocal/devices/e8/message.py index f8ab61b1..9c14e3b6 100644 --- a/midealocal/devices/e8/message.py +++ b/midealocal/devices/e8/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -29,7 +29,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize E8 message base.""" super().__init__( @@ -52,7 +52,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.AA, + body_type=ListTypes.AA, ) @property diff --git a/midealocal/devices/ea/message.py b/midealocal/devices/ea/message.py index d168052e..e297fbcb 100644 --- a/midealocal/devices/ea/message.py +++ b/midealocal/devices/ea/message.py @@ -4,12 +4,11 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, MessageType, - SubBodyType, ) @@ -27,7 +26,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType = BodyType.X00, + body_type: ListTypes = ListTypes.X00, ) -> None: """Initialize EA message base.""" super().__init__( @@ -135,46 +134,42 @@ def __init__(self, message: bytes) -> None: super().__init__(bytearray(message)) if ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X01 + and super().body[3] == ListTypes.X01 ): self.set_body(EABodyNew(super().body)) elif self.protocol_version == 0: if ( self.message_type == MessageType.set - and super().body[5] == SubBodyType.X16 + and super().body[5] == ListTypes.X16 ): # 381 self.set_body(EABody1(super().body)) elif self.message_type == MessageType.query: if ( - super().body[6] == SubBodyType.X52 - and super().body[7] == SubBodyType.C3 + super().body[6] == ListTypes.X52 and super().body[7] == ListTypes.C3 ): # 404 self.set_body(EABody2(super().body)) - elif super().body[5] == SubBodyType.X3D: # 420 + elif super().body[5] == ListTypes.X3D: # 420 self.set_body(EABody1(super().body)) elif ( self.message_type == MessageType.notify1 - and super().body[5] == SubBodyType.X3D + and super().body[5] == ListTypes.X3D ): # 463 self.set_body(EABody1(super().body)) elif ( - ( - self.message_type == MessageType.set - and super().body[3] == SubBodyType.X02 - ) + (self.message_type == MessageType.set and super().body[3] == ListTypes.X02) or ( self.message_type == MessageType.query - and super().body[3] == SubBodyType.X03 + and super().body[3] == ListTypes.X03 ) or ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X04 + and super().body[3] == ListTypes.X04 ) ): # 351 self.set_body(EABody3(super().body)) elif ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X06 + and super().body[3] == ListTypes.X06 ): self.mode = super().body[4] + (super().body[5] << 8) self.set_attr() diff --git a/midealocal/devices/ec/message.py b/midealocal/devices/ec/message.py index c0f9cfed..3ae4705f 100644 --- a/midealocal/devices/ec/message.py +++ b/midealocal/devices/ec/message.py @@ -2,12 +2,11 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, MessageType, - SubBodyType, ) @@ -18,7 +17,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType = BodyType.X00, + body_type: ListTypes = ListTypes.X00, ) -> None: """Initialize EC message base.""" super().__init__( @@ -92,31 +91,28 @@ def __init__(self, message: bytes) -> None: super().__init__(bytearray(message)) if ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X01 + and super().body[3] == ListTypes.X01 ): self.set_body(ECBodyNew(super().body)) elif ( - ( - self.message_type == MessageType.set - and super().body[3] == SubBodyType.X02 - ) + (self.message_type == MessageType.set and super().body[3] == ListTypes.X02) or ( self.message_type == MessageType.query - and super().body[3] == SubBodyType.X03 + and super().body[3] == ListTypes.X03 ) or ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X04 + and super().body[3] == ListTypes.X04 ) or ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X3D + and super().body[3] == ListTypes.X3D ) ): self.set_body(ECGeneralMessageBody(super().body)) elif ( self.message_type == MessageType.notify1 - and super().body[3] == SubBodyType.X06 + and super().body[3] == ListTypes.X06 ): self.mode = super().body[4] + (super().body[5] << 8) self.set_attr() diff --git a/midealocal/devices/ed/__init__.py b/midealocal/devices/ed/__init__.py index f8472611..92b62ddd 100644 --- a/midealocal/devices/ed/__init__.py +++ b/midealocal/devices/ed/__init__.py @@ -6,7 +6,7 @@ from midealocal.const import DeviceType, ProtocolVersion from midealocal.device import MideaDevice -from midealocal.message import BodyType +from midealocal.message import ListTypes from .message import MessageEDResponse, MessageNewSet, MessageOldSet, MessageQuery @@ -71,7 +71,7 @@ def __init__( DeviceAttributes.child_lock: False, }, ) - self._device_class = BodyType.X00 + self._device_class = ListTypes.X00 def _use_new_set(self) -> bool: # if (self.sub_type > 342 or self.sub_type == 340) else False diff --git a/midealocal/devices/ed/message.py b/midealocal/devices/ed/message.py index 7a51549e..ecad02e6 100644 --- a/midealocal/devices/ed/message.py +++ b/midealocal/devices/ed/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -46,7 +46,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType = BodyType.X00, + body_type: ListTypes = ListTypes.X00, ) -> None: """Initialize ED message base.""" super().__init__( @@ -64,7 +64,7 @@ def _body(self) -> bytearray: class MessageQuery(MessageEDBase): """ED message query.""" - def __init__(self, protocol_version: int, body_type: BodyType) -> None: + def __init__(self, protocol_version: int, body_type: ListTypes) -> None: """Initialize ED message query.""" super().__init__( protocol_version=protocol_version, @@ -85,7 +85,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X15, + body_type=ListTypes.X15, ) self.power: bool | None = None self.lock: bool | None = None @@ -250,16 +250,16 @@ def __init__(self, message: bytes) -> None: MessageType.notify1, ]: self.device_class = self._body_type - if self._body_type in [BodyType.X00, BodyType.X15, BodyType.FF]: + if self._body_type in [ListTypes.X00, ListTypes.X15, ListTypes.FF]: self.set_body(EDMessageBodyFF(super().body)) - if self.body_type == BodyType.X01: + if self.body_type == ListTypes.X01: self.set_body(EDMessageBody01(super().body)) - elif self.body_type in [BodyType.X03, BodyType.X04]: + elif self.body_type in [ListTypes.X03, ListTypes.X04]: self.set_body(EDMessageBody03(super().body)) - elif self.body_type == BodyType.X05: + elif self.body_type == ListTypes.X05: self.set_body(EDMessageBody05(super().body)) - elif self.body_type == BodyType.X06: + elif self.body_type == ListTypes.X06: self.set_body(EDMessageBody06(super().body)) - elif self.body_type == BodyType.X07: + elif self.body_type == ListTypes.X07: self.set_body(EDMessageBody07(super().body)) self.set_attr() diff --git a/midealocal/devices/fa/message.py b/midealocal/devices/fa/message.py index f7ad927b..ed5ae462 100644 --- a/midealocal/devices/fa/message.py +++ b/midealocal/devices/fa/message.py @@ -2,12 +2,11 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, MessageType, - SubBodyType, ) MAX_FAN_SPEED = 26 @@ -22,7 +21,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType = BodyType.X00, + body_type: ListTypes = ListTypes.X00, ) -> None: """Initialize the message with protocol version, message type, and body type.""" super().__init__( @@ -65,7 +64,7 @@ def __init__(self, protocol_version: int, subtype: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self._subtype = subtype self.power: bool | None = None @@ -79,7 +78,7 @@ def __init__(self, protocol_version: int, subtype: int) -> None: @property def _body(self) -> bytearray: - if 1 <= self._subtype <= SubBodyType.X0A or self._subtype == SubBodyType.A1: + if 1 <= self._subtype <= ListTypes.X0A or self._subtype == ListTypes.A1: _body_return = bytearray( [ 0x00, @@ -102,7 +101,7 @@ def _body(self) -> bytearray: 0x00, ], ) - if self._subtype != SubBodyType.X0A: + if self._subtype != ListTypes.X0A: _body_return[13] = 0xFF else: _body_return = bytearray( diff --git a/midealocal/devices/fb/message.py b/midealocal/devices/fb/message.py index ec000d25..31e16c1e 100644 --- a/midealocal/devices/fb/message.py +++ b/midealocal/devices/fb/message.py @@ -2,12 +2,11 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, MessageType, - SubBodyType, ) CHILD_LOCK_BYTE = 18 @@ -25,7 +24,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType = BodyType.X00, + body_type: ListTypes = ListTypes.X00, ) -> None: """Initialize FB message base.""" super().__init__( @@ -68,7 +67,7 @@ def __init__(self, protocol_version: int, subtype: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self._subtype = subtype self.power: bool | None = None @@ -133,7 +132,7 @@ def body(self) -> bytearray: 0x00, ], ) - if self._subtype > SubBodyType.X05: + if self._subtype > ListTypes.X05: _return_body += bytearray([0x00, 0x00, 0x00]) return _return_body diff --git a/midealocal/devices/fc/message.py b/midealocal/devices/fc/message.py index d0ef97f0..ff99cfb6 100644 --- a/midealocal/devices/fc/message.py +++ b/midealocal/devices/fc/message.py @@ -3,7 +3,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.crc8 import calculate from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -37,7 +37,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize FC message base.""" super().__init__( @@ -71,7 +71,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 @@ -109,7 +109,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.mode = 0 @@ -253,14 +253,16 @@ class MessageFCResponse(MessageResponse): def __init__(self, message: bytes) -> None: """Initialize FC message response.""" super().__init__(bytearray(message)) - if self.body_type in [BodyType.B0, BodyType.B1]: + if self.body_type in [ListTypes.B0, ListTypes.B1]: pass elif ( self.message_type in [MessageType.query, MessageType.set, MessageType.notify1] - and self.body_type == BodyType.C8 + and self.body_type == ListTypes.C8 ): self.set_body(FCGeneralMessageBody(super().body)) - elif self.message_type == MessageType.notify1 and self.body_type == BodyType.A0: + elif ( + self.message_type == MessageType.notify1 and self.body_type == ListTypes.A0 + ): self.set_body(FCNotifyMessageBody(super().body)) self.set_attr() diff --git a/midealocal/devices/fd/message.py b/midealocal/devices/fd/message.py index 2a550a87..be7b42ab 100644 --- a/midealocal/devices/fd/message.py +++ b/midealocal/devices/fd/message.py @@ -3,7 +3,7 @@ from midealocal.const import DeviceType from midealocal.crc8 import calculate from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -25,7 +25,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize FD message base.""" super().__init__( @@ -59,7 +59,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 @@ -97,7 +97,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.fan_speed = 0 @@ -192,9 +192,9 @@ def __init__(self, message: bytes) -> None: ]: if self.body_type in [0xB0, 0xB1]: pass - elif self.body_type == BodyType.A0: + elif self.body_type == ListTypes.A0: self.set_body(FDA0MessageBody(super().body)) - elif self.body_type == BodyType.C8: + elif self.body_type == ListTypes.C8: self.set_body(FDC8MessageBody(super().body)) self.fan_speed: int self.set_attr() diff --git a/midealocal/devices/x13/message.py b/midealocal/devices/x13/message.py index da7b322e..f3646615 100644 --- a/midealocal/devices/x13/message.py +++ b/midealocal/devices/x13/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -19,7 +19,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize X13 message base.""" super().__init__( @@ -42,7 +42,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.query, - body_type=BodyType.X24, + body_type=ListTypes.X24, ) @property @@ -58,7 +58,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self.brightness: int | None = None self.color_temperature: int | None = None @@ -69,16 +69,16 @@ def __init__(self, protocol_version: int) -> None: def _body(self) -> bytearray: body_byte = 0x00 if self.power is not None: - self.body_type = BodyType.X01 + self.body_type = ListTypes.X01 body_byte = 0x01 if self.power else 0x00 elif self.effect is not None and self.effect in range(1, 6): - self.body_type = BodyType.X01 + self.body_type = ListTypes.X01 body_byte = self.effect + 1 elif self.color_temperature is not None: - self.body_type = BodyType.X03 + self.body_type = ListTypes.X03 body_byte = self.color_temperature elif self.brightness is not None: - self.body_type = BodyType.X04 + self.body_type = ListTypes.X04 body_byte = self.brightness return bytearray([body_byte, 0x00, 0x00, 0x00]) @@ -112,9 +112,9 @@ class Message13Response(MessageResponse): def __init__(self, message: bytes) -> None: """Initialize X13 message response.""" super().__init__(bytearray(message)) - if self.body_type == BodyType.A4: + if self.body_type == ListTypes.A4: self.set_body(MessageMainLightBody(super().body)) - elif self.message_type == MessageType.set and self.body_type > BodyType.X80: + elif self.message_type == MessageType.set and self.body_type > ListTypes.X80: self.set_body(MessageMainLightResponseBody(super().body)) self.control_success: bool self.set_attr() diff --git a/midealocal/devices/x26/message.py b/midealocal/devices/x26/message.py index 2b3f0c70..df50edf7 100644 --- a/midealocal/devices/x26/message.py +++ b/midealocal/devices/x26/message.py @@ -5,7 +5,7 @@ from midealocal.const import MAX_BYTE_VALUE, DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -34,7 +34,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize X26 message base.""" super().__init__( @@ -57,7 +57,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 @@ -73,7 +73,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.fields: dict[str, int] = {} self.main_light = False diff --git a/midealocal/devices/x34/message.py b/midealocal/devices/x34/message.py index a2eb74ed..b8d7b56c 100644 --- a/midealocal/devices/x34/message.py +++ b/midealocal/devices/x34/message.py @@ -2,7 +2,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -20,7 +20,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize X34 message base.""" super().__init__( @@ -43,7 +43,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 @@ -59,7 +59,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X08, + body_type=ListTypes.X08, ) self.power = False @@ -77,7 +77,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X83, + body_type=ListTypes.X83, ) self.lock = False @@ -95,7 +95,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X81, + body_type=ListTypes.X81, ) self.storage = False @@ -155,7 +155,8 @@ def __init__(self, message: bytes) -> None: """Initialize X34 message response.""" super().__init__(bytearray(message)) if ( - self.message_type == MessageType.set and 0 <= self.body_type <= BodyType.X07 + self.message_type == MessageType.set + and 0 <= self.body_type <= ListTypes.X07 ) or ( self.message_type in [MessageType.query, MessageType.notify1] and self.body_type == 0 diff --git a/midealocal/devices/x40/message.py b/midealocal/devices/x40/message.py index a6080563..fdadf640 100644 --- a/midealocal/devices/x40/message.py +++ b/midealocal/devices/x40/message.py @@ -4,7 +4,7 @@ from midealocal.const import DeviceType from midealocal.message import ( - BodyType, + ListTypes, MessageBody, MessageRequest, MessageResponse, @@ -21,7 +21,7 @@ def __init__( self, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize X40 message base.""" super().__init__( @@ -44,7 +44,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 @@ -60,7 +60,7 @@ def __init__(self, protocol_version: int) -> None: super().__init__( protocol_version=protocol_version, message_type=MessageType.set, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) self.fields: dict[str, int | bool] = {} self.light = False diff --git a/midealocal/message.py b/midealocal/message.py index 6f82a34b..6e207aed 100644 --- a/midealocal/message.py +++ b/midealocal/message.py @@ -1,30 +1,115 @@ """Midea local message.""" import logging +import warnings from enum import IntEnum -from typing import Generic, SupportsIndex, TypeVar, cast +from typing import Any, Generic, SupportsIndex, TypeVar, cast + +from deprecated import deprecated from midealocal.const import DeviceType _LOGGER = logging.getLogger(__name__) -class BodyType(IntEnum): - """Body Type.""" +class ListTypes(IntEnum): + """Body and SubBody Types.""" A0 = 0xA0 A1 = 0xA1 + A2 = 0xA2 A3 = 0xA3 A4 = 0xA4 + A5 = 0xA5 + A6 = 0xA6 + A7 = 0xA7 + A8 = 0xA8 + A9 = 0xA9 AA = 0xAA + AB = 0xAB + AC = 0xAC + AD = 0xAD + AE = 0xAE + AF = 0xAF B0 = 0xB0 B1 = 0xB1 + B2 = 0xB2 + B3 = 0xB3 + B4 = 0xB4 B5 = 0xB5 + B6 = 0xB6 + B7 = 0xB7 + B8 = 0xB8 + B9 = 0xB9 + BA = 0xBA BB = 0xBB + BC = 0xBC + BD = 0xBD + BE = 0xBE + BF = 0xBF C0 = 0xC0 C1 = 0xC1 + C2 = 0xC2 C3 = 0xC3 + C4 = 0xC4 + C5 = 0xC5 + C6 = 0xC6 + C7 = 0xC7 C8 = 0xC8 + C9 = 0xC9 + CA = 0xCA + CB = 0xCB + CC = 0xCC + CD = 0xCD + CE = 0xCE + CF = 0xCF + D0 = 0xD0 + D1 = 0xD1 + D2 = 0xD2 + D3 = 0xD3 + D4 = 0xD4 + D5 = 0xD5 + D6 = 0xD6 + D7 = 0xD7 + D8 = 0xD8 + D9 = 0xD9 + DA = 0xDA + DB = 0xDB + DC = 0xDC + DD = 0xDD + DE = 0xDE + DF = 0xDF + E0 = 0xE0 + E1 = 0xE1 + E2 = 0xE2 + E3 = 0xE3 + E4 = 0xE4 + E5 = 0xE5 + E6 = 0xE6 + E7 = 0xE7 + E8 = 0xE8 + E9 = 0xE9 + EA = 0xEA + EB = 0xEB + EC = 0xEC + ED = 0xED + EE = 0xEE + EF = 0xEF + F0 = 0xF0 + F1 = 0xF1 + F2 = 0xF2 + F3 = 0xF3 + F4 = 0xF4 + F5 = 0xF5 + F6 = 0xF6 + F7 = 0xF7 + F8 = 0xF8 + F9 = 0xF9 + FA = 0xFA + FB = 0xFB + FC = 0xFC + FD = 0xFD + FE = 0xFE FF = 0xFF X00 = 0x00 X01 = 0x01 @@ -35,59 +120,185 @@ class BodyType(IntEnum): X06 = 0x06 X07 = 0x07 X08 = 0x08 + X09 = 0x09 X0A = 0x0A + X0B = 0x0B + X0C = 0x0C + X0D = 0x0D + X0E = 0x0E + X0F = 0x0F + X10 = 0x10 X11 = 0x11 + X12 = 0x12 + X13 = 0x13 X14 = 0x14 X15 = 0x15 + X16 = 0x16 + X17 = 0x17 + X18 = 0x18 + X19 = 0x19 + X1A = 0x1A + X1B = 0x1B + X1C = 0x1C + X1D = 0x1D + X1E = 0x1E + X1F = 0x1F + X20 = 0x20 X21 = 0x21 X22 = 0x22 + X23 = 0x23 X24 = 0x24 + X25 = 0x25 + X26 = 0x26 + X27 = 0x27 + X28 = 0x28 + X29 = 0x29 + X2A = 0x2A + X2B = 0x2B + X2C = 0x2C + X2D = 0x2D + X2E = 0x2E + X2F = 0x2F + X30 = 0x30 X31 = 0x31 X32 = 0x32 + X33 = 0x33 + X34 = 0x34 + X35 = 0x35 + X36 = 0x36 + X37 = 0x37 + X38 = 0x38 + X39 = 0x39 + X3A = 0x3A + X3B = 0x3B + X3C = 0x3C + X3D = 0x3D + X3E = 0x3E + X3F = 0x3F X40 = 0x40 X41 = 0x41 X42 = 0x42 + X43 = 0x43 + X44 = 0x44 + X45 = 0x45 + X46 = 0x46 + X47 = 0x47 X48 = 0x48 + X49 = 0x49 + X4A = 0x4A + X4B = 0x4B + X4C = 0x4C + X4D = 0x4D + X4E = 0x4E + X4F = 0x4F + X50 = 0x50 + X51 = 0x51 + X52 = 0x52 + X53 = 0x53 + X54 = 0x54 + X55 = 0x55 + X56 = 0x56 + X57 = 0x57 + X58 = 0x58 + X59 = 0x59 + X5A = 0x5A + X5B = 0x5B + X5C = 0x5C + X5D = 0x5D + X5E = 0x5E + X5F = 0x5F + X60 = 0x60 + X61 = 0x61 + X62 = 0x62 + X63 = 0x63 + X64 = 0x64 + X65 = 0x65 + X66 = 0x66 + X67 = 0x67 + X68 = 0x68 + X69 = 0x69 + X6A = 0x6A + X6B = 0x6B + X6C = 0x6C + X6D = 0x6D + X6E = 0x6E + X6F = 0x6F + X70 = 0x70 + X71 = 0x71 + X72 = 0x72 + X73 = 0x73 + X74 = 0x74 + X75 = 0x75 + X76 = 0x76 + X77 = 0x77 + X78 = 0x78 + X79 = 0x79 + X7A = 0x7A + X7B = 0x7B + X7C = 0x7C + X7D = 0x7D + X7E = 0x7E + X7F = 0x7F X80 = 0x80 X81 = 0x81 + X82 = 0x82 X83 = 0x83 + X84 = 0x84 + X85 = 0x85 + X86 = 0x86 + X87 = 0x87 + X88 = 0x88 + X89 = 0x89 + X8A = 0x8A + X8B = 0x8B + X8C = 0x8C + X8D = 0x8D + X8E = 0x8E + X8F = 0x8F + X90 = 0x90 + X91 = 0x91 + X92 = 0x92 + X93 = 0x93 + X94 = 0x94 + X95 = 0x95 + X96 = 0x96 + X97 = 0x97 + X98 = 0x98 + X99 = 0x99 + X9A = 0x9A + X9B = 0x9B + X9C = 0x9C + X9D = 0x9D + X9E = 0x9E + X9F = 0x9F + + +@deprecated("Use ListTypes instead") +class BodyType(IntEnum): + """Body Types (Deprecated).""" + + @classmethod + def _missing_(cls, value: Any) -> IntEnum: # noqa: ANN401 + warnings.warn( + "BodyType is deprecated, use ListTypes instead.", + DeprecationWarning, + stacklevel=2, + ) + return ListTypes(value) +@deprecated("Use ListTypes instead") class SubBodyType(IntEnum): - """Sub Body Type.""" + """SubBody Types (Deprecated).""" - A0 = 0xA0 - A1 = 0xA1 - A2 = 0xA2 - B0 = 0xB0 - B1 = 0xB1 - B5 = 0xB5 - BB = 0xBB - C0 = 0xC0 - C1 = 0xC1 - C3 = 0xC3 - X01 = 0x01 - X02 = 0x02 - X03 = 0x03 - X04 = 0x04 - X05 = 0x05 - X06 = 0x06 - X0A = 0x0A - X10 = 0x10 - X11 = 0x11 - X12 = 0x12 - X13 = 0x13 - X16 = 0x16 - X20 = 0x20 - X21 = 0x21 - X22 = 0x22 - X24 = 0x24 - X30 = 0x30 - X31 = 0x31 - X32 = 0x32 - X3D = 0x3D - X41 = 0x41 - X52 = 0x52 + @classmethod + def _missing_(cls, value: Any) -> IntEnum: # noqa: ANN401 + warnings.warn( + "SubBodyType is deprecated, use ListTypes instead.", + DeprecationWarning, + stacklevel=2, + ) + return ListTypes(value) class MessageLenError(Exception): @@ -132,7 +343,7 @@ def __init__(self) -> None: """Initialize message base.""" self._device_type: DeviceType = DeviceType.X00 self._message_type: MessageType = MessageType.default - self._body_type: BodyType = BodyType.X00 + self._body_type: ListTypes = ListTypes.X00 self._message_protocol_version: int = 0 @staticmethod @@ -169,12 +380,12 @@ def device_type(self, value: DeviceType) -> None: self._device_type = value @property - def body_type(self) -> BodyType: + def body_type(self) -> ListTypes: """Message body type.""" return self._body_type @body_type.setter - def body_type(self, value: BodyType) -> None: + def body_type(self, value: ListTypes) -> None: self._body_type = value @property @@ -236,7 +447,7 @@ def __init__( device_type: DeviceType, protocol_version: int, message_type: MessageType, - body_type: BodyType, + body_type: ListTypes, ) -> None: """Initialize message request.""" super().__init__() @@ -309,7 +520,7 @@ def __init__( device_type=device_type, protocol_version=protocol_version, message_type=cmd_type, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) self._cmd_body = cmd_body @@ -332,7 +543,7 @@ def __init__(self, device_type: DeviceType) -> None: device_type=device_type, protocol_version=0, message_type=MessageType.query_appliance, - body_type=BodyType.X00, + body_type=ListTypes.X00, ) @property @@ -502,9 +713,9 @@ def data(self) -> bytearray: return self._data @property - def body_type(self) -> BodyType: + def body_type(self) -> ListTypes: """Message body type.""" - return BodyType(self._data[0]) + return ListTypes(self._data[0]) @staticmethod def read_byte(body: bytearray, byte: int, default_value: int = 0) -> int: @@ -530,7 +741,7 @@ class NewProtocolMessageBody(MessageBody): def __init__(self, body: bytearray, bt: int) -> None: """Initialize new protocol message body.""" super().__init__(body) - if bt == BodyType.B5: + if bt == ListTypes.B5: self._pack_len = NewProtocolPackLength.FOUR else: self._pack_len = NewProtocolPackLength.FIVE diff --git a/midealocal/version.py b/midealocal/version.py index 75fd81d2..4c53f64f 100644 --- a/midealocal/version.py +++ b/midealocal/version.py @@ -1,3 +1,3 @@ """Midea Local Version.""" -__version__ = "6.0.1" +__version__ = "6.0.3" diff --git a/requirements-dev.txt b/requirements-dev.txt index 097a0001..2659965c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,4 +6,5 @@ pytest-asyncio pytest-cov ruff setuptools +types-deprecated types-aiofiles diff --git a/requirements.txt b/requirements.txt index c16efbc3..9cce0991 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ aiohttp colorlog commonregex defusedxml +deprecated ifaddr pycryptodome platformdirs diff --git a/scripts/setup.sh b/scripts/setup.sh index 43d671e4..d96b5b27 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -5,3 +5,6 @@ set -e pre-commit install +pre-commit install --hook-type commit-msg +cd +npm install @commitlint/config-conventional diff --git a/tests/devices/a1/message_a1_test.py b/tests/devices/a1/message_a1_test.py index 80de6173..b6b56a02 100644 --- a/tests/devices/a1/message_a1_test.py +++ b/tests/devices/a1/message_a1_test.py @@ -12,7 +12,7 @@ MessageSet, NewProtocolTags, ) -from midealocal.message import BodyType, MessageType +from midealocal.message import ListTypes, MessageType class TestMessageA1Base: @@ -23,12 +23,12 @@ def test_message_id_increment(self) -> None: msg = MessageA1Base( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) msg2 = MessageA1Base( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) assert msg2._message_id == msg._message_id + 1 # test reset @@ -36,7 +36,7 @@ def test_message_id_increment(self) -> None: msg = MessageA1Base( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) assert msg._message_id == 1 @@ -45,7 +45,7 @@ def test_body_not_implemented(self) -> None: msg = MessageA1Base( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) with pytest.raises(NotImplementedError): _ = msg.body diff --git a/tests/devices/ac/message_ac_test.py b/tests/devices/ac/message_ac_test.py index 7425abf1..8912e786 100644 --- a/tests/devices/ac/message_ac_test.py +++ b/tests/devices/ac/message_ac_test.py @@ -16,7 +16,7 @@ MessageToggleDisplay, NewProtocolTags, ) -from midealocal.message import BodyType, MessageType +from midealocal.message import ListTypes, MessageType class TestMessageACBase: @@ -27,12 +27,12 @@ def test_message_id_increment(self) -> None: msg = MessageACBase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) msg2 = MessageACBase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) assert msg2._message_id == msg._message_id + 1 # test reset @@ -40,7 +40,7 @@ def test_message_id_increment(self) -> None: msg = MessageACBase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) assert msg._message_id == 1 @@ -49,7 +49,7 @@ def test_body_not_implemented(self) -> None: msg = MessageACBase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) with pytest.raises(NotImplementedError): _ = msg.body diff --git a/tests/devices/c3/message_c3_test.py b/tests/devices/c3/message_c3_test.py index 11a7017e..8787269b 100644 --- a/tests/devices/c3/message_c3_test.py +++ b/tests/devices/c3/message_c3_test.py @@ -14,7 +14,7 @@ MessageSetECO, MessageSetSilent, ) -from midealocal.message import BodyType, MessageType +from midealocal.message import ListTypes, MessageType class TestMessageC3Base: @@ -25,7 +25,7 @@ def test_body_not_implemented(self) -> None: msg = MessageC3Base( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) with pytest.raises(NotImplementedError): _ = msg.body @@ -142,7 +142,7 @@ def test_message_generic_response(self) -> None: """Test message generic response.""" body = bytearray( [ - BodyType.X01, + ListTypes.X01, 0x01 | 0x04 | 0x08 @@ -182,7 +182,7 @@ def test_message_generic_response(self) -> None: self.header[-1] = message_type response = MessageC3Response(self.header + body) - assert response.body_type == BodyType.X01 + assert response.body_type == ListTypes.X01 assert hasattr(response, "zone1_power") assert response.zone1_power is True assert hasattr(response, "zone2_power") @@ -241,7 +241,7 @@ def test_message_notify1_x04_response(self) -> None: self.header[-1] = MessageType.notify1 body = bytearray( [ - BodyType.X04, + ListTypes.X04, 0x01 | 0x04, # BYTE 1: status_dhw + status_heating 0x32, # BYTE 2: total_energy_consumption 0x1A, # BYTE 3: total_energy_consumption @@ -256,7 +256,7 @@ def test_message_notify1_x04_response(self) -> None: ], ) response = MessageC3Response(self.header + body) - assert response.body_type == BodyType.X04 + assert response.body_type == ListTypes.X04 assert hasattr(response, "status_tbh") assert response.status_tbh is False assert hasattr(response, "status_dhw") @@ -282,7 +282,7 @@ def test_message_silence_response(self) -> None: self.header[-1] = MessageType.query body = bytearray( [ - BodyType.X05, + ListTypes.X05, 0x00, 0x00, 0x00, diff --git a/tests/devices/da/message_da_test.py b/tests/devices/da/message_da_test.py index b778914c..2588905d 100644 --- a/tests/devices/da/message_da_test.py +++ b/tests/devices/da/message_da_test.py @@ -10,7 +10,7 @@ MessageQuery, MessageStart, ) -from midealocal.message import BodyType, MessageType +from midealocal.message import ListTypes, MessageType class TestMessageDABase: @@ -21,7 +21,7 @@ def test_body_not_implemented(self) -> None: msg = MessageDABase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) with pytest.raises(NotImplementedError): _ = msg.body diff --git a/tests/devices/ed/message_ed_test.py b/tests/devices/ed/message_ed_test.py index a8e03a7e..3e280f62 100644 --- a/tests/devices/ed/message_ed_test.py +++ b/tests/devices/ed/message_ed_test.py @@ -15,7 +15,7 @@ MessageNewSet, MessageQuery, ) -from midealocal.message import BodyType, MessageType +from midealocal.message import ListTypes, MessageType class TestMessageEDBase: @@ -26,7 +26,7 @@ def test_body_not_implemented(self) -> None: msg = MessageEDBase( protocol_version=ProtocolVersion.V1, message_type=MessageType.query, - body_type=BodyType.X01, + body_type=ListTypes.X01, ) with pytest.raises(NotImplementedError): _ = msg.body @@ -39,7 +39,7 @@ def test_query_body(self) -> None: """Test query body.""" query = MessageQuery( protocol_version=ProtocolVersion.V1, - body_type=BodyType.X02, + body_type=ListTypes.X02, ) expected_body = bytearray([0x02, 0x01]) assert query.body == expected_body diff --git a/tests/message_test.py b/tests/message_test.py index f9a43283..3ec7415b 100644 --- a/tests/message_test.py +++ b/tests/message_test.py @@ -4,10 +4,10 @@ from midealocal.message import ( BodyParser, - BodyType, BoolParser, IntEnumParser, IntParser, + ListTypes, MessageBody, ) @@ -124,15 +124,20 @@ class TestIntEnumParser: def test_intenum_default(self) -> None: """Test default behaviour.""" - parser = IntEnumParser[BodyType]("name", 0, BodyType) - assert parser._parse(0x01) == BodyType.X01 - assert parser._parse(0x00) == BodyType.X00 - assert parser._parse(0x10) == BodyType.X00 - - parser = IntEnumParser[BodyType]("name", 0, BodyType, default_value=BodyType.A0) - assert parser._parse(0x01) == BodyType.X01 - assert parser._parse(0x00) == BodyType.X00 - assert parser._parse(0x10) == BodyType.A0 + parser = IntEnumParser[ListTypes]("name", 0, ListTypes) + assert parser._parse(0x01) == ListTypes.X01 + assert parser._parse(0x00) == ListTypes.X00 + assert parser._parse(0x10) == ListTypes.X10 + + parser = IntEnumParser[ListTypes]( + "name", + 0, + ListTypes, + default_value=ListTypes.A0, + ) + assert parser._parse(0x01) == ListTypes.X01 + assert parser._parse(0x00) == ListTypes.X00 + assert parser._parse(0xA0) == ListTypes.A0 class TestIntParser: @@ -169,7 +174,7 @@ def test_parse_all(self) -> None: body = MessageBody(data) body.parser_list.extend( [ - IntEnumParser("bt", 0, BodyType), + IntEnumParser("bt", 0, ListTypes), BoolParser("power", 1), BoolParser("feature_1", 2, 0), BoolParser("feature_2", 2, 1), @@ -178,7 +183,7 @@ def test_parse_all(self) -> None: ) body.parse_all() assert hasattr(body, "bt") is True - assert getattr(body, "bt", None) == BodyType.X00 + assert getattr(body, "bt", None) == ListTypes.X00 assert hasattr(body, "power") is True assert getattr(body, "power", False) is True assert hasattr(body, "feature_1") is True