4040# Polling interval
4141SCAN_INTERVAL = timedelta (seconds = 5 )
4242
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 ()}
43+ # Preset modes
44+ PRESET_MODE_DEHUMIDIFY = "Dehumidify"
45+ PRESET_MODE_AIR_PURIFICATION = "Air Purification"
46+ PRESET_MODES = [PRESET_MODE_DEHUMIDIFY , PRESET_MODE_AIR_PURIFICATION ]
5147
5248
5349async def async_setup_entry (
@@ -75,7 +71,7 @@ class MedoleDehumidifierHumidifier(HumidifierEntity):
7571 _attr_name = None
7672 _attr_supported_features = HumidifierEntityFeature .MODES
7773 _attr_device_class = HumidifierDeviceClass .DEHUMIDIFIER
78- _attr_available_modes = list ( REVERSE_MODES . keys ())
74+ _attr_available_modes = PRESET_MODES
7975 _attr_min_humidity = MIN_HUMIDITY
8076 _attr_max_humidity = MAX_HUMIDITY
8177
@@ -97,6 +93,7 @@ def __init__(self, hass, name, client):
9793 self ._attr_mode = None
9894 self ._attr_is_on = False
9995 self ._attr_action = None
96+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
10097
10198 @property
10299 def current_humidity (self ):
@@ -166,14 +163,22 @@ async def async_update(self) -> None:
166163 else :
167164 _LOGGER .error ("Failed to read humidity setpoint" )
168165
169- # Get the fan speed
170- fan_speed_result = await self ._client .async_read_register (REG_FAN_SPEED )
166+ # Check which mode is active (dehumidify or air purification)
167+ dehumidify_result = await self ._client .async_read_register (
168+ REG_DEHUMIDIFY_MODE
169+ )
170+ purify_result = await self ._client .async_read_register (REG_PURIFY_MODE )
171171
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" )
172+ if dehumidify_result and purify_result :
173+ dehumidify_on = dehumidify_result .registers [0 ] == 1
174+ purify_on = purify_result .registers [0 ] == 1
175+
176+ if purify_on :
177+ self ._current_preset = PRESET_MODE_AIR_PURIFICATION
178+ self ._attr_mode = PRESET_MODE_AIR_PURIFICATION
179+ else :
180+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
181+ self ._attr_mode = PRESET_MODE_DEHUMIDIFY
177182
178183 # Get the current humidity
179184 humidity_result = await self ._client .async_read_register (REG_HUMIDITY_1 )
@@ -185,16 +190,36 @@ async def async_update(self) -> None:
185190
186191 async def async_set_mode (self , mode : str ) -> None :
187192 """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 )
193+ if mode == PRESET_MODE_AIR_PURIFICATION :
194+ # Switch to air purification mode with high fan speed
195+ await self ._client .async_write_register (
196+ REG_FAN_SPEED , FAN_SPEED_HIGH
197+ )
198+ await self ._client .async_write_register (REG_DEHUMIDIFY_MODE , 0 )
199+ success = await self ._client .async_write_register (
200+ REG_PURIFY_MODE , 1
201+ )
202+ if success :
203+ self ._current_preset = PRESET_MODE_AIR_PURIFICATION
204+ self ._attr_mode = mode
205+ _LOGGER .info ("Switched to air purification mode" )
206+ else :
207+ _LOGGER .error ("Failed to set air purification mode" )
208+ elif mode == PRESET_MODE_DEHUMIDIFY :
209+ # Switch to dehumidify mode with high fan speed
210+ await self ._client .async_write_register (
211+ REG_FAN_SPEED , FAN_SPEED_HIGH
212+ )
213+ await self ._client .async_write_register (REG_PURIFY_MODE , 0 )
214+ success = await self ._client .async_write_register (
215+ REG_DEHUMIDIFY_MODE , 1
216+ )
217+ if success :
218+ self ._current_preset = PRESET_MODE_DEHUMIDIFY
219+ self ._attr_mode = mode
220+ _LOGGER .info ("Switched to dehumidify mode" )
221+ else :
222+ _LOGGER .error ("Failed to set dehumidify mode" )
198223
199224 async def async_set_humidity (self , humidity : int ) -> None :
200225 """Set new target humidity."""
@@ -212,6 +237,9 @@ async def async_set_humidity(self, humidity: int) -> None:
212237
213238 async def async_turn_on (self , ** kwargs ) -> None :
214239 """Turn the device on."""
240+ # Set fan speed to high
241+ await self ._client .async_write_register (REG_FAN_SPEED , FAN_SPEED_HIGH )
242+
215243 # Set the power on
216244 result = await self ._client .async_write_register (REG_POWER , 1 )
217245 if not result :
0 commit comments