diff --git a/custom_components/midea_ac_lan/fan.py b/custom_components/midea_ac_lan/fan.py index dde643b..806f9c2 100644 --- a/custom_components/midea_ac_lan/fan.py +++ b/custom_components/midea_ac_lan/fan.py @@ -5,7 +5,13 @@ 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, + MAJOR_VERSION, + MINOR_VERSION, + Platform, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from midealocal.device import DeviceType @@ -57,9 +63,18 @@ async def async_setup_entry( async_add_entities(devs) +FAN_FEATURE_TURN_ON_OFF: FanEntityFeature = ( + (FanEntityFeature.TURN_ON | FanEntityFeature.TURN_OFF) + if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 8) + else 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.""" @@ -137,6 +152,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 @@ -160,7 +176,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 @@ -186,8 +204,7 @@ def __init__(self, device: MideaACDevice, entity_key: str) -> None: self._attr_supported_features = ( FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE - | FanEntityFeature.TURN_ON - | FanEntityFeature.TURN_OFF + | FAN_FEATURE_TURN_ON_OFF ) self._attr_speed_count = 100 @@ -246,7 +263,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 @@ -273,7 +292,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