From 8abfeaf3fe7efeaa16990e8c96ac078bea44d2b9 Mon Sep 17 00:00:00 2001 From: Attila Ersek Date: Mon, 6 May 2024 18:31:57 +0200 Subject: [PATCH 1/3] fix: refactor blocking import_module call --- custom_components/midea_ac_lan/__init__.py | 5 +++-- .../midea_ac_lan/midea/devices/__init__.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/custom_components/midea_ac_lan/__init__.py b/custom_components/midea_ac_lan/__init__.py index 4ee8c147..330f5e15 100644 --- a/custom_components/midea_ac_lan/__init__.py +++ b/custom_components/midea_ac_lan/__init__.py @@ -27,7 +27,7 @@ CONF_TYPE, CONF_CUSTOMIZE, ) -from .midea.devices import device_selector +from .midea.devices import async_device_selector _LOGGER = logging.getLogger(__name__) @@ -145,7 +145,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry): if protocol == 3 and (key is None or key is None): _LOGGER.error("For V3 devices, the key and the token is required.") return False - device = device_selector( + device = await async_device_selector( + hass=hass, name=name, device_id=device_id, device_type=device_type, diff --git a/custom_components/midea_ac_lan/midea/devices/__init__.py b/custom_components/midea_ac_lan/midea/devices/__init__.py index 43a7b94c..a8700311 100644 --- a/custom_components/midea_ac_lan/midea/devices/__init__.py +++ b/custom_components/midea_ac_lan/midea/devices/__init__.py @@ -1,7 +1,9 @@ +from homeassistant.core import HomeAssistant from importlib import import_module +from types import ModuleType - -def device_selector( +async def async_device_selector( + hass: HomeAssistant, name: str, device_id: int, device_type: int, @@ -20,8 +22,14 @@ def device_selector( device_path = f".{'x%02x' % device_type}.device" else: device_path = f".{'%02x' % device_type}.device" - module = import_module(device_path, __package__) - device = module.MideaAppliance( + + modules: list[ModuleType] = [] + def _load_device_module() -> None: + """Load all service modules.""" + modules.append(import_module(device_path, __package__)) + await hass.async_add_import_executor_job(_load_device_module) + + device = modules[0].MideaAppliance( name=name, device_id=device_id, ip_address=ip_address, From 1d3578e8f960d99622ba3e6218a7318877f79a4e Mon Sep 17 00:00:00 2001 From: Attila Ersek Date: Mon, 6 May 2024 18:34:10 +0200 Subject: [PATCH 2/3] chore: vscode devcontainer configuration for development and testing --- .devcontainer/devcontainer.json | 40 +++++++++++++++++++++++++++++++++ .gitignore | 3 +++ .vscode/settings.json | 7 ++++++ .vscode/tasks.json | 11 +++++++++ requirements.txt | 2 ++ scripts/run.sh | 20 +++++++++++++++++ scripts/setup.sh | 7 ++++++ 7 files changed, 90 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 requirements.txt create mode 100755 scripts/run.sh create mode 100755 scripts/setup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..bdb4191a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "midea_ac_lan", + "image": "mcr.microsoft.com/devcontainers/python:3.12-bullseye", + "postCreateCommand": "scripts/setup.sh", + "forwardPorts": [ + 8123 + ], + "portsAttributes": { + "8123": { + "label": "Home Assistant", + "onAutoForward": "notify" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ryanluker.vscode-coverage-gutters", + "ms-python.vscode-pylance" + ], + "settings": { + "files.eol": "\n", + "editor.tabSize": 4, + "python.pythonPath": "/usr/bin/python3", + "python.analysis.autoSearchPaths": false, + "python.formatting.provider": "black", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true + } + } + }, + "remoteUser": "vscode", + "features": { + "ghcr.io/devcontainers/features/python:1": { + "version": "3.12" + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5241b7e1..d55e7881 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +#Config +config/ + #Sensitive files sensitive/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..9b388533 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..75eb3c53 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run Home Assistant on port 8123", + "type": "shell", + "command": "scripts/run.sh", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..73256096 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +homeassistant==2024.5.1 +pycryptodome==3.20.0 \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 00000000..1c529a66 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +# Create config dir if not present +if [[ ! -d "${PWD}/config" ]]; then + mkdir -p "${PWD}/config" + hass --config "${PWD}/config" --script ensure_config +fi + +# Set the path to custom_components +## This let's us have the structure we want /custom_components/vaillant_vsmart +## while at the same time have Home Assistant configuration inside /config +## without resulting to symlinks. +export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components" + +# Start Home Assistant +hass --config "${PWD}/config" --debug diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 00000000..141d19f9 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +python3 -m pip install --requirement requirements.txt From feb87b4e399a35c5e308aa58cb2f1e71a176c567 Mon Sep 17 00:00:00 2001 From: Attila Ersek Date: Mon, 6 May 2024 18:34:50 +0200 Subject: [PATCH 3/3] feat: bump versions and change owner to @CyrielRct --- custom_components/midea_ac_lan/manifest.json | 14 +++++++++----- hacs.json | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/midea_ac_lan/manifest.json b/custom_components/midea_ac_lan/manifest.json index bb693c0f..eb8566a1 100644 --- a/custom_components/midea_ac_lan/manifest.json +++ b/custom_components/midea_ac_lan/manifest.json @@ -1,13 +1,17 @@ { "domain": "midea_ac_lan", "name": "Midea AC LAN", - "codeowners": ["@georgezhao2010"], + "codeowners": [ + "@CyrielRct" + ], "config_flow": true, "dependencies": [], - "documentation": "https://github.com/georgezhao2010/midea_ac_lan#readme", + "documentation": "https://github.com/CyrielRct/midea_ac_lan#readme", "integration_type": "device", "iot_class": "local_push", - "issue_tracker": "https://github.com/georgezhao2010/midea_ac_lan/issues", - "requirements": [], - "version": "v0.3.22" + "issue_tracker": "https://github.com/CyrielRct/midea_ac_lan/issues", + "requirements": [ + "pycryptodome" + ], + "version": "v0.3.23" } \ No newline at end of file diff --git a/hacs.json b/hacs.json index 0806be08..59afaea5 100644 --- a/hacs.json +++ b/hacs.json @@ -1,7 +1,7 @@ { "name": "Midea AC LAN", "render_readme": true, - "homeassistant": "2023.1", + "homeassistant": "2024.5", "zip_release": true, "filename": "midea_ac_lan.zip" -} +} \ No newline at end of file