Skip to content

Commit

Permalink
add github superlinter and auto release job (#1)
Browse files Browse the repository at this point in the history
* add github superlinter and auto release job

* rename and upadte linter

* update based on super linter error

* update based on super linter error

* update based on super linter error

* update with superlinter error

* convert CRLF to LF for all the files

* update with superlinter error

* update with superlinter error

* revert master source code and recheck with linter

* sync with master

* fix flake8 and yaml linter error

* enable python3 isort and fix with error

* enable python3 isort and fix with error

* update codeql version
  • Loading branch information
wuwentao authored May 21, 2024
1 parent e3a3b71 commit a8a316d
Show file tree
Hide file tree
Showing 95 changed files with 4,659 additions and 3,182 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ jobs:

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 }}"
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ jobs:
VALIDATE_JSCPD: false
VALIDATE_PYTHON_PYLINT: false
VALIDATE_PYTHON_MYPY: false
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_ISORT: false
# VALIDATE_PYTHON_BLACK: false
# VALIDATE_PYTHON_ISORT: false
91 changes: 51 additions & 40 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
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__)

Expand All @@ -34,18 +35,13 @@ async def update_listener(hass, config_entry):
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 @@ -60,7 +56,10 @@ async def async_setup(hass: HomeAssistant, hass_config: dict):
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):
Expand All @@ -72,11 +71,20 @@ 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):
device_id = service.data.get("device_id")
Expand All @@ -85,7 +93,9 @@ def service_send_command(service):
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 +109,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,9 +122,9 @@ 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

Expand All @@ -128,7 +138,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,8 +177,9 @@ 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
Expand Down
14 changes: 5 additions & 9 deletions custom_components/midea_ac_lan/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import Platform, CONF_DEVICE_ID, CONF_SENSORS
from .const import (
DOMAIN,
DEVICES
)
from .midea_entity import MideaEntity
from homeassistant.const import CONF_DEVICE_ID, CONF_SENSORS, Platform

from .const import DEVICES, DOMAIN
from .midea_devices import MIDEA_DEVICES
from .midea_entity import MideaEntity


async def async_setup_entry(hass, config_entry, async_add_entities):
device_id = config_entry.data.get(CONF_DEVICE_ID)
device = hass.data[DOMAIN][DEVICES].get(device_id)
extra_sensors = config_entry.options.get(
CONF_SENSORS, []
)
extra_sensors = config_entry.options.get(CONF_SENSORS, [])
binary_sensors = []
for entity_key, config in MIDEA_DEVICES[device.device_type]["entities"].items():
if config["type"] == Platform.BINARY_SENSOR and entity_key in extra_sensors:
Expand Down
Loading

0 comments on commit a8a316d

Please sign in to comment.