Skip to content

Commit

Permalink
Merge branch 'release/2024.8.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Aug 13, 2024
2 parents 770be5c + bdd7ccc commit 22f2dee
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
File renamed without changes.
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
18 changes: 13 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
71 changes: 40 additions & 31 deletions custom_components/xiaomi_miio_fan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -627,7 +614,7 @@ def _extract_value_from_attribute(state, attribute):
async def _try_command(self, mask_error, func, *args, **kwargs):
"""Call a miio device command handling error messages."""
try:
result = await self.hass.async_add_job(partial(func, *args, **kwargs))
result = await self.hass.async_add_executor_job(partial(func, *args, **kwargs))

_LOGGER.debug("Response received from miio device: %s", result)

Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -733,6 +723,8 @@ def supported_features(self) -> int:
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.OSCILLATE
| FanEntityFeature.DIRECTION
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

async def async_update(self):
Expand All @@ -743,7 +735,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -964,7 +956,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -1101,7 +1093,13 @@ 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
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

async def async_update(self):
"""Fetch state from the device."""
Expand All @@ -1111,7 +1109,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -1239,7 +1237,13 @@ 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
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

async def async_update(self):
"""Fetch state from the device."""
Expand All @@ -1249,7 +1253,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -1419,6 +1423,8 @@ def supported_features(self) -> int:
| FanEntityFeature.OSCILLATE
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.SET_SPEED
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

async def async_update(self):
Expand All @@ -1427,7 +1433,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -1860,6 +1866,8 @@ def supported_features(self) -> int:
| FanEntityFeature.OSCILLATE
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.SET_SPEED
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

"""
Expand All @@ -1875,7 +1883,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -2167,6 +2175,8 @@ def supported_features(self) -> int:
| FanEntityFeature.OSCILLATE
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.SET_SPEED
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)

async def async_update(self):
Expand All @@ -2175,7 +2185,7 @@ async def async_update(self):
return

try:
state = await self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_executor_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -2336,8 +2346,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(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_miio_fan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"construct==2.10.68",
"python-miio>=0.5.12"
],
"version": "2024.7.0.0"
"version": "2024.8.0.0"
}

0 comments on commit 22f2dee

Please sign in to comment.