Skip to content

Commit

Permalink
Add support for setting target humidity (#172)
Browse files Browse the repository at this point in the history
* Add properties to climate entity for humidity

* Attempt to handle SMART_DRY mode

* Exclude smart dry from supported modes

* Update README
  • Loading branch information
mill1000 authored Jul 18, 2024
1 parent 5583b6e commit 4661488
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ See [Getting Device Info](#getting-device-info) to determine if a device is supp
* Service to enable "Follow Me" function<sup>2</sup>.
* Select entities to control swing angle when supported.
* Indoor humidity sensor when supported.
* Target humidity in Dry mode when supported.
* Energy and power sensors when supported<sup>3</sup>.
* Button and binary sensor to start & monitor self cleaning.
* Translations
Expand Down
44 changes: 40 additions & 4 deletions custom_components/midea_ac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ def __init__(self,
self._device, "supported_operation_modes", AC.OperationalMode.list())

# Convert from Midea operational modes to HA HVAC mode
self._hvac_modes = [_OPERATIONAL_MODE_TO_HVAC_MODE[m]
for m in supported_op_modes]
self._hvac_modes = [
_OPERATIONAL_MODE_TO_HVAC_MODE[m]
for m in supported_op_modes
# Don't include smart dry, we will try to automatically use this mode when supported
if m != AC.OperationalMode.SMART_DRY
]
self._hvac_modes.append(HVACMode.OFF)

# Append additional operation modes as needed
Expand Down Expand Up @@ -247,6 +251,12 @@ async def async_set_follow_me(self, enabled: bool) -> None:
@property
def supported_features(self) -> int:
"""Return the supported features."""

if (self._device.operational_mode in [AC.OperationalMode.DRY,
AC.OperationalMode.SMART_DRY]
and getattr(self._device, "supports_target_humidity", False)):
return self._supported_features | ClimateEntityFeature.TARGET_HUMIDITY

return self._supported_features

@property
Expand Down Expand Up @@ -288,6 +298,21 @@ async def async_set_temperature(self, **kwargs) -> None:
self._device.target_temperature = round(temperature * 2) / 2
await self._apply()

@property
def current_humidity(self) -> float | None:
"""Return the current humidity."""
return self._device.indoor_humidity

@property
def target_humidity(self) -> float | None:
"""Return the current target humidity."""
return self._device.target_humidity

async def async_set_humidity(self, humidity) -> None:
"""Set a new target humidity."""
self._device.target_humidity = int(humidity)
await self._apply()

@property
def swing_modes(self) -> list[str]:
"""Return the supported swing modes."""
Expand Down Expand Up @@ -350,7 +375,12 @@ def hvac_mode(self) -> HVACMode:
if not self._device.power_state:
return HVACMode.OFF

return _OPERATIONAL_MODE_TO_HVAC_MODE.get(self._device.operational_mode, HVACMode.OFF)
mode = self._device.operational_mode

if mode == AC.OperationalMode.SMART_DRY:
mode = AC.OperationalMode.DRY

return _OPERATIONAL_MODE_TO_HVAC_MODE.get(mode, HVACMode.OFF)

async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the HVAC mode."""
Expand All @@ -359,9 +389,15 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
else:
self._device.power_state = True

self._device.operational_mode = _HVAC_MODE_TO_OPERATIONAL_MODE.get(
mode = _HVAC_MODE_TO_OPERATIONAL_MODE.get(
hvac_mode, self._device.operational_mode)

if (mode == AC.OperationalMode.DRY
and getattr(self._device, "supports_target_humidity", False)):
mode = AC.OperationalMode.SMART_DRY

self._device.operational_mode = mode

await self._apply()

@property
Expand Down

0 comments on commit 4661488

Please sign in to comment.