Skip to content

Commit

Permalink
update with superlinter error
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed May 14, 2024
1 parent f51e66e commit 569e370
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/linters/.python-lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[FORMAT]
max-line-length=500
[MESSAGES CONTROL]
disable=import-error, logging-fstring-interpolation
disable=import-error, logging-fstring-interpolation, missing-class-docstring
33 changes: 16 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,28 @@ jobs:
clean: true
- name: Zip release file
run: |
apt update && apt install zip || exit 1
echo 'show runner hostname'
apt-get update && apt-get install zip || exit 1
echo "show runner hostname"
hostname
echo 'show runner user'
echo "show runner user"
whoami
echo 'show runner pwd'
echo "show runner pwd"
pwd
echo 'show runner kernel'
echo "show runner kernel"
uname -a
echo 'show runner pwd file list'
echo "show runner pwd file list"
ls
ls -alht "custom_components/midea_ac_lan/" || exit 1
echo 'show manifest.json for debug'
echo "show manifest.json for debug"
cat "custom_components/midea_ac_lan/manifest.json" || exit 1
dst_dir="/github/workspace/artifacts"
sudo mkdir -p "$dst_dir" || exit 1
sudo chown -R $(id -u):$(id -g) "$dst_dir" || exit 1
sudo chmod -R 755 "$dst_dir" || exit 1
cd "custom_components/midea_ac_lan/" || exit 1
zip -r ../midea_ac_lan.zip ./* || exit 1
cp ../midea_ac_lan.zip "$dst_dir/midea_ac_lan.zip" || exit 1
zip -r "../midea_ac_lan.zip" "./*" || exit 1
cp "../midea_ac_lan.zip" "$dst_dir/midea_ac_lan.zip" || exit 1
ls -alht "$dst_dir" || exit 1
shell: bash
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -71,20 +70,20 @@ jobs:

- name: Show Working Directory For Debug Purpose
run: |
echo 'show runner hostname'
echo "show runner hostname"
hostname
echo 'show runner user'
echo "show runner user"
whoami
echo 'show runner disk usage'
echo "show runner disk usage"
df -h
echo 'show runner pwd'
echo "show runner pwd"
pwd
echo 'show runner kernel'
echo "show runner kernel"
uname -a
echo 'show runner pwd file list'
echo "show runner pwd file list"
ls
ls -alht
echo 'show runner artifacts'
echo "show runner artifacts"
ls -alht artifacts || exit 0
echo "github.ref: ${{github.ref}}"
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[![Stable](https://img.shields.io/github/v/release/CyrielRct/midea_ac_lan)](https://github.com/CyrielRct/midea_ac_lan/releases/latest)
[![Super-Linter](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE_NAME>/badge.svg)](https://github.com/marketplace/actions/super-linter)

> :warning: **This is a fork of midea_ac_lan done by Georgezhao**: As the project is in a vegetative state we have done a fork and merged some pending fixes.
I'm trying to get in touch with the maintainer at the moment to find a solution, and at the same time we're looking for people available to maintain the project, which is actively used by the community. please contact me if you can help !
> :warning: **This is a fork of midea_ac_lan done by Georgezhao**
English | [简体中文](README_hans.md)

Expand Down Expand Up @@ -76,9 +75,23 @@ And more.

## Installation

Search 'Midea AC LAN' in HACS and install, or copy all files in `custom_components/midea_ac_lan` from [Latest Release](https://github.com/georgezhao2010/midea_ac_lan/releases/latest) to your `/custom_components/midea_ac_lan` in Home Assistant manually.
**Search `Midea AC LAN` in HACS not available now, it will be ready later**

Restart Home Assistant.
Please use manual install as below:

Option 1:

1. make sure you have installed HACS to Home Assistant [HACS install guide](https://hacs.xyz/docs/setup/download)
2. open HACS, click [Custom repositories], Repository input: `https://github.com/wuwentao/midea_ac_lan`, Category select [Integration]
3. **Restart Home Assistant**.

Option 2:

1. Download `midea_ac_lan.zip` from [Latest Release](https://github.com/wuwentao/midea_ac_lan/releases/latest)
2. copy `midea_ac_lan.zip` to `/custom_components/midea_ac_lan` in Home Assistant.
3. **Restart Home Assistant**.

Once it done, open `[Settings]`, `[Device & services]`, `[Integrations]`, `[Midea AC Lan]`, do init config and add all your devices.

## Add device

Expand Down
18 changes: 16 additions & 2 deletions README_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,23 @@

## 安装

在HACS中搜索'Midea AC LAN'并安装, 或者从[Latest release](https://github.com/georgezhao2010/midea_ac_lan/releases/latest)下载最新的Release版本, 将其中的`custom_components/midea_ac_lan`放到你的Home Assistant的`custom_components/midea_ac_lan`
**在HACS中搜索'Midea AC LAN'并安装的方式当前还不可用**,请耐心等待HACS审核和处理流程

重启Home Assistant
请先使用以下二种方式手工安装:

方式1:

1. 确保Home Assistant中已安装HACS [HACS install docs](https://hacs.xyz/docs/setup/download)
2. 打开HACS, 点击[Custom repositories], Repository 输入: `https://github.com/wuwentao/midea_ac_lan`, Category 选择 [Integration]
3. **重启Home Assistant**.

方式2:

1. Download midea_ac_lan.zip from [Latest Release](https://github.com/wuwentao/midea_ac_lan/releases/latest)
2. copy midea_ac_lan.zip to `/custom_components/midea_ac_lan` in Home Assistant.
3. **Restart Home Assistant**.

Once it done, open [Settings], [Device & services], [Integrations], [Midea AC Lan], do init config and add all your devices.

## 添加设备

Expand Down
17 changes: 9 additions & 8 deletions custom_components/midea_ac_lan/climate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
climate.py
"""
import logging

from homeassistant.components.climate import (
Expand Down Expand Up @@ -357,16 +360,15 @@ def fan_mode(self) -> str:
fan_speed = self._device.get_attribute(ACAttributes.fan_speed)
if fan_speed > 100:
return FAN_AUTO.capitalize()
elif fan_speed > 80:
if fan_speed > 80:
return FAN_FULL_SPEED.capitalize()
elif fan_speed > 60:
if fan_speed > 60:
return FAN_HIGH.capitalize()
elif fan_speed > 40:
if fan_speed > 40:
return FAN_MEDIUM.capitalize()
elif fan_speed > 20:
if fan_speed > 20:
return FAN_LOW.capitalize()
else:
return FAN_SILENT.capitalize()
return FAN_SILENT.capitalize()

@property
def target_temperature_step(self):
Expand Down Expand Up @@ -635,8 +637,7 @@ def hvac_mode(self) -> str:
"""
if self._device.get_attribute(self._power_attr):
return self._modes[self._device.get_attribute(C3Attributes.mode)]
else:
return HVACMode.OFF
return HVACMode.OFF

@property
def target_temperature(self):
Expand Down
141 changes: 67 additions & 74 deletions custom_components/midea_ac_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import logging

import voluptuous as vol

Expand All @@ -11,8 +12,6 @@
except ImportError:
from homeassistant.util.json import save_json

import logging

import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries
from homeassistant.const import (
Expand Down Expand Up @@ -177,11 +176,10 @@ async def async_step_user(self, user_input=None, error=None):
if user_input is not None:
if user_input["action"] == "discovery":
return await self.async_step_discovery()
elif user_input["action"] == "manually":
if user_input["action"] == "manually":
self.found_device = {}
return await self.async_step_manually()
else:
return await self.async_step_list()
return await self.async_step_list()
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
Expand Down Expand Up @@ -212,8 +210,7 @@ async def async_step_login(self, user_input=None, error=None):
}
self._save_account(self.account)
return await self.async_step_auto()
else:
return await self.async_step_login(error="login_failed")
return await self.async_step_login(error="login_failed")
return self.async_show_form(
step_id="login",
data_schema=vol.Schema(
Expand Down Expand Up @@ -268,8 +265,7 @@ async def async_step_discovery(self, user_input=None, error=None):
)
if len(self.available_device) > 0:
return await self.async_step_auto()
else:
return await self.async_step_discovery(error="no_devices")
return await self.async_step_discovery(error="no_devices")
return self.async_show_form(
step_id="discovery",
data_schema=vol.Schema(
Expand Down Expand Up @@ -303,73 +299,71 @@ async def async_step_auto(self, user_input=None, error=None):
f"Loaded configuration for device {device_id} from storage"
)
return await self.async_step_manually()
else:
if CONF_ACCOUNT not in self.account.keys():
self.account = self._load_account()
if CONF_ACCOUNT not in self.account.keys():
self.account = self._load_account()
if CONF_ACCOUNT not in self.account.keys():
return await self.async_step_login()
if self.session is None:
self.session = async_create_clientsession(self.hass)
if self.cloud is None:
return await self.async_step_login()
if self.session is None:
self.session = async_create_clientsession(self.hass)
if self.cloud is None:
self.cloud = get_midea_cloud(
self.account[CONF_SERVER],
self.session,
self.account[CONF_ACCOUNT],
self.account[CONF_PASSWORD],
)
if not await self.cloud.login():
return await self.async_step_login()
self.found_device = {
CONF_DEVICE_ID: device_id,
CONF_TYPE: device.get(CONF_TYPE),
CONF_PROTOCOL: device.get(CONF_PROTOCOL),
CONF_IP_ADDRESS: device.get(CONF_IP_ADDRESS),
CONF_PORT: device.get(CONF_PORT),
CONF_MODEL: device.get(CONF_MODEL),
}
if device_info := await self.cloud.get_device_info(device_id):
self.found_device[CONF_NAME] = device_info.get("name")
self.found_device[CONF_SUBTYPE] = device_info.get("model_number")
if device.get(CONF_PROTOCOL) == 3:
if self.account[CONF_SERVER] == "美的美居":
_LOGGER.debug(
"Try to get the Token and the Key use the preset MSmartHome account"
)
self.cloud = get_midea_cloud(
self.account[CONF_SERVER],
"MSmartHome",
self.session,
self.account[CONF_ACCOUNT],
self.account[CONF_PASSWORD],
bytes.fromhex(
format((PRESET_ACCOUNT[0] ^ PRESET_ACCOUNT[1]), "X")
).decode("ASCII"),
bytes.fromhex(
format((PRESET_ACCOUNT[0] ^ PRESET_ACCOUNT[2]), "X")
).decode("ASCII"),
)
if not await self.cloud.login():
return await self.async_step_login()
self.found_device = {
CONF_DEVICE_ID: device_id,
CONF_TYPE: device.get(CONF_TYPE),
CONF_PROTOCOL: device.get(CONF_PROTOCOL),
CONF_IP_ADDRESS: device.get(CONF_IP_ADDRESS),
CONF_PORT: device.get(CONF_PORT),
CONF_MODEL: device.get(CONF_MODEL),
}
if device_info := await self.cloud.get_device_info(device_id):
self.found_device[CONF_NAME] = device_info.get("name")
self.found_device[CONF_SUBTYPE] = device_info.get("model_number")
if device.get(CONF_PROTOCOL) == 3:
if self.account[CONF_SERVER] == "美的美居":
_LOGGER.debug(
"Try to get the Token and the Key use the preset MSmartHome account"
)
self.cloud = get_midea_cloud(
"MSmartHome",
self.session,
bytes.fromhex(
format((PRESET_ACCOUNT[0] ^ PRESET_ACCOUNT[1]), "X")
).decode("ASCII"),
bytes.fromhex(
format((PRESET_ACCOUNT[0] ^ PRESET_ACCOUNT[2]), "X")
).decode("ASCII"),
)
if not await self.cloud.login():
return await self.async_step_auto(error="preset_account")
keys = await self.cloud.get_keys(user_input[CONF_DEVICE])
for method, key in keys.items():
dm = MiedaDevice(
name="",
device_id=device_id,
device_type=device.get(CONF_TYPE),
ip_address=device.get(CONF_IP_ADDRESS),
port=device.get(CONF_PORT),
token=key["token"],
key=key["key"],
protocol=3,
model=device.get(CONF_MODEL),
subtype=0,
attributes={},
)
if dm.connect(refresh_status=False):
dm.close_socket()
self.found_device[CONF_TOKEN] = key["token"]
self.found_device[CONF_KEY] = key["key"]
return await self.async_step_manually()
return await self.async_step_auto(error="connect_error")
else:
return await self.async_step_manually()
if not await self.cloud.login():
return await self.async_step_auto(error="preset_account")
keys = await self.cloud.get_keys(user_input[CONF_DEVICE])
for method, key in keys.items():
dm = MiedaDevice(
name="",
device_id=device_id,
device_type=device.get(CONF_TYPE),
ip_address=device.get(CONF_IP_ADDRESS),
port=device.get(CONF_PORT),
token=key["token"],
key=key["key"],
protocol=3,
model=device.get(CONF_MODEL),
subtype=0,
attributes={},
)
if dm.connect(refresh_status=False):
dm.close_socket()
self.found_device[CONF_TOKEN] = key["token"]
self.found_device[CONF_KEY] = key["key"]
return await self.async_step_manually()
return await self.async_step_auto(error="connect_error")
return await self.async_step_manually()

return self.async_show_form(
step_id="auto",
Expand Down Expand Up @@ -438,8 +432,7 @@ async def async_step_manually(self, user_input=None, error=None):
return self.async_create_entry(
title=f"{user_input[CONF_NAME]}", data=data
)
else:
return await self.async_step_manually(error="config_incorrect")
return await self.async_step_manually(error="config_incorrect")
return self.async_show_form(
step_id="manually",
data_schema=vol.Schema(
Expand Down
3 changes: 3 additions & 0 deletions custom_components/midea_ac_lan/humidifier.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
humidifier.py
"""
import logging

from homeassistant.components.humidifier import (
Expand Down
Loading

0 comments on commit 569e370

Please sign in to comment.