diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6060c954..2e3b3a18 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -44,5 +44,5 @@ }, "remoteUser": "root", "containerUser": "vscode", - "postAttachCommand": "pip3 install --user -r requirements.txt" + "postAttachCommand": ["pip3 install --user -r requirements.txt"] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..6f115313 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Install requirements.txt", + "type": "shell", + "command": "pip3 install --user -r requirements.txt", + "problemMatcher": [] + }, + { + "label": "Build and install midealocal lib", + "type": "shell", + "command": "python3 -m build && pip3 install dist/midea_local*.whl", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/src/__init__.py b/midealocal/__init__.py similarity index 100% rename from src/__init__.py rename to midealocal/__init__.py diff --git a/src/backports/enum.py b/midealocal/backports/enum.py similarity index 100% rename from src/backports/enum.py rename to midealocal/backports/enum.py diff --git a/src/cloud.py b/midealocal/cloud.py similarity index 100% rename from src/cloud.py rename to midealocal/cloud.py diff --git a/src/crc8.py b/midealocal/crc8.py similarity index 100% rename from src/crc8.py rename to midealocal/crc8.py diff --git a/src/device.py b/midealocal/device.py similarity index 100% rename from src/device.py rename to midealocal/device.py diff --git a/src/devices/__init__.py b/midealocal/devices/__init__.py similarity index 100% rename from src/devices/__init__.py rename to midealocal/devices/__init__.py diff --git a/src/devices/a1/device.py b/midealocal/devices/a1/device.py similarity index 100% rename from src/devices/a1/device.py rename to midealocal/devices/a1/device.py diff --git a/src/devices/a1/message.py b/midealocal/devices/a1/message.py similarity index 100% rename from src/devices/a1/message.py rename to midealocal/devices/a1/message.py diff --git a/src/devices/ac/device.py b/midealocal/devices/ac/device.py similarity index 100% rename from src/devices/ac/device.py rename to midealocal/devices/ac/device.py diff --git a/src/devices/ac/message.py b/midealocal/devices/ac/message.py similarity index 100% rename from src/devices/ac/message.py rename to midealocal/devices/ac/message.py diff --git a/src/devices/b0/device.py b/midealocal/devices/b0/device.py similarity index 100% rename from src/devices/b0/device.py rename to midealocal/devices/b0/device.py diff --git a/src/devices/b0/message.py b/midealocal/devices/b0/message.py similarity index 100% rename from src/devices/b0/message.py rename to midealocal/devices/b0/message.py diff --git a/src/devices/b1/device.py b/midealocal/devices/b1/device.py similarity index 100% rename from src/devices/b1/device.py rename to midealocal/devices/b1/device.py diff --git a/src/devices/b1/message.py b/midealocal/devices/b1/message.py similarity index 100% rename from src/devices/b1/message.py rename to midealocal/devices/b1/message.py diff --git a/src/devices/b3/device.py b/midealocal/devices/b3/device.py similarity index 100% rename from src/devices/b3/device.py rename to midealocal/devices/b3/device.py diff --git a/src/devices/b3/message.py b/midealocal/devices/b3/message.py similarity index 100% rename from src/devices/b3/message.py rename to midealocal/devices/b3/message.py diff --git a/src/devices/b4/device.py b/midealocal/devices/b4/device.py similarity index 100% rename from src/devices/b4/device.py rename to midealocal/devices/b4/device.py diff --git a/src/devices/b4/message.py b/midealocal/devices/b4/message.py similarity index 100% rename from src/devices/b4/message.py rename to midealocal/devices/b4/message.py diff --git a/src/devices/b6/device.py b/midealocal/devices/b6/device.py similarity index 100% rename from src/devices/b6/device.py rename to midealocal/devices/b6/device.py diff --git a/src/devices/b6/message.py b/midealocal/devices/b6/message.py similarity index 100% rename from src/devices/b6/message.py rename to midealocal/devices/b6/message.py diff --git a/src/devices/bf/device.py b/midealocal/devices/bf/device.py similarity index 100% rename from src/devices/bf/device.py rename to midealocal/devices/bf/device.py diff --git a/src/devices/bf/message.py b/midealocal/devices/bf/message.py similarity index 100% rename from src/devices/bf/message.py rename to midealocal/devices/bf/message.py diff --git a/src/devices/c2/device.py b/midealocal/devices/c2/device.py similarity index 100% rename from src/devices/c2/device.py rename to midealocal/devices/c2/device.py diff --git a/src/devices/c2/message.py b/midealocal/devices/c2/message.py similarity index 100% rename from src/devices/c2/message.py rename to midealocal/devices/c2/message.py diff --git a/src/devices/c3/device.py b/midealocal/devices/c3/device.py similarity index 100% rename from src/devices/c3/device.py rename to midealocal/devices/c3/device.py diff --git a/src/devices/c3/message.py b/midealocal/devices/c3/message.py similarity index 100% rename from src/devices/c3/message.py rename to midealocal/devices/c3/message.py diff --git a/src/devices/ca/device.py b/midealocal/devices/ca/device.py similarity index 100% rename from src/devices/ca/device.py rename to midealocal/devices/ca/device.py diff --git a/src/devices/ca/message.py b/midealocal/devices/ca/message.py similarity index 100% rename from src/devices/ca/message.py rename to midealocal/devices/ca/message.py diff --git a/src/devices/cc/device.py b/midealocal/devices/cc/device.py similarity index 100% rename from src/devices/cc/device.py rename to midealocal/devices/cc/device.py diff --git a/src/devices/cc/message.py b/midealocal/devices/cc/message.py similarity index 100% rename from src/devices/cc/message.py rename to midealocal/devices/cc/message.py diff --git a/src/devices/cd/device.py b/midealocal/devices/cd/device.py similarity index 100% rename from src/devices/cd/device.py rename to midealocal/devices/cd/device.py diff --git a/src/devices/cd/message.py b/midealocal/devices/cd/message.py similarity index 100% rename from src/devices/cd/message.py rename to midealocal/devices/cd/message.py diff --git a/src/devices/ce/device.py b/midealocal/devices/ce/device.py similarity index 100% rename from src/devices/ce/device.py rename to midealocal/devices/ce/device.py diff --git a/src/devices/ce/message.py b/midealocal/devices/ce/message.py similarity index 100% rename from src/devices/ce/message.py rename to midealocal/devices/ce/message.py diff --git a/src/devices/cf/device.py b/midealocal/devices/cf/device.py similarity index 100% rename from src/devices/cf/device.py rename to midealocal/devices/cf/device.py diff --git a/src/devices/cf/message.py b/midealocal/devices/cf/message.py similarity index 100% rename from src/devices/cf/message.py rename to midealocal/devices/cf/message.py diff --git a/src/devices/da/device.py b/midealocal/devices/da/device.py similarity index 100% rename from src/devices/da/device.py rename to midealocal/devices/da/device.py diff --git a/src/devices/da/message.py b/midealocal/devices/da/message.py similarity index 100% rename from src/devices/da/message.py rename to midealocal/devices/da/message.py diff --git a/src/devices/db/device.py b/midealocal/devices/db/device.py similarity index 100% rename from src/devices/db/device.py rename to midealocal/devices/db/device.py diff --git a/src/devices/db/message.py b/midealocal/devices/db/message.py similarity index 100% rename from src/devices/db/message.py rename to midealocal/devices/db/message.py diff --git a/src/devices/dc/device.py b/midealocal/devices/dc/device.py similarity index 100% rename from src/devices/dc/device.py rename to midealocal/devices/dc/device.py diff --git a/src/devices/dc/message.py b/midealocal/devices/dc/message.py similarity index 100% rename from src/devices/dc/message.py rename to midealocal/devices/dc/message.py diff --git a/src/devices/e1/device.py b/midealocal/devices/e1/device.py similarity index 100% rename from src/devices/e1/device.py rename to midealocal/devices/e1/device.py diff --git a/src/devices/e1/message.py b/midealocal/devices/e1/message.py similarity index 100% rename from src/devices/e1/message.py rename to midealocal/devices/e1/message.py diff --git a/src/devices/e2/device.py b/midealocal/devices/e2/device.py similarity index 100% rename from src/devices/e2/device.py rename to midealocal/devices/e2/device.py diff --git a/src/devices/e2/message.py b/midealocal/devices/e2/message.py similarity index 100% rename from src/devices/e2/message.py rename to midealocal/devices/e2/message.py diff --git a/src/devices/e3/device.py b/midealocal/devices/e3/device.py similarity index 100% rename from src/devices/e3/device.py rename to midealocal/devices/e3/device.py diff --git a/src/devices/e3/message.py b/midealocal/devices/e3/message.py similarity index 100% rename from src/devices/e3/message.py rename to midealocal/devices/e3/message.py diff --git a/src/devices/e6/device.py b/midealocal/devices/e6/device.py similarity index 100% rename from src/devices/e6/device.py rename to midealocal/devices/e6/device.py diff --git a/src/devices/e6/message.py b/midealocal/devices/e6/message.py similarity index 100% rename from src/devices/e6/message.py rename to midealocal/devices/e6/message.py diff --git a/src/devices/e8/device.py b/midealocal/devices/e8/device.py similarity index 100% rename from src/devices/e8/device.py rename to midealocal/devices/e8/device.py diff --git a/src/devices/e8/message.py b/midealocal/devices/e8/message.py similarity index 100% rename from src/devices/e8/message.py rename to midealocal/devices/e8/message.py diff --git a/src/devices/ea/device.py b/midealocal/devices/ea/device.py similarity index 100% rename from src/devices/ea/device.py rename to midealocal/devices/ea/device.py diff --git a/src/devices/ea/message.py b/midealocal/devices/ea/message.py similarity index 100% rename from src/devices/ea/message.py rename to midealocal/devices/ea/message.py diff --git a/src/devices/ec/device.py b/midealocal/devices/ec/device.py similarity index 100% rename from src/devices/ec/device.py rename to midealocal/devices/ec/device.py diff --git a/src/devices/ec/message.py b/midealocal/devices/ec/message.py similarity index 100% rename from src/devices/ec/message.py rename to midealocal/devices/ec/message.py diff --git a/src/devices/ed/device.py b/midealocal/devices/ed/device.py similarity index 100% rename from src/devices/ed/device.py rename to midealocal/devices/ed/device.py diff --git a/src/devices/ed/message.py b/midealocal/devices/ed/message.py similarity index 100% rename from src/devices/ed/message.py rename to midealocal/devices/ed/message.py diff --git a/src/devices/fa/device.py b/midealocal/devices/fa/device.py similarity index 100% rename from src/devices/fa/device.py rename to midealocal/devices/fa/device.py diff --git a/src/devices/fa/message.py b/midealocal/devices/fa/message.py similarity index 100% rename from src/devices/fa/message.py rename to midealocal/devices/fa/message.py diff --git a/src/devices/fb/device.py b/midealocal/devices/fb/device.py similarity index 100% rename from src/devices/fb/device.py rename to midealocal/devices/fb/device.py diff --git a/src/devices/fb/message.py b/midealocal/devices/fb/message.py similarity index 100% rename from src/devices/fb/message.py rename to midealocal/devices/fb/message.py diff --git a/src/devices/fc/device.py b/midealocal/devices/fc/device.py similarity index 100% rename from src/devices/fc/device.py rename to midealocal/devices/fc/device.py diff --git a/src/devices/fc/message.py b/midealocal/devices/fc/message.py similarity index 100% rename from src/devices/fc/message.py rename to midealocal/devices/fc/message.py diff --git a/src/devices/fd/device.py b/midealocal/devices/fd/device.py similarity index 100% rename from src/devices/fd/device.py rename to midealocal/devices/fd/device.py diff --git a/src/devices/fd/message.py b/midealocal/devices/fd/message.py similarity index 100% rename from src/devices/fd/message.py rename to midealocal/devices/fd/message.py diff --git a/src/devices/x13/device.py b/midealocal/devices/x13/device.py similarity index 100% rename from src/devices/x13/device.py rename to midealocal/devices/x13/device.py diff --git a/src/devices/x13/message.py b/midealocal/devices/x13/message.py similarity index 100% rename from src/devices/x13/message.py rename to midealocal/devices/x13/message.py diff --git a/src/devices/x26/device.py b/midealocal/devices/x26/device.py similarity index 100% rename from src/devices/x26/device.py rename to midealocal/devices/x26/device.py diff --git a/src/devices/x26/message.py b/midealocal/devices/x26/message.py similarity index 100% rename from src/devices/x26/message.py rename to midealocal/devices/x26/message.py diff --git a/src/devices/x34/device.py b/midealocal/devices/x34/device.py similarity index 100% rename from src/devices/x34/device.py rename to midealocal/devices/x34/device.py diff --git a/src/devices/x34/message.py b/midealocal/devices/x34/message.py similarity index 100% rename from src/devices/x34/message.py rename to midealocal/devices/x34/message.py diff --git a/src/devices/x40/device.py b/midealocal/devices/x40/device.py similarity index 100% rename from src/devices/x40/device.py rename to midealocal/devices/x40/device.py diff --git a/src/devices/x40/message.py b/midealocal/devices/x40/message.py similarity index 100% rename from src/devices/x40/message.py rename to midealocal/devices/x40/message.py diff --git a/src/discover.py b/midealocal/discover.py similarity index 100% rename from src/discover.py rename to midealocal/discover.py diff --git a/src/message.py b/midealocal/message.py similarity index 100% rename from src/message.py rename to midealocal/message.py diff --git a/src/packet_builder.py b/midealocal/packet_builder.py similarity index 100% rename from src/packet_builder.py rename to midealocal/packet_builder.py diff --git a/src/security.py b/midealocal/security.py similarity index 100% rename from src/security.py rename to midealocal/security.py diff --git a/requirements.txt b/requirements.txt index e6d16ed6..d36fbd50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ pytest ruff aiohttp ifaddr -pycryptodome \ No newline at end of file +pycryptodome +build \ No newline at end of file diff --git a/setup.py b/setup.py index 8563b7f4..a553b861 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,9 @@ long_description_content_type="text/markdown", url="https://github.com/rokam/midea-local", install_requires=requires, - packages=setuptools.find_packages(exclude=["tests", "tests.*"]), + packages=setuptools.find_packages( + include=["midealocal", "midealocal.*"], exclude=["tests", "tests.*"] + ), python_requires=">=3.10", classifiers=[ "Programming Language :: Python :: 3", diff --git a/tests/crc8_test.py b/tests/crc8_test.py new file mode 100644 index 00000000..2e969033 --- /dev/null +++ b/tests/crc8_test.py @@ -0,0 +1,60 @@ +"""CRC8 Test""" + +from midealocal.crc8 import calculate + + +def test_calculate() -> None: + """Test calculate method.""" + data: bytearray = bytearray( + [ + # 2 bytes - StaicHeader + 0x5A, + 0x5A, + # 2 bytes - mMessageType + 0x01, + 0x11, + # 2 bytes - PacketLenght + 0x00, + 0x00, + # 2 bytes + 0x20, + 0x00, + # 4 bytes - MessageId + 0x00, + 0x00, + 0x00, + 0x00, + # 8 bytes - Date&Time + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + # 6 bytes - mDeviceID + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + # 12 bytes + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ] + ) + assert calculate(data) == 86