Skip to content

Commit

Permalink
revert master source code and recheck with linter
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed May 17, 2024
1 parent 3bbd16f commit ed21124
Show file tree
Hide file tree
Showing 95 changed files with 3,287 additions and 5,291 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
---
name: "CodeQL"

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

permissions: {}

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

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

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

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

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
121 changes: 43 additions & 78 deletions custom_components/midea_ac_lan/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
"""
__init__.py
"""

import logging

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

import homeassistant.helpers.config_validation as cv
from .const import (
ALL_PLATFORM,
DOMAIN,
CONF_ACCOUNT,
CONF_KEY,
CONF_MODEL,
CONF_REFRESH_INTERVAL,
CONF_SUBTYPE,
CONF_REFRESH_INTERVAL,
DEVICES,
DOMAIN,
EXTRA_SENSOR,
EXTRA_SWITCH,
EXTRA_CONTROL,
ALL_PLATFORM,
)
from .midea.devices import async_device_selector
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

_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 @@ -58,28 +57,15 @@ async def update_listener(hass, config_entry):
dev.set_refresh_interval(refresh_interval)


async def async_setup(hass: HomeAssistant, config: dict):
"""
async_setup
"""
if config.get(DOMAIN) is None:
# We get her if the integration is set up using config flow
return True

async def async_setup(hass: HomeAssistant, hass_config: dict):
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 @@ -88,34 +74,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):
"""
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 @@ -129,9 +101,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 @@ -142,17 +114,14 @@ 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 @@ -161,7 +130,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 @@ -200,18 +169,14 @@ 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
31 changes: 9 additions & 22 deletions custom_components/midea_ac_lan/binary_sensor.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
"""
binary_sensor.py
"""

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import CONF_DEVICE_ID, CONF_SENSORS, Platform

from .const import DEVICES, DOMAIN
from .midea_devices import MIDEA_DEVICES
from homeassistant.const import Platform, CONF_DEVICE_ID, CONF_SENSORS
from .const import (
DOMAIN,
DEVICES
)
from .midea_entity import MideaEntity
from .midea_devices import MIDEA_DEVICES


async def async_setup_entry(hass, config_entry, async_add_entities):
"""
async_setup_entry
"""
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 All @@ -26,20 +23,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):


class MideaSensor(MideaEntity, BinarySensorEntity):
"""
MideaSensor
"""

@property
def device_class(self):
"""
device_class
"""
return self._config.get("device_class")

@property
def is_on(self):
"""
is_on
"""
return self._device.get_attribute(self._entity_key)
Loading

0 comments on commit ed21124

Please sign in to comment.