Skip to content

Commit

Permalink
update based on super linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed May 14, 2024
1 parent 055ced0 commit a722dcb
Show file tree
Hide file tree
Showing 104 changed files with 5,187 additions and 3,208 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

6 changes: 4 additions & 2 deletions .github/ISSUE_TEMPLATE/2-issue_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ body:
attributes:
label: Device type and model
placeholder: Air Conditioner 22012225
description: Can be found in Settings -> Devices & Services -> Midea AC LAN -> Devices -> Device Info
description: Can be found in Settings -> Devices & Services -> \
Midea AC LAN -> Devices -> Device Info
- type: input
validations:
required: true
Expand All @@ -35,4 +36,5 @@ body:
- type: textarea
attributes:
label: The logs
description: Should enable the debug log of Midea AC LAN, and post or upload the log when the error occurs to here
description: Should enable the debug log of Midea AC LAN, and post or \
upload the log when the error occurs to here
3 changes: 3 additions & 0 deletions .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 500
extend-ignore = E203,E701
4 changes: 4 additions & 0 deletions .github/linters/.python-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[FORMAT]
max-line-length=500
[MESSAGES CONTROL]
disable=import-error, logging-fstring-interpolation
6 changes: 6 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 500
level: warning
14 changes: 7 additions & 7 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: "CodeQL"

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]
# schedule:
# - cron: "42 8 * * 6"

Expand All @@ -23,22 +23,22 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ python ]
language: [python]

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ jobs:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_GITLEAKS: false
VALIDATE_JSCPD: false
49 changes: 25 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@ jobs:
with:
fetch-depth: 0
clean: true

- name: Show Output Directory For Debug Purpose
- name: Zip release file
run: |
apt update && apt install zip || exit 1
echo "show runner hostname"
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"
cat custom_components/midea_ac_lan/manifest.json || exit 1
sudo mkdir -p /github/workspace/artifacts || exit 1
sudo chown -R $(id -u):$(id -g) /github/workspace/artifacts || exit 1
sudo chmod -R 755 /github/workspace/artifacts || exit 1
cd custom_components/midea_ac_lan/ || exit 1
ls -alht "custom_components/midea_ac_lan/" || exit 1
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 /github/workspace/artifacts/midea_ac_lan.zip || exit 1
ls -alht /github/workspace/artifacts/ || 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 @@ -72,20 +71,22 @@ 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 pwd"
echo 'show runner disk usage'
df -h
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}} "
echo "github.ref: ${{github.ref}}"
- name: Upload images to Release Asset
uses: softprops/action-gh-release@v2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name: HACS Validation
on:
pull_request:
push:
# schedule:
# - cron: "0 0 * * *"

Expand Down
115 changes: 74 additions & 41 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
"""
__init__.py
"""

import logging
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.const import (
CONF_CUSTOMIZE,
CONF_DEVICE_ID,
CONF_IP_ADDRESS,
CONF_NAME,
CONF_PORT,
CONF_PROTOCOL,
CONF_TOKEN,
CONF_TYPE,
)
from homeassistant.core import HomeAssistant

from .const import (
DOMAIN,
ALL_PLATFORM,
CONF_ACCOUNT,
CONF_KEY,
CONF_MODEL,
CONF_SUBTYPE,
CONF_REFRESH_INTERVAL,
CONF_SUBTYPE,
DEVICES,
DOMAIN,
EXTRA_SWITCH,
ALL_PLATFORM,
)
from .midea_devices import MIDEA_DEVICES

from homeassistant.core import HomeAssistant
from homeassistant.const import (
CONF_NAME,
CONF_TOKEN,
CONF_IP_ADDRESS,
CONF_PORT,
CONF_PROTOCOL,
CONF_DEVICE_ID,
CONF_TYPE,
CONF_CUSTOMIZE,
)
from .midea.devices import async_device_selector
from .midea_devices import MIDEA_DEVICES

_LOGGER = logging.getLogger(__name__)


async def update_listener(hass, config_entry):
"""
update_listener
"""
for platform in ALL_PLATFORM:
await hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in ALL_PLATFORM:
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
config_entry, platform))
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)
device_id = config_entry.data.get(CONF_DEVICE_ID)
customize = config_entry.options.get(
CONF_CUSTOMIZE, ""
)
ip_address = config_entry.options.get(
CONF_IP_ADDRESS, None
)
refresh_interval = config_entry.options.get(
CONF_REFRESH_INTERVAL, None
)
customize = config_entry.options.get(CONF_CUSTOMIZE, "")
ip_address = config_entry.options.get(CONF_IP_ADDRESS, None)
refresh_interval = config_entry.options.get(CONF_REFRESH_INTERVAL, None)
dev = hass.data[DOMAIN][DEVICES].get(device_id)
if dev:
dev.set_customize(customize)
Expand All @@ -55,15 +58,24 @@ async def update_listener(hass, config_entry):
dev.set_refresh_interval(refresh_interval)


