Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

fix blocking call in event loop, and add dev/test tooling #9

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Config
config/

#Sensitive files
sensitive/

Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "scripts/run.sh",
"problemMatcher": []
}
]
}
5 changes: 3 additions & 2 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions custom_components/midea_ac_lan/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
16 changes: 12 additions & 4 deletions custom_components/midea_ac_lan/midea/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
homeassistant==2024.5.1
pycryptodome==3.20.0
20 changes: 20 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -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 <root>/custom_components/vaillant_vsmart
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

# Start Home Assistant
hass --config "${PWD}/config" --debug
7 changes: 7 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

python3 -m pip install --requirement requirements.txt