Skip to content

Commit

Permalink
fix: Add MideaACFreshAirFan feature turn_on and turn_off (#285)
Browse files Browse the repository at this point in the history
* Add fan entity feature turn_on and turn_off

* chore(pre-commit.ci): auto fixes

* check HA version

* Update fan.py to fix pylint error

* Update fan.py to fix pylint error

* Update fan.py to fix line too long error

* try to fix both mypy and pylint error

* try to fix both mypy and pylint error

* chore(pre-commit.ci): auto fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Necroneco <[email protected]>
Co-authored-by: Hello World <[email protected]>
  • Loading branch information
4 people authored Aug 23, 2024
1 parent 2b37e57 commit 2d466d5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions custom_components/midea_ac_lan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICE_ID, CONF_SWITCHES, Platform
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_SWITCHES,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from midealocal.device import DeviceType
Expand Down Expand Up @@ -57,9 +61,18 @@ async def async_setup_entry(
async_add_entities(devs)


# HA version >= 2024,8 support TURN_ON | TURN_OFF,for future changes, ref PR #285
try:
FAN_FEATURE_TURN_ON_OFF = FanEntityFeature["TURN_ON"] | FanEntityFeature["TURN_OFF"]
except KeyError:
FAN_FEATURE_TURN_ON_OFF = FanEntityFeature(0)


class MideaFan(MideaEntity, FanEntity):
"""Midea Fan Entries Base Class."""

_enable_turn_on_off_backwards_compatibility = False # 2024.8~2025.1

@property
def preset_modes(self) -> list[str] | None:
"""Midea Fan preset modes."""
Expand Down Expand Up @@ -137,6 +150,7 @@ def __init__(self, device: MideaFADevice, entity_key: str) -> None:
FanEntityFeature.SET_SPEED
| FanEntityFeature.OSCILLATE
| FanEntityFeature.PRESET_MODE
| FAN_FEATURE_TURN_ON_OFF
)
self._attr_speed_count = self._device.speed_count

Expand All @@ -160,7 +174,9 @@ def __init__(self, device: MideaB6Device, entity_key: str) -> None:
"""Midea B6 Fan entity init."""
super().__init__(device, entity_key)
self._attr_supported_features = (
FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
FanEntityFeature.SET_SPEED
| FanEntityFeature.PRESET_MODE
| FAN_FEATURE_TURN_ON_OFF
)
self._attr_speed_count = self._device.speed_count

Expand All @@ -184,7 +200,9 @@ def __init__(self, device: MideaACDevice, entity_key: str) -> None:
"""Midea AC Fresh Air Fan entity init."""
super().__init__(device, entity_key)
self._attr_supported_features = (
FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
FanEntityFeature.SET_SPEED
| FanEntityFeature.PRESET_MODE
| FAN_FEATURE_TURN_ON_OFF
)
self._attr_speed_count = 100

Expand Down Expand Up @@ -243,7 +261,9 @@ def __init__(self, device: MideaCEDevice, entity_key: str) -> None:
"""Midea CE Fan entity init."""
super().__init__(device, entity_key)
self._attr_supported_features = (
FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
FanEntityFeature.SET_SPEED
| FanEntityFeature.PRESET_MODE
| FAN_FEATURE_TURN_ON_OFF
)
self._attr_speed_count = self._device.speed_count

Expand All @@ -270,7 +290,9 @@ def __init__(self, device: MideaX40Device, entity_key: str) -> None:
"""Midea X40 Fan entity init."""
super().__init__(device, entity_key)
self._attr_supported_features = (
FanEntityFeature.SET_SPEED | FanEntityFeature.OSCILLATE
FanEntityFeature.SET_SPEED
| FanEntityFeature.OSCILLATE
| FAN_FEATURE_TURN_ON_OFF
)
self._attr_speed_count = 2

Expand Down

0 comments on commit 2d466d5

Please sign in to comment.