From 294dd8fbd938c538261311b053da0f7aa472e541 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Fri, 9 Aug 2024 22:52:29 +0200 Subject: [PATCH 1/2] Update pre-commit hooks --- .flake8.ini => .flake8 | 0 .hound.yml | 2 +- .pre-commit-config.yaml | 22 +++++++++--- custom_components/xiaomi_miio_fan/fan.py | 43 +++++++++++------------- 4 files changed, 38 insertions(+), 29 deletions(-) rename .flake8.ini => .flake8 (100%) diff --git a/.flake8.ini b/.flake8 similarity index 100% rename from .flake8.ini rename to .flake8 diff --git a/.hound.yml b/.hound.yml index 0b519662..5076dae9 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1,3 +1,3 @@ python: enabled: true - config_file: .flake8.ini + config_file: .flake8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da905778..6a5213e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,18 @@ repos: -- repo: https://github.com/ambv/black - rev: stable - hooks: - - id: black - language_version: python3 + - repo: https://github.com/pre-commit/mirrors-isort + rev: v5.10.1 + hooks: + - id: isort + args: ["--profile", "black"] + + - repo: https://github.com/psf/black + rev: 24.2.0 + hooks: + - id: black + language_version: python3 + + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-builtins, flake8-print, flake8-pytest-style, flake8-return, flake8-simplify, flake8-annotations] diff --git a/custom_components/xiaomi_miio_fan/fan.py b/custom_components/xiaomi_miio_fan/fan.py index c1ada7e5..dc025dce 100644 --- a/custom_components/xiaomi_miio_fan/fan.py +++ b/custom_components/xiaomi_miio_fan/fan.py @@ -4,6 +4,7 @@ For more details about this platform, please refer to the documentation https://home-assistant.io/components/fan.xiaomi_miio/ """ + import asyncio import logging from enum import Enum @@ -12,12 +13,7 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol -from homeassistant.components.fan import ( - PLATFORM_SCHEMA, - FanEntity, - FanEntityFeature, -) - +from homeassistant.components.fan import PLATFORM_SCHEMA, FanEntity, FanEntityFeature from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_MODE, @@ -30,19 +26,9 @@ ordered_list_item_to_percentage, percentage_to_ordered_list_item, ) -from miio import ( - Device, - DeviceException, - Fan, - Fan1C, - FanLeshow, - FanMiot, - FanP5, -) +from miio import Device, DeviceException, Fan, Fan1C, FanLeshow, FanMiot, FanP5 from miio.fan_common import FanException -from miio.fan_common import ( - LedBrightness as FanLedBrightness, -) +from miio.fan_common import LedBrightness as FanLedBrightness from miio.fan_common import MoveDirection as FanMoveDirection from miio.fan_common import OperationMode as FanOperationMode from miio.integrations.fan.leshow.fan_leshow import ( @@ -429,6 +415,7 @@ def _filter_request_fields(req): """Return only the parts that belong to the request..""" return {k: v for k, v in req.items() if k in ["did", "siid", "piid"]} + # pylint: disable=unused-argument async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the miio fan device from config.""" @@ -637,7 +624,9 @@ async def _try_command(self, mask_error, func, *args, **kwargs): self._available = False return False - async def async_turn_on(self, speed: str = None, mode: str = None, **kwargs) -> None: + async def async_turn_on( + self, speed: str = None, mode: str = None, **kwargs + ) -> None: """Turn the device on.""" result = await self._try_command( "Turning the miio device on failed.", self._device.on @@ -725,6 +714,7 @@ def __init__(self, name, device, model, unique_id, retries, preset_modes_overrid self._state_attrs.update( {attribute: None for attribute in self._available_attributes} ) + @property def supported_features(self) -> int: """Supported features.""" @@ -1101,7 +1091,11 @@ def __init__(self, name, device, model, unique_id, retries, preset_modes_overrid @property def supported_features(self) -> int: """Supported features.""" - return FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE | FanEntityFeature.OSCILLATE + return ( + FanEntityFeature.SET_SPEED + | FanEntityFeature.PRESET_MODE + | FanEntityFeature.OSCILLATE + ) async def async_update(self): """Fetch state from the device.""" @@ -1239,7 +1233,11 @@ def __init__(self, name, device, model, unique_id, retries, preset_modes_overrid @property def supported_features(self) -> int: """Supported features.""" - return FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE | FanEntityFeature.OSCILLATE + return ( + FanEntityFeature.SET_SPEED + | FanEntityFeature.PRESET_MODE + | FanEntityFeature.OSCILLATE + ) async def async_update(self): """Fetch state from the device.""" @@ -2336,8 +2334,7 @@ def get_properties_for_mapping(self, *, max_properties=15) -> list: properties = [ {"did": k, **_filter_request_fields(v)} for k, v in mapping.items() - if "aiid" not in v - and ("access" not in v or "read" in v["access"]) + if "aiid" not in v and ("access" not in v or "read" in v["access"]) ] return self.get_properties( From 61b79feca175d5f75e4d061fec015a9deefe78d7 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Fri, 9 Aug 2024 22:58:49 +0200 Subject: [PATCH 2/2] Move to ruff --- .pre-commit-config.yaml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a5213e3..c1fa6b52 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,11 @@ repos: - - repo: https://github.com/pre-commit/mirrors-isort - rev: v5.10.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.5 hooks: - - id: isort - args: ["--profile", "black"] - - - repo: https://github.com/psf/black - rev: 24.2.0 - hooks: - - id: black - language_version: python3 + - id: ruff + args: + - --fix + - id: ruff-format - repo: https://github.com/pycqa/flake8 rev: 7.0.0