Skip to content

Commit

Permalink
chore: enabled pre-commit (#28)
Browse files Browse the repository at this point in the history
* chore: enabled pre-commit

* chore: small fixes

* chore: add myself as codeowner
  • Loading branch information
chemelli74 authored May 28, 2024
1 parent d64b2a9 commit 8f24cad
Show file tree
Hide file tree
Showing 64 changed files with 1,330 additions and 1,189 deletions.
78 changes: 38 additions & 40 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
{
"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",
"github.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"ms-python.black-formatter"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
}
},
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.12"
}
}
}
"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",
"github.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"ms-python.black-formatter"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
}
},
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.12"
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/issue-translator.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'issue-translator'
name: "issue-translator"
on:
issue_comment:
types: [created]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Lint

on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
push: null
pull_request: null

Expand All @@ -27,7 +27,7 @@ jobs:
fetch-depth: 0

- name: Super-linter
uses: super-linter/super-linter@v6.4.1 # x-release-please-version
uses: super-linter/super-linter@v6.4.1 # x-release-please-version
env:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "CHANGELOG.md|.copier-answers.yml"
default_stages: [commit]

ci:
autofix_commit_msg: "chore(pre-commit.ci): auto fixes"
autoupdate_commit_msg: "chore(pre-commit.ci): pre-commit autoupdate"
autoupdate_schedule: weekly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: no-commit-to-branch
args: ["--branch", "master"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.26.0
hooks:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v4.0.0-alpha.8
# hooks:
# - id: prettier
# args: ["--tab-width", "2"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py37-plus]
# - repo: https://github.com/codespell-project/codespell
# rev: v2.3.0
# hooks:
# - id: codespell
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: []
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
Expand Down
10 changes: 4 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
20 changes: 10 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "scripts/run.sh",
"problemMatcher": []
}
]
}
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "scripts/run.sh",
"problemMatcher": []
}
]
}
5 changes: 4 additions & 1 deletion custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import cast

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -55,7 +56,9 @@ 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():
for attribute_name, attribute in cast(
dict, device_entities["entities"]
).items():
if (
attribute.get("type") in EXTRA_SWITCH
and attribute_name.value not in attributes
Expand Down
7 changes: 3 additions & 4 deletions custom_components/midea_ac_lan/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):


class MideaClimate(MideaEntity, ClimateEntity):

# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded
_enable_turn_on_off_backwards_compatibility: bool = (
False # maybe remove after 2025.1
Expand Down Expand Up @@ -176,7 +175,7 @@ def turn_off(self):
def set_temperature(self, **kwargs) -> None:
if ATTR_TEMPERATURE not in kwargs:
return
temperature = float(int((float(kwargs.get(ATTR_TEMPERATURE)) * 2) + 0.5)) / 2
temperature = float(int((float(kwargs[ATTR_TEMPERATURE]) * 2) + 0.5)) / 2
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode == HVACMode.OFF:
self.turn_off()
Expand Down Expand Up @@ -462,7 +461,7 @@ def current_temperature(self):
def set_temperature(self, **kwargs) -> None:
if ATTR_TEMPERATURE not in kwargs:
return
temperature = float(int((float(kwargs.get(ATTR_TEMPERATURE)) * 2) + 0.5)) / 2
temperature = float(int((float(kwargs[ATTR_TEMPERATURE]) * 2) + 0.5)) / 2
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode == HVACMode.OFF:
self.turn_off()
Expand Down Expand Up @@ -541,7 +540,7 @@ def current_temperature(self):
def set_temperature(self, **kwargs) -> None:
if ATTR_TEMPERATURE not in kwargs:
return
temperature = float(int((float(kwargs.get(ATTR_TEMPERATURE)) * 2) + 0.5)) / 2
temperature = float(int((float(kwargs[ATTR_TEMPERATURE]) * 2) + 0.5)) / 2
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode == HVACMode.OFF:
self.turn_off()
Expand Down
20 changes: 10 additions & 10 deletions custom_components/midea_ac_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.util.json import load_json
from midealocal.cloud import get_midea_cloud
from midealocal.cloud import MideaCloud, get_midea_cloud
from midealocal.device import MideaDevice
from midealocal.discover import discover

Expand Down Expand Up @@ -70,19 +70,19 @@
]


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
available_device = []
devices = {}
found_device = {}
supports = {}
unsorted = {}
account = {}
cloud = None
class ConfigFlow(config_entries.ConfigFlow):
available_device: list = []
devices: dict = {}
found_device: dict = {}
supports: dict = {}
unsorted: dict = {}
account: dict = {}
cloud: MideaCloud | None = None
session = None
for device_type, device_info in MIDEA_DEVICES.items():
unsorted[device_type] = device_info["name"]

unsorted = sorted(unsorted.items(), key=lambda x: x[1])
unsorted = dict(sorted(unsorted.items(), key=lambda x: x[1]))
for item in unsorted:
supports[item[0]] = item[1]

Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def turn_on(self, **kwargs: Any):
if not self.is_on:
self._device.set_attribute(attr=X13Attributes.power, value=True)
for key in kwargs:
value = kwargs.get(key)
value = kwargs[key]
if key == ATTR_BRIGHTNESS:
self._device.set_attribute(attr=X13Attributes.brightness, value=value)
if key == ATTR_COLOR_TEMP:
Expand Down
1 change: 0 additions & 1 deletion custom_components/midea_ac_lan/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):


class MideaLock(MideaEntity, LockEntity):

@property
def is_locked(self):
return self._device.get_attribute(self._entity_key)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/midea_ac_lan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"name": "Midea AC LAN",
"codeowners": [
"@wuwentao",
"@rokam"
"@rokam",
"@chemelli74"
],
"config_flow": true,
"dependencies": [],
Expand Down
4 changes: 3 additions & 1 deletion custom_components/midea_ac_lan/midea_devices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (
Expand Down Expand Up @@ -45,7 +47,7 @@
from midealocal.devices.x34 import DeviceAttributes as X34Attributes
from midealocal.devices.x40 import DeviceAttributes as X40Attributes

MIDEA_DEVICES = {
MIDEA_DEVICES: dict[int, dict[str, dict[str, Any] | str]] = {
0x13: {
"name": "Light",
"entities": {
Expand Down
5 changes: 4 additions & 1 deletion custom_components/midea_ac_lan/midea_entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import cast

from homeassistant.helpers.entity import Entity

Expand All @@ -12,7 +13,9 @@ class MideaEntity(Entity):
def __init__(self, device, entity_key: str):
self._device = device
self._device.register_update(self.update_state)
self._config = MIDEA_DEVICES[self._device.device_type]["entities"][entity_key]
self._config = cast(dict, MIDEA_DEVICES[self._device.device_type]["entities"])[
entity_key
]
self._entity_key = entity_key
self._unique_id = f"{DOMAIN}.{self._device.device_id}_{entity_key}"
self.entity_id = self._unique_id
Expand Down
Loading

0 comments on commit 8f24cad

Please sign in to comment.