From fd63a03e616f948dda86b6ccd5cc438521b2693b Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Fri, 31 May 2024 03:10:42 +0900 Subject: [PATCH] build: enable pre-commit (#39) * build: enable pre-commit * chore: add missing dependency * chore: fix typing * chore: update env to python 3.12 * chore: move HA to dev requirements * chore: fix typing * chore: spaces --- .github/workflows/linter.yml | 7 +++++++ .pre-commit-config.yaml | 5 ++++- custom_components/midea_ac_lan/climate.py | 6 +++--- custom_components/midea_ac_lan/config_flow.py | 3 ++- custom_components/midea_ac_lan/light.py | 2 +- custom_components/midea_ac_lan/lock.py | 2 +- requirements.dev.txt | 4 +++- requirements.txt | 1 - scripts/setup.sh | 3 +++ 9 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b1de6f38..d021bfd6 100755 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -26,6 +26,13 @@ jobs: # list of files that changed across commits fetch-depth: 0 + - uses: actions/setup-python@v3 + with: + python-version: '3.12' + + - name: Pre-commit + uses: pre-commit/action@v3.0.1 + - name: Super-linter uses: super-linter/super-linter@v6.4.1 # x-release-please-version env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c5e5a31..947d07d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,9 @@ exclude: "CHANGELOG.md|.copier-answers.yml" default_stages: [commit] +default_language_version: + python: python3.12 + ci: autofix_commit_msg: "chore(pre-commit.ci): auto fixes" autoupdate_commit_msg: "chore(pre-commit.ci): pre-commit autoupdate" @@ -53,4 +56,4 @@ repos: rev: v1.10.0 hooks: - id: mypy - additional_dependencies: [] + additional_dependencies: [homeassistant==2024.5.1] diff --git a/custom_components/midea_ac_lan/climate.py b/custom_components/midea_ac_lan/climate.py index 6583d7d8..756486da 100644 --- a/custom_components/midea_ac_lan/climate.py +++ b/custom_components/midea_ac_lan/climate.py @@ -128,7 +128,7 @@ def is_on(self) -> bool: return self.hvac_mode != HVACMode.OFF @property - def hvac_mode(self) -> str: + def hvac_mode(self) -> HVACMode: if self._device.get_attribute("power"): return self._modes[self._device.get_attribute("mode")] else: @@ -449,7 +449,7 @@ def turn_off(self): self._device.set_attribute(attr=self._power_attr, value=False) @property - def hvac_mode(self) -> str: + def hvac_mode(self) -> HVACMode: if self._device.get_attribute(self._power_attr): return self._modes[self._device.get_attribute(C3Attributes.mode)] else: @@ -533,7 +533,7 @@ def target_temperature_high(self): return 35 @property - def hvac_mode(self) -> str: + def hvac_mode(self) -> HVACMode: return ( HVACMode.HEAT if self._device.get_attribute(attr=FBAttributes.power) diff --git a/custom_components/midea_ac_lan/config_flow.py b/custom_components/midea_ac_lan/config_flow.py index 25690f1e..675a441c 100644 --- a/custom_components/midea_ac_lan/config_flow.py +++ b/custom_components/midea_ac_lan/config_flow.py @@ -1,4 +1,5 @@ import os +from typing import Any import voluptuous as vol @@ -75,7 +76,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): devices: dict = {} found_device: dict = {} supports: dict = {} - unsorted: dict[int, str] = {} + unsorted: dict[int, Any] = {} account: dict = {} cloud: MideaCloud | None = None session = None diff --git a/custom_components/midea_ac_lan/light.py b/custom_components/midea_ac_lan/light.py index 473c173e..ae3a358e 100644 --- a/custom_components/midea_ac_lan/light.py +++ b/custom_components/midea_ac_lan/light.py @@ -94,7 +94,7 @@ def supported_features(self) -> LightEntityFeature: supported_features |= SUPPORT_EFFECT if self._device.get_attribute(X13Attributes.rgb_color): supported_features |= SUPPORT_COLOR - return supported_features + return LightEntityFeature(supported_features) def turn_on(self, **kwargs: Any): if not self.is_on: diff --git a/custom_components/midea_ac_lan/lock.py b/custom_components/midea_ac_lan/lock.py index 195d1773..28813fb9 100644 --- a/custom_components/midea_ac_lan/lock.py +++ b/custom_components/midea_ac_lan/lock.py @@ -30,4 +30,4 @@ def unlock(self, **kwargs) -> None: self._device.set_attribute(attr=self._entity_key, value=False) def open(self, **kwargs) -> None: - self.async_unlock() + self.unlock() diff --git a/requirements.dev.txt b/requirements.dev.txt index c9d17274..93bbe686 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1 +1,3 @@ -mypy==1.10.0 \ No newline at end of file +homeassistant==2024.5.1 +mypy==1.10.0 +pre-commit==3.7.1 diff --git a/requirements.txt b/requirements.txt index 8b6be90e..f241f067 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ -homeassistant==2024.5.1 pycryptodome==3.20.0 midea-local==1.0.3 diff --git a/scripts/setup.sh b/scripts/setup.sh index d6235531..c8f4e5e5 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -7,6 +7,9 @@ cd "$(dirname "$0")/.." python3 -m pip install --requirement requirements.txt python3 -m pip install --requirement requirements.dev.txt +# Install pre-commit hooks on commit +pre-commit install + # Create config dir if not present if [[ ! -d "${PWD}/config" ]]; then mkdir -p "${PWD}/config"