Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for HomeKit fan modes (issue #563) #704

Merged
34 changes: 29 additions & 5 deletions custom_components/smartthinq_sensors/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
ATTR_HVAC_MODE,
DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP,
FAN_AUTO,
FAN_DIFFUSE,
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
PRESET_ECO,
PRESET_NONE,
ClimateEntityFeature,
Expand All @@ -29,7 +34,13 @@
from .const import DOMAIN, LGE_DEVICES, LGE_DISCOVERY_NEW
from .device_helpers import TEMP_UNIT_LOOKUP, LGERefrigeratorDevice
from .wideq import AirConditionerFeatures, DeviceType, TemperatureUnit
from .wideq.devices.ac import AWHP_MAX_TEMP, AWHP_MIN_TEMP, ACMode, AirConditionerDevice
from .wideq.devices.ac import (
AWHP_MAX_TEMP,
AWHP_MIN_TEMP,
ACFanSpeed,
ACMode,
AirConditionerDevice,
)

# general ac attributes
ATTR_FRIDGE = "fridge"
Expand All @@ -47,6 +58,15 @@
ACMode.ACO.name: HVACMode.HEAT_COOL,
}

FAN_MODE_LOOKUP: dict[str, str] = {
ACFanSpeed.AUTO.name: FAN_AUTO,
ACFanSpeed.HIGH.name: FAN_HIGH,
ACFanSpeed.LOW.name: FAN_LOW,
ACFanSpeed.MID.name: FAN_MEDIUM,
ACFanSpeed.NATURE.name: FAN_DIFFUSE,
}
FAN_MODE_REVERSE_LOOKUP = {v: k for k, v in FAN_MODE_LOOKUP.items()}

PRESET_MODE_LOOKUP: dict[str, dict[str, HVACMode]] = {
ACMode.ENERGY_SAVING.name: {"preset": PRESET_ECO, "hvac": HVACMode.COOL},
ACMode.ENERGY_SAVER.name: {"preset": PRESET_ECO, "hvac": HVACMode.COOL},
Expand Down Expand Up @@ -181,7 +201,9 @@ def __init__(self, api: LGEDevice) -> None:
super().__init__(api)
self._device: AirConditionerDevice = api.device
self._attr_unique_id = f"{api.unique_id}-AC"
self._attr_fan_modes = self._device.fan_speeds
self._attr_fan_modes = [
FAN_MODE_LOOKUP.get(s, s) for s in self._device.fan_speeds
]
self._attr_swing_modes = [
f"{SWING_PREFIX[0]}{mode}" for mode in self._device.vertical_step_modes
] + [f"{SWING_PREFIX[1]}{mode}" for mode in self._device.horizontal_step_modes]
Expand Down Expand Up @@ -365,13 +387,15 @@ async def async_set_temperature(self, **kwargs) -> None:
@property
def fan_mode(self) -> str | None:
"""Return the fan setting."""
return self._api.state.fan_speed
speed = self._api.state.fan_speed
return FAN_MODE_LOOKUP.get(speed, speed)

async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
if fan_mode not in self.fan_modes:
lg_fan_mode = FAN_MODE_REVERSE_LOOKUP.get(fan_mode, fan_mode)
if lg_fan_mode not in self._device.fan_speeds:
raise ValueError(f"Invalid fan mode [{fan_mode}]")
await self._device.set_fan_speed(fan_mode)
await self._device.set_fan_speed(lg_fan_mode)
self._api.async_set_updated()

@property
Expand Down
Loading