1818 CONTINUOUS_DEHUMIDIFICATION ,
1919 DOMAIN ,
2020 FAN_SPEED_HIGH ,
21- FAN_SPEED_LOW ,
22- FAN_SPEED_MEDIUM ,
2321 MAX_HUMIDITY ,
2422 MIN_HUMIDITY ,
2523 REG_DEHUMIDIFY_MODE ,
4038# Polling interval
4139SCAN_INTERVAL = timedelta (seconds = 5 )
4240
43- # Fan speed mapping for modes
44- MODES = {
45- FAN_SPEED_LOW : "Low" ,
46- FAN_SPEED_MEDIUM : "Medium" ,
47- FAN_SPEED_HIGH : "High" ,
48- }
49-
50- REVERSE_MODES = {v : k for k , v in MODES .items ()}
41+ # Preset modes
42+ PRESET_MODE_DEHUMIDIFY = "Dehumidify"
43+ PRESET_MODE_AIR_PURIFICATION = "Air Purification"
44+ PRESET_MODES = [PRESET_MODE_DEHUMIDIFY , PRESET_MODE_AIR_PURIFICATION ]
5145
5246
5347async def async_setup_entry (
@@ -75,7 +69,7 @@ class MedoleDehumidifierHumidifier(HumidifierEntity):
7569 _attr_name = None
7670 _attr_supported_features = HumidifierEntityFeature .MODES
7771 _attr_device_class = HumidifierDeviceClass .DEHUMIDIFIER
78- _attr_available_modes = list ( REVERSE_MODES . keys ())
72+ _attr_available_modes = PRESET_MODES
7973 _attr_min_humidity = MIN_HUMIDITY
8074 _attr_max_humidity = MAX_HUMIDITY
8175
@@ -97,6 +91,7 @@ def __init__(self, hass, name, client):
9791 self ._attr_mode = None
9892 self ._attr_is_on = False
9993 self ._attr_action = None
94+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
10095
10196 @property
10297 def current_humidity (self ):
@@ -166,14 +161,27 @@ async def async_update(self) -> None:
166161 else :
167162 _LOGGER .error ("Failed to read humidity setpoint" )
168163
169- # Get the fan speed
170- fan_speed_result = await self ._client .async_read_register (REG_FAN_SPEED )
171-
172- if fan_speed_result :
173- fan_speed = fan_speed_result .registers [0 ]
174- self ._attr_mode = MODES .get (fan_speed , "Medium" )
175- else :
176- _LOGGER .error ("Failed to read fan speed" )
164+ # Check which mode is active (dehumidify or air purification)
165+ dehumidify_result = await self ._client .async_read_register (
166+ REG_DEHUMIDIFY_MODE
167+ )
168+ purify_result = await self ._client .async_read_register (REG_PURIFY_MODE )
169+
170+ if dehumidify_result and purify_result :
171+ dehumidify_on = dehumidify_result .registers [0 ] == 1
172+ purify_on = purify_result .registers [0 ] == 1
173+
174+ # Prioritize showing dehumidify mode when both are active
175+ if dehumidify_on :
176+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
177+ self ._attr_mode = PRESET_MODE_DEHUMIDIFY
178+ elif purify_on :
179+ self ._current_preset = PRESET_MODE_AIR_PURIFICATION
180+ self ._attr_mode = PRESET_MODE_AIR_PURIFICATION
181+ else :
182+ # Neither mode is active
183+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
184+ self ._attr_mode = PRESET_MODE_DEHUMIDIFY
177185
178186 # Get the current humidity
179187 humidity_result = await self ._client .async_read_register (REG_HUMIDITY_1 )
@@ -185,16 +193,36 @@ async def async_update(self) -> None:
185193
186194 async def async_set_mode (self , mode : str ) -> None :
187195 """Set new mode."""
188- fan_speed = REVERSE_MODES .get (mode , FAN_SPEED_MEDIUM )
189-
190- success = await self ._client .async_write_register (
191- REG_FAN_SPEED , fan_speed
192- )
193-
194- if success :
195- self ._attr_mode = mode
196- else :
197- _LOGGER .error ("Failed to set mode to %s" , mode )
196+ if mode == PRESET_MODE_AIR_PURIFICATION :
197+ # Switch to air purification mode with high fan speed
198+ await self ._client .async_write_register (
199+ REG_FAN_SPEED , FAN_SPEED_HIGH
200+ )
201+ await self ._client .async_write_register (REG_DEHUMIDIFY_MODE , 0 )
202+ success = await self ._client .async_write_register (
203+ REG_PURIFY_MODE , 1
204+ )
205+ if success :
206+ self ._current_preset = PRESET_MODE_AIR_PURIFICATION
207+ self ._attr_mode = mode
208+ _LOGGER .info ("Switched to air purification mode" )
209+ else :
210+ _LOGGER .error ("Failed to set air purification mode" )
211+ elif mode == PRESET_MODE_DEHUMIDIFY :
212+ # Switch to dehumidify mode with high fan speed
213+ await self ._client .async_write_register (
214+ REG_FAN_SPEED , FAN_SPEED_HIGH
215+ )
216+ await self ._client .async_write_register (REG_PURIFY_MODE , 1 )
217+ success = await self ._client .async_write_register (
218+ REG_DEHUMIDIFY_MODE , 1
219+ )
220+ if success :
221+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
222+ self ._attr_mode = mode
223+ _LOGGER .info ("Switched to dehumidify mode" )
224+ else :
225+ _LOGGER .error ("Failed to set dehumidify mode" )
198226
199227 async def async_set_humidity (self , humidity : int ) -> None :
200228 """Set new target humidity."""
@@ -212,6 +240,9 @@ async def async_set_humidity(self, humidity: int) -> None:
212240
213241 async def async_turn_on (self , ** kwargs ) -> None :
214242 """Turn the device on."""
243+ # Set fan speed to high
244+ await self ._client .async_write_register (REG_FAN_SPEED , FAN_SPEED_HIGH )
245+
215246 # Set the power on
216247 result = await self ._client .async_write_register (REG_POWER , 1 )
217248 if not result :
0 commit comments