Skip to content

Commit

Permalink
Update pre-commit hooks (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Aug 9, 2024
1 parent 081727b commit 31bad41
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 72 deletions.
1 change: 1 addition & 0 deletions .flake8.ini → .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
exclude = .git,.tox,__pycache__
max-line-length = 120
select = C,E,F,W,B,B950
ignore = E501,W503,E203,D202,W504
2 changes: 1 addition & 1 deletion .hound.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
python:
enabled: true
config_file: .flake8.ini
config_file: .flake8
25 changes: 9 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@

repos:
- repo: https://github.com/psf/black
rev: 19.3b0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
hooks:
- id: black
- id: ruff
args:
- --safe
- --quiet
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.3.1
- pydocstyle==4.0.0
- --fix
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: isort
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-builtins, flake8-print, flake8-pytest-style, flake8-return, flake8-simplify, flake8-annotations]
1 change: 1 addition & 0 deletions custom_components/xiaomi_miio_airpurifier/climate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Xiaomi Mi Air Dehumidifier."""

import asyncio
from enum import Enum
from functools import partial
Expand Down
49 changes: 30 additions & 19 deletions custom_components/xiaomi_miio_airpurifier/fan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Xiaomi Mi Air Purifier and Xiaomi Mi Air Humidifier."""

import asyncio
from enum import Enum
from functools import partial
Expand Down Expand Up @@ -74,11 +75,7 @@
)
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,
Expand Down Expand Up @@ -1899,9 +1896,12 @@ def __init__(self, name, device, model, unique_id):
self._device_features = FEATURE_FLAGS_AIRHUMIDIFIER_MJJSQ
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_MJJSQ

self._preset_modes = [mode.name for mode in AirhumidifierMjjsqOperationMode
if self._device_features & FEATURE_SET_WET_PROTECTION != 0
or mode != AirhumidifierMjjsqOperationMode.WetAndProtect]
self._preset_modes = [
mode.name
for mode in AirhumidifierMjjsqOperationMode
if self._device_features & FEATURE_SET_WET_PROTECTION != 0
or mode != AirhumidifierMjjsqOperationMode.WetAndProtect
]
self._state_attrs = {ATTR_MODEL: self._model}
self._state_attrs.update(
{attribute: None for attribute in self._available_attributes}
Expand Down Expand Up @@ -2749,7 +2749,11 @@ def __init__(self, name, device, model, unique_id, retries):
@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."""
Expand Down Expand Up @@ -2882,7 +2886,11 @@ def __init__(self, name, device, model, unique_id, retries):
@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."""
Expand Down Expand Up @@ -3141,12 +3149,14 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
self._preset_modes_to_mode_speed[preset_mode],
)

# Following is true on AirDogX5 with firmware 1.3.5_0005. Maybe this is different for other models. Needs testing
# Following is true on AirDogX5 with firmware 1.3.5_0005.
# Maybe this is different for other models. Needs testing

# It looks like the device was not designed to switch from any arbitrary mode to any other mode.
# Some of the combinations produce unexpected results
#
# For example, switching from 'Auto' to 'Speed X' switches to Manual mode, but always sets speed to 1, regardless of the speed parameter.
# For example, switching from 'Auto' to 'Speed X' switches to Manual mode,
# but always sets speed to 1, regardless of the speed parameter.
#
# Switching from 'Night mode' to 'Speed X' sets device in Auto mode with speed X.
# Tihs 'Auto X' state is quite strange and does not seem to be useful.
Expand All @@ -3157,31 +3167,32 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
# Here is a full table of device behaviour

# FROM TO RESULT
#'Night mode' ->
# 'Night mode' ->
# 'Auto' Good
# 'Speed 1' 'Auto 1' + repeat -> Good
# 'Speed 2' 'Auto 2' + repeat -> Good
# 'Speed 3' 'Auto 3' + repeat -> Good
# 'Speed 4' 'Auto 4' + repeat -> Good
#'Speed 1'
# 'Speed 1'
# 'Night mode' Good
# 'Auto' Good
#'Speed 2' ->
# 'Speed 2' ->
# 'Night mode' Good
# 'Auto' Good
#'Speed 3' ->
# 'Speed 3' ->
# 'Night mode' Good
# 'Auto' Good
#'Speed 4' ->
# 'Speed 4' ->
# 'Night mode' Good
#'Auto'->
# 'Auto'->
# 'Night mode' Good
# 'Speed 1' Good
# 'Speed 2' 'Speed 1' + repeat -> Good
# 'Speed 3' 'Speed 1' + repeat -> Good
# 'Speed 4' 'Speed 1' + repeat -> Good

# To allow switching from any mode to any other mode command is repeated twice when switching is from 'Night mode' or 'Auto' to 'Speed X'.
# To allow switching from any mode to any other mode command is repeated
# twice when switching is from 'Night mode' or 'Auto' to 'Speed X'.

await self._try_command(
"Setting preset mode of the miio device failed.",
Expand Down
36 changes: 0 additions & 36 deletions tox.ini

This file was deleted.

0 comments on commit 31bad41

Please sign in to comment.