From b6bf0f9cdb2281e52c79357b0a2870a7cd00c598 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Fri, 9 Aug 2024 23:02:25 +0200 Subject: [PATCH 1/2] Update pre-commit hooks (#169) --- .flake8.ini => .flake8 | 0 .hound.yml | 2 +- .pre-commit-config.yaml | 18 +++++++++++++----- .../climate.py | 10 ++++++---- 4 files changed, 20 insertions(+), 10 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 0b51966..5076dae 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 da90577..c1fa6b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,14 @@ repos: -- repo: https://github.com/ambv/black - rev: stable - hooks: - - id: black - language_version: python3 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.5 + hooks: + - id: ruff + args: + - --fix + - id: ruff-format + + - 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_airconditioningcompanion/climate.py b/custom_components/xiaomi_miio_airconditioningcompanion/climate.py index ef437b4..b4947d7 100644 --- a/custom_components/xiaomi_miio_airconditioningcompanion/climate.py +++ b/custom_components/xiaomi_miio_airconditioningcompanion/climate.py @@ -4,6 +4,7 @@ For more details about this platform, please refer to the documentation https://home-assistant.io/components/climate.xiaomi_miio """ + import asyncio import enum import logging @@ -227,7 +228,6 @@ def __init__( min_temp, max_temp, ): - """Initialize the climate device.""" self.hass = hass self._name = name @@ -527,9 +527,11 @@ async def _send_configuration(self): self._device.send_configuration, self._air_condition_model, Power(int(self._state)), - MiioOperationMode[OperationMode(self._hvac_mode).name] - if self._state - else MiioOperationMode[OperationMode(self._last_on_operation).name], + ( + MiioOperationMode[OperationMode(self._hvac_mode).name] + if self._state + else MiioOperationMode[OperationMode(self._last_on_operation).name] + ), int(self._target_temperature), self._fan_mode, self._swing_mode, From 122d05f1c56a7e91830d15bf85cca9d51b6a35c8 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Fri, 9 Aug 2024 23:08:51 +0200 Subject: [PATCH 2/2] Migrate away from deprecated consts (#168) --- .../climate.py | 37 +++++++++---------- .../manifest.json | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/custom_components/xiaomi_miio_airconditioningcompanion/climate.py b/custom_components/xiaomi_miio_airconditioningcompanion/climate.py index b4947d7..37d0f89 100644 --- a/custom_components/xiaomi_miio_airconditioningcompanion/climate.py +++ b/custom_components/xiaomi_miio_airconditioningcompanion/climate.py @@ -17,15 +17,8 @@ from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, - HVAC_MODE_AUTO, - HVAC_MODE_COOL, - HVAC_MODE_DRY, - HVAC_MODE_FAN_ONLY, - HVAC_MODE_HEAT, - HVAC_MODE_OFF, - SUPPORT_FAN_MODE, - SUPPORT_SWING_MODE, - SUPPORT_TARGET_TEMPERATURE, + ClimateEntityFeature, + HVACMode, ) from homeassistant.components.remote import ( ATTR_DELAY_SECS, @@ -42,7 +35,7 @@ CONF_TIMEOUT, CONF_TOKEN, STATE_ON, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import callback from homeassistant.exceptions import PlatformNotReady @@ -67,7 +60,11 @@ ATTR_LOAD_POWER = "load_power" ATTR_LED = "led" -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE +SUPPORT_FLAGS = ( + ClimateEntityFeature.TARGET_TEMPERATURE + | ClimateEntityFeature.FAN_MODE + | ClimateEntityFeature.SWING_MODE +) CONF_SENSOR = "target_sensor" CONF_MIN_TEMP = "min_temp" @@ -206,12 +203,12 @@ async def async_service_handler(service): class OperationMode(enum.Enum): - Heat = HVAC_MODE_HEAT - Cool = HVAC_MODE_COOL - Auto = HVAC_MODE_AUTO - Dehumidify = HVAC_MODE_DRY - Ventilate = HVAC_MODE_FAN_ONLY - Off = HVAC_MODE_OFF + Heat = HVACMode.HEAT + Cool = HVACMode.COOL + Auto = HVACMode.AUTO + Dehumidify = HVACMode.DRY + Ventilate = HVACMode.FAN_ONLY + Off = HVACMode.OFF class XiaomiAirConditioningCompanion(ClimateEntity): @@ -364,7 +361,7 @@ async def async_update(self): ) self._last_on_operation = OperationMode[state.mode.name].value if state.power == "off": - self._hvac_mode = HVAC_MODE_OFF + self._hvac_mode = HVACMode.OFF self._state = False else: self._hvac_mode = self._last_on_operation @@ -427,7 +424,7 @@ def extra_state_attributes(self): @property def temperature_unit(self): """Return the unit of measurement.""" - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS @property def current_temperature(self): @@ -497,7 +494,7 @@ async def async_set_hvac_mode(self, hvac_mode): ) if result: self._state = False - self._hvac_mode = HVAC_MODE_OFF + self._hvac_mode = HVACMode.OFF await self._send_configuration() else: self._hvac_mode = OperationMode(hvac_mode).value diff --git a/custom_components/xiaomi_miio_airconditioningcompanion/manifest.json b/custom_components/xiaomi_miio_airconditioningcompanion/manifest.json index c724f44..e5b9064 100644 --- a/custom_components/xiaomi_miio_airconditioningcompanion/manifest.json +++ b/custom_components/xiaomi_miio_airconditioningcompanion/manifest.json @@ -13,5 +13,5 @@ "construct==2.10.68", "python-miio>=0.5.12" ], - "version": "2023.12.0.0" + "version": "2024.8.0.0" }