Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix mode selection and display for humidifier Dual 200S (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlebourl authored Apr 1, 2022
1 parent f36fc12 commit d2f06b0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions custom_components/vesync/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import logging

from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.components.humidifier.const import SUPPORT_MODES
from homeassistant.components.humidifier.const import (
MODE_AUTO,

This comment has been minimized.

Copy link
@borpin

borpin Apr 3, 2022

Contributor

Are these part of the translations? If so, does the API respect the language setting or does it always return English?

The humidifiers seem to have a manual mode which does not exist in the HA Modes. I'd suggest that MODE_NORMAL is a better fit as a match, than Boost.

This comment has been minimized.

Copy link
@vlebourl

vlebourl Apr 3, 2022

Author Owner

These are part of the core humidifier component. They indeed are translated, depending on your HA instance language.

This comment has been minimized.

Copy link
@borpin

borpin Apr 3, 2022

Contributor

But the set_mode command will be expecting the specific strings (as defined in the device details. If it sends the string boost rather than manual to the library, the set command will fail.

MODE_BOOST,
MODE_SLEEP,
SUPPORT_MODES,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand All @@ -16,6 +21,10 @@
MAX_HUMIDITY = 80
MIN_HUMIDITY = 30

MODE_MANUAL = "manual"

MODES = [MODE_AUTO, MODE_BOOST, MODE_SLEEP]


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -68,7 +77,7 @@ def __init__(self, humidifier):
@property
def available_modes(self):
"""Return the available mist modes."""
return self.device.config_dict["mist_modes"]
return MODES

@property
def supported_features(self):
Expand All @@ -83,8 +92,14 @@ def target_humidity(self):
@property
def mode(self):
"""Get the current preset mode."""
if self.smarthumidifier.details["mode"] in self.available_modes:
return self.smarthumidifier.details["mode"]
if self.smarthumidifier.details["mode"] == MODE_AUTO:

This comment has been minimized.

Copy link
@borpin

borpin Apr 3, 2022

Contributor

I think you should still check if the mode is in an available mode.

I don't agree with the logic here. My Dual 200S only has auto and manual modes, so Boost is inappropriate. the HA mode of normal is the closest. Going from auto to manual should be to mist_level 1 I'd suggest.

I think using the HA modes could also be problematic when trying to set the mode of the humidifier.

This comment has been minimized.

Copy link
@vlebourl

vlebourl Apr 3, 2022

Author Owner

mine has auto, low and high, so boost is for high and sleep for low. Renaming to sleep and normal is possible, but doesn't change much.

This comment has been minimized.

Copy link
@vlebourl

vlebourl Apr 3, 2022

Author Owner

low and high correspond to mist level 1 and 2 when in manual mode.

This comment has been minimized.

Copy link
@borpin

borpin Apr 3, 2022

Contributor

But does the library accept those strings and set the mode correctly?

I simply got errors that the mode was not recognised (I've reverted the commit in my fork).

return MODE_AUTO
if self.smarthumidifier.details["mode"] == MODE_MANUAL:
return (
MODE_SLEEP
if self.smarthumidifier.details["mist_level"] == 1
else MODE_BOOST
)
return None

@property
Expand Down Expand Up @@ -138,10 +153,8 @@ def set_mode(self, mode):
raise ValueError(
"{mode} is not one of the valid available modes: {self.available_modes}"
)
if mode == "manual":
self.smarthumidifier.set_mist_level(
self.smarthumidifier.details["mist_level"]
)
if mode != MODE_AUTO:
self.smarthumidifier.set_mist_level(1 if mode == MODE_SLEEP else 2)
else:
self.smarthumidifier.set_humidity_mode(mode)
self.schedule_update_ha_state()
Expand Down

0 comments on commit d2f06b0

Please sign in to comment.