async def async_setup(hass: HomeAssistant, hass_config: dict):
async def async_setup(hass: HomeAssistant):
"""
async_setup
"""
hass.data.setdefault(DOMAIN, {})
attributes = []
for device_entities in MIDEA_DEVICES.values():
for attribute_name, attribute in device_entities.get("entities").items():
if attribute.get("type") in EXTRA_SWITCH and attribute_name.value not in attributes:
if (
attribute.get("type") in EXTRA_SWITCH
and attribute_name.value not in attributes
):
attributes.append(attribute_name.value)

def service_set_attribute(service):
"""
service_set_attribute
"""
device_id = service.data.get("device_id")
attr = service.data.get("attribute")
value = service.data.get("value")
Expand All @@ -72,20 +84,34 @@ def service_set_attribute(service):
if attr == "fan_speed" and value == "auto":
value = 102
item = MIDEA_DEVICES.get(dev.device_type).get("entities").get(attr)
if (item and (item.get("type") in EXTRA_SWITCH) or
(dev.device_type == 0xAC and attr == "fan_speed" and value in range(0, 103))):
if (
item
and (item.get("type") in EXTRA_SWITCH)
or (
dev.device_type == 0xAC
and attr == "fan_speed"
and value in range(0, 103)
)
):
dev.set_attribute(attr=attr, value=value)
else:
_LOGGER.error(f"Appliance [{device_id}] has no attribute {attr} or value is invalid")
_LOGGER.error(
f"Appliance [{device_id}] has no attribute {attr} or value is invalid"
)

def service_send_command(service):
"""
service_send_command
"""
device_id = service.data.get("device_id")
cmd_type = service.data.get("cmd_type")
cmd_body = service.data.get("cmd_body")
try:
cmd_body = bytearray.fromhex(cmd_body)
except ValueError:
_LOGGER.error(f"Appliance [{device_id}] invalid cmd_body, a hexadecimal string required")
_LOGGER.error(
f"Appliance [{device_id}] invalid cmd_body, a hexadecimal string required"
)
return
dev = hass.data[DOMAIN][DEVICES].get(device_id)
if dev:
Expand All @@ -99,9 +125,9 @@ def service_send_command(service):
{
vol.Required("device_id"): vol.Coerce(int),
vol.Required("attribute"): vol.In(attributes),
vol.Required("value"): vol.Any(int, cv.boolean, str)
vol.Required("value"): vol.Any(int, cv.boolean, str),
}
)
),
)

hass.services.async_register(
Expand All @@ -112,14 +138,17 @@ def service_send_command(service):
{
vol.Required("device_id"): vol.Coerce(int),
vol.Required("cmd_type"): vol.In([2, 3]),
vol.Required("cmd_body"): str
vol.Required("cmd_body"): str,
}
)
),
)
return True


async def async_setup_entry(hass: HomeAssistant, config_entry):
"""
async_setup_entry
"""
device_type = config_entry.data.get(CONF_TYPE)
if device_type == CONF_ACCOUNT:
return True
Expand All @@ -128,7 +157,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):
if name is None:
name = f"{device_id}"
if device_type is None:
device_type = 0xac
device_type = 0xAC
token = config_entry.data.get(CONF_TOKEN)
key = config_entry.data.get(CONF_KEY)
ip_address = config_entry.options.get(CONF_IP_ADDRESS, None)
Expand Down Expand Up @@ -167,14 +196,18 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):
hass.data[DOMAIN][DEVICES] = {}
hass.data[DOMAIN][DEVICES][device_id] = device
for platform in ALL_PLATFORM:
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
config_entry, platform))
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)
config_entry.add_update_listener(update_listener)
return True
return False


async def async_unload_entry(hass: HomeAssistant, config_entry):
"""
async_unload_entry
"""
device_type = config_entry.data.get(CONF_TYPE)
if device_type == CONF_ACCOUNT:
return True
Expand Down
Loading

0 comments on commit a722dcb

Please sign in to comment.