Skip to content

Commit a820266

Browse files
committed
Expose air purifying mode
1 parent db034c6 commit a820266

2 files changed

Lines changed: 86 additions & 30 deletions

File tree

custom_components/medole/humidifier.py

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
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,
@@ -40,14 +38,10 @@
4038
# Polling interval
4139
SCAN_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

5347
async 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:

custom_components/medole/sensor.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
from .const import (
2121
CONF_NAME,
2222
DOMAIN,
23+
REG_DEHUMIDIFY_MODE,
2324
REG_FAN_ALARM_HOURS,
2425
REG_FAN_OPERATION_HOURS,
2526
REG_HUMIDITY_1,
2627
REG_HUMIDITY_2,
2728
REG_OPERATION_STATUS,
2829
REG_PIPE_TEMPERATURE,
30+
REG_PURIFY_MODE,
2931
REG_TEMPERATURE_1,
3032
REG_TEMPERATURE_2,
3133
STATUS_COMPRESSOR_ON,
@@ -215,6 +217,8 @@ def __init__(self, hass, name, client):
215217
super().__init__(hass, name, client, "status")
216218
self._attr_name = "Status"
217219
self._status_value = None
220+
self._dehumidify_mode = None
221+
self._purify_mode = None
218222

219223
@property
220224
def extra_state_attributes(self):
@@ -228,6 +232,8 @@ def extra_state_attributes(self):
228232
return {
229233
"compressor_on": bool(lo_byte & STATUS_COMPRESSOR_ON),
230234
"fan_on": bool(lo_byte & STATUS_FAN_ON),
235+
"dehumidify_mode": bool(self._dehumidify_mode),
236+
"air_purification_mode": bool(self._purify_mode),
231237
"pipe_temp_error": bool(lo_byte & STATUS_PIPE_TEMP_ERROR),
232238
"humidity_sensor_error": bool(
233239
lo_byte & STATUS_HUMIDITY_SENSOR_ERROR
@@ -249,6 +255,19 @@ async def async_update(self) -> None:
249255
if result:
250256
self._status_value = result.registers[0]
251257

258+
# Read mode registers
259+
dehumidify_result = await self._client.async_read_register(
260+
REG_DEHUMIDIFY_MODE
261+
)
262+
purify_result = await self._client.async_read_register(
263+
REG_PURIFY_MODE
264+
)
265+
266+
if dehumidify_result:
267+
self._dehumidify_mode = dehumidify_result.registers[0] == 1
268+
if purify_result:
269+
self._purify_mode = purify_result.registers[0] == 1
270+
252271
# Set the state based on errors
253272
errors = []
254273
lo_byte = self._status_value & 0xFF
@@ -272,9 +291,15 @@ async def async_update(self) -> None:
272291
elif lo_byte & STATUS_COMPRESSOR_ON:
273292
self._attr_native_value = "Dehumidifying"
274293
elif lo_byte & STATUS_FAN_ON:
275-
self._attr_native_value = "Fan Only"
294+
# Fan running - check mode
295+
if self._purify_mode and not self._dehumidify_mode:
296+
self._attr_native_value = "Air Purification"
297+
else:
298+
self._attr_native_value = "Fan Only"
276299
else:
277300
self._attr_native_value = "Idle"
278301
else:
279302
self._attr_native_value = "Communication Error"
280303
self._status_value = None
304+
self._dehumidify_mode = None
305+
self._purify_mode = None

0 commit comments

Comments
 (0)