Fix fan speed regression for some xiaomi fans (#78406)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/78679/head
parent
b8ccf53799
commit
1f7c90baa0
|
@ -112,15 +112,6 @@ MODELS_FAN_MIOT = [
|
||||||
MODEL_FAN_ZA5,
|
MODEL_FAN_ZA5,
|
||||||
]
|
]
|
||||||
|
|
||||||
# number of speed levels each fan has
|
|
||||||
SPEEDS_FAN_MIOT = {
|
|
||||||
MODEL_FAN_1C: 3,
|
|
||||||
MODEL_FAN_P10: 4,
|
|
||||||
MODEL_FAN_P11: 4,
|
|
||||||
MODEL_FAN_P9: 4,
|
|
||||||
MODEL_FAN_ZA5: 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
MODELS_PURIFIER_MIOT = [
|
MODELS_PURIFIER_MIOT = [
|
||||||
MODEL_AIRPURIFIER_3,
|
MODEL_AIRPURIFIER_3,
|
||||||
MODEL_AIRPURIFIER_3C,
|
MODEL_AIRPURIFIER_3C,
|
||||||
|
|
|
@ -85,7 +85,6 @@ from .const import (
|
||||||
MODELS_PURIFIER_MIOT,
|
MODELS_PURIFIER_MIOT,
|
||||||
SERVICE_RESET_FILTER,
|
SERVICE_RESET_FILTER,
|
||||||
SERVICE_SET_EXTRA_FEATURES,
|
SERVICE_SET_EXTRA_FEATURES,
|
||||||
SPEEDS_FAN_MIOT,
|
|
||||||
)
|
)
|
||||||
from .device import XiaomiCoordinatedMiioEntity
|
from .device import XiaomiCoordinatedMiioEntity
|
||||||
|
|
||||||
|
@ -235,13 +234,11 @@ async def async_setup_entry(
|
||||||
elif model in MODELS_FAN_MIIO:
|
elif model in MODELS_FAN_MIIO:
|
||||||
entity = XiaomiFan(device, config_entry, unique_id, coordinator)
|
entity = XiaomiFan(device, config_entry, unique_id, coordinator)
|
||||||
elif model == MODEL_FAN_ZA5:
|
elif model == MODEL_FAN_ZA5:
|
||||||
speed_count = SPEEDS_FAN_MIOT[model]
|
entity = XiaomiFanZA5(device, config_entry, unique_id, coordinator)
|
||||||
entity = XiaomiFanZA5(device, config_entry, unique_id, coordinator, speed_count)
|
elif model == MODEL_FAN_1C:
|
||||||
|
entity = XiaomiFan1C(device, config_entry, unique_id, coordinator)
|
||||||
elif model in MODELS_FAN_MIOT:
|
elif model in MODELS_FAN_MIOT:
|
||||||
speed_count = SPEEDS_FAN_MIOT[model]
|
entity = XiaomiFanMiot(device, config_entry, unique_id, coordinator)
|
||||||
entity = XiaomiFanMiot(
|
|
||||||
device, config_entry, unique_id, coordinator, speed_count
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1049,11 +1046,6 @@ class XiaomiFanP5(XiaomiGenericFan):
|
||||||
class XiaomiFanMiot(XiaomiGenericFan):
|
class XiaomiFanMiot(XiaomiGenericFan):
|
||||||
"""Representation of a Xiaomi Fan Miot."""
|
"""Representation of a Xiaomi Fan Miot."""
|
||||||
|
|
||||||
def __init__(self, device, entry, unique_id, coordinator, speed_count):
|
|
||||||
"""Initialize MIOT fan with speed count."""
|
|
||||||
super().__init__(device, entry, unique_id, coordinator)
|
|
||||||
self._speed_count = speed_count
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operation_mode_class(self):
|
def operation_mode_class(self):
|
||||||
"""Hold operation mode class."""
|
"""Hold operation mode class."""
|
||||||
|
@ -1071,9 +1063,7 @@ class XiaomiFanMiot(XiaomiGenericFan):
|
||||||
self._preset_mode = self.coordinator.data.mode.name
|
self._preset_mode = self.coordinator.data.mode.name
|
||||||
self._oscillating = self.coordinator.data.oscillate
|
self._oscillating = self.coordinator.data.oscillate
|
||||||
if self.coordinator.data.is_on:
|
if self.coordinator.data.is_on:
|
||||||
self._percentage = ranged_value_to_percentage(
|
self._percentage = self.coordinator.data.speed
|
||||||
(1, self._speed_count), self.coordinator.data.speed
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self._percentage = 0
|
self._percentage = 0
|
||||||
|
|
||||||
|
@ -1092,6 +1082,59 @@ class XiaomiFanMiot(XiaomiGenericFan):
|
||||||
self._preset_mode = preset_mode
|
self._preset_mode = preset_mode
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_set_percentage(self, percentage: int) -> None:
|
||||||
|
"""Set the percentage of the fan."""
|
||||||
|
if percentage == 0:
|
||||||
|
self._percentage = 0
|
||||||
|
await self.async_turn_off()
|
||||||
|
return
|
||||||
|
|
||||||
|
result = await self._try_command(
|
||||||
|
"Setting fan speed percentage of the miio device failed.",
|
||||||
|
self._device.set_speed,
|
||||||
|
percentage,
|
||||||
|
)
|
||||||
|
if result:
|
||||||
|
self._percentage = percentage
|
||||||
|
|
||||||
|
if not self.is_on:
|
||||||
|
await self.async_turn_on()
|
||||||
|
elif result:
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
|
class XiaomiFanZA5(XiaomiFanMiot):
|
||||||
|
"""Representation of a Xiaomi Fan ZA5."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operation_mode_class(self):
|
||||||
|
"""Hold operation mode class."""
|
||||||
|
return FanZA5OperationMode
|
||||||
|
|
||||||
|
|
||||||
|
class XiaomiFan1C(XiaomiFanMiot):
|
||||||
|
"""Representation of a Xiaomi Fan 1C (Standing Fan 2 Lite)."""
|
||||||
|
|
||||||
|
def __init__(self, device, entry, unique_id, coordinator):
|
||||||
|
"""Initialize MIOT fan with speed count."""
|
||||||
|
super().__init__(device, entry, unique_id, coordinator)
|
||||||
|
self._speed_count = 3
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self):
|
||||||
|
"""Fetch state from the device."""
|
||||||
|
self._state = self.coordinator.data.is_on
|
||||||
|
self._preset_mode = self.coordinator.data.mode.name
|
||||||
|
self._oscillating = self.coordinator.data.oscillate
|
||||||
|
if self.coordinator.data.is_on:
|
||||||
|
self._percentage = ranged_value_to_percentage(
|
||||||
|
(1, self._speed_count), self.coordinator.data.speed
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._percentage = 0
|
||||||
|
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_set_percentage(self, percentage: int) -> None:
|
async def async_set_percentage(self, percentage: int) -> None:
|
||||||
"""Set the percentage of the fan."""
|
"""Set the percentage of the fan."""
|
||||||
if percentage == 0:
|
if percentage == 0:
|
||||||
|
@ -1116,12 +1159,3 @@ class XiaomiFanMiot(XiaomiGenericFan):
|
||||||
if result:
|
if result:
|
||||||
self._percentage = ranged_value_to_percentage((1, self._speed_count), speed)
|
self._percentage = ranged_value_to_percentage((1, self._speed_count), speed)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class XiaomiFanZA5(XiaomiFanMiot):
|
|
||||||
"""Representation of a Xiaomi Fan ZA5."""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def operation_mode_class(self):
|
|
||||||
"""Hold operation mode class."""
|
|
||||||
return FanZA5OperationMode
|
|
||||||
|
|
Loading…
Reference in New Issue