Skip to content

Commit

Permalink
💦 add humidity control for climate
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Feb 11, 2025
1 parent 661a829 commit f3016a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions custom_components/xiaomi_miot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class ClimateEntity(XEntity, BaseClimateEntity):
_conv_swing_h = None
_conv_target_temp = None
_conv_current_temp = None
_conv_target_humidity = None
_conv_current_humidity = None
_prop_temperature = None

Expand Down Expand Up @@ -222,6 +223,12 @@ def on_init(self):
self._attr_temperature_unit = self.prop_temperature_unit(prop)
elif prop.in_list(['relative_humidity', 'humidity']):
self._conv_current_humidity = conv
elif prop.in_list(['target_humidity']):
self._conv_target_humidity = conv
if prop.value_range:
self._attr_min_humidity = prop.range_min()
self._attr_max_humidity = prop.range_max()
self._attr_supported_features |= ClimateEntityFeature.TARGET_HUMIDITY

def set_state(self, data: dict):
if self._conv_mode:
Expand Down Expand Up @@ -262,6 +269,11 @@ def set_state(self, data: dict):
val = self._conv_current_temp.value_from_dict(data)
if val is not None:
self._attr_current_temperature = val

if self._conv_target_humidity:
val = self._conv_target_humidity.value_from_dict(data)
if val is not None:
self._attr_target_humidity = val
if self._conv_current_humidity:
val = self._conv_current_humidity.value_from_dict(data)
if val is not None:
Expand Down Expand Up @@ -327,6 +339,11 @@ async def async_set_temperature(self, **kwargs):
dat[self._conv_target_temp.attr] = temp
await self.device.async_write(dat)

async def async_set_humidity(self, humidity: int):
if not self._conv_target_humidity:
return
await self.device.async_write({self._conv_target_humidity.attr: humidity})

async def async_set_fan_mode(self, fan_mode: str):
if not self._conv_speed:
return
Expand Down
2 changes: 2 additions & 0 deletions custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2746,6 +2746,8 @@
{'props': ['on', 'target_temperature']},
{'props': ['indoor_temperature', 'temperature']},
{'props': ['environment.indoor_temperature', 'environment.temperature']},
{'props': ['relative_humidity', 'humidity', 'target_humidity']},
{'props': ['environment.relative_humidity', 'environment.humidity']},
{'props': ['mode', 'fan_control.mode'], 'desc': True},
{'props': ['fan_level', 'fan_control.fan_level', 'heat_level'], 'desc': True},
{'props': ['horizontal_swing', 'fan_control.horizontal_swing']},
Expand Down

0 comments on commit f3016a0

Please sign in to comment.