Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Energy saving mode (airState.powerSave.basic) #739

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions custom_components/smartthinq_sensors/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ class ThinQSwitchEntityDescription(SwitchEntityDescription):
turn_off_fn=lambda x: x.device.set_mode_airclean(False),
turn_on_fn=lambda x: x.device.set_mode_airclean(True),
),
ThinQSwitchEntityDescription(
key=AirConditionerFeatures.MODE_REMOVE_MOISTURE,
name="Remove moisture",
icon="mdi:fan",
turn_off_fn=lambda x: x.device.set_mode_remove_moisture(False),
turn_on_fn=lambda x: x.device.set_mode_remove_moisture(True),
),
ThinQSwitchEntityDescription(
key=AirConditionerFeatures.MODE_POWER_SAVE,
name="Energy saving",
icon="mdi:leaf-circle-outline",
turn_off_fn=lambda x: x.device.set_mode_power_save(False),
turn_on_fn=lambda x: x.device.set_mode_power_save(True),
),
ThinQSwitchEntityDescription(
key=AirConditionerFeatures.MODE_JET,
name="Jet mode",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/smartthinq_sensors/wideq/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AirConditionerFeatures(StrEnum):
FILTER_MAIN_USE = "filter_main_use"
LIGHTING_DISPLAY = "lighting_display"
MODE_AIRCLEAN = "mode_airclean"
MODE_REMOVE_MOISTURE = "mode_remove_moisture"
MODE_POWER_SAVE = "mode_power_save"
MODE_AWHP_SILENT = "mode_awhp_silent"
MODE_JET = "mode_jet"
PM1 = "pm1"
Expand Down
68 changes: 64 additions & 4 deletions custom_components/smartthinq_sensors/wideq/devices/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
SUPPORT_JET_COOL = [SUPPORT_RAC_SUBMODE, "@AC_MAIN_WIND_MODE_COOL_JET_W"]
SUPPORT_JET_HEAT = [SUPPORT_RAC_SUBMODE, "@AC_MAIN_WIND_MODE_HEAT_JET_W"]
SUPPORT_AIRCLEAN = [SUPPORT_RAC_MODE, "@AIRCLEAN"]
SUPPORT_REMOVE_MOISTURE = [SUPPORT_RAC_MODE, "@AUTODRY"]
SUPPORT_POWER_SAVE = [SUPPORT_RAC_MODE, "@ENERGYSAVING"]
SUPPORT_HOT_WATER = [SUPPORT_PAC_MODE, ["@HOTWATER", "@HOTWATER_ONLY"]]
SUPPORT_LIGHT_SWITCH = [SUPPORT_LIGHT, "@RAC_88_DISPLAY_CONTROL"]
SUPPORT_LIGHT_INV_SWITCH = [SUPPORT_LIGHT, "@BRIGHTNESS_CONTROL"]
SUPPORT_LIGHT_SWITCH = [SUPPORT_LIGHT, "@BRIGHTNESS_CONTROL"]
#SUPPORT_LIGHT_INV_SWITCH = [SUPPORT_LIGHT, "@RAC_88_DISPLAY_CONTROL"]
SUPPORT_PM = [
SUPPORT_AIR_POLUTION,
["@PM1_0_SUPPORT", "@PM2_5_SUPPORT", "@PM10_SUPPORT"],
Expand Down Expand Up @@ -72,6 +74,8 @@
STATE_POWER = [STATE_POWER_V1, "airState.energy.onCurrent"]
STATE_HUMIDITY = ["SensorHumidity", "airState.humidity.current"]
STATE_MODE_AIRCLEAN = ["AirClean", "airState.wMode.airClean"]
STATE_MODE_REMOVE_MOISTURE = ["RemoveMoisture", "airState.miscFuncState.autoDry"]
STATE_MODE_POWER_SAVE = ["PowerSave", "airState.powerSave.basic"]
STATE_MODE_JET = ["Jet", "airState.wMode.jet"]
STATE_LIGHTING_DISPLAY = ["DisplayControl", "airState.lightingState.displayControl"]
STATE_AIRSENSORMON = ["SensorMon", "airState.quality.sensorMon"]
Expand Down Expand Up @@ -103,6 +107,8 @@
CMD_STATE_WDIR_VSWING = [CTRL_WIND_DIRECTION, "Set", STATE_WDIR_VSWING]
CMD_STATE_DUCT_ZONES = [CTRL_MISC, "Set", [DUCT_ZONE_V1, "airState.ductZone.control"]]
CMD_STATE_MODE_AIRCLEAN = [CTRL_BASIC, "Set", STATE_MODE_AIRCLEAN]
CMD_STATE_MODE_REMOVE_MOISTURE = [CTRL_BASIC, "Set", STATE_MODE_REMOVE_MOISTURE]
CMD_STATE_MODE_POWER_SAVE = [CTRL_BASIC, "Set", STATE_MODE_POWER_SAVE]
CMD_STATE_MODE_JET = [CTRL_BASIC, "Set", STATE_MODE_JET]
CMD_STATE_LIGHTING_DISPLAY = [CTRL_BASIC, "Set", STATE_LIGHTING_DISPLAY]
CMD_RESERVATION_SLEEP_TIME = [CTRL_BASIC, "Set", STATE_RESERVATION_SLEEP_TIME]
Expand Down Expand Up @@ -589,13 +595,23 @@ def is_mode_airclean_supported(self):
"""Return if AirClean mode is supported."""
return self._is_mode_supported(SUPPORT_AIRCLEAN)

@cached_property
def is_mode_remove_moisture_supported(self):
"""Return if RemoveMoisture mode is supported."""
return self._is_mode_supported(SUPPORT_REMOVE_MOISTURE)

@cached_property
def is_mode_power_save_supported(self):
"""Return if PowerSave mode is supported."""
return self._is_mode_supported(SUPPORT_POWER_SAVE)

@cached_property
def supported_ligth_modes(self):
"""Return light switch modes supported."""
if self._is_mode_supported(SUPPORT_LIGHT_SWITCH):
return {MODE_OFF: LIGHT_DISPLAY_OFF, MODE_ON: LIGHT_DISPLAY_ON}
if self._is_mode_supported(SUPPORT_LIGHT_INV_SWITCH):
return {MODE_OFF: LIGHT_DISPLAY_INV_OFF, MODE_ON: LIGHT_DISPLAY_INV_ON}
# if self._is_mode_supported(SUPPORT_LIGHT_INV_SWITCH):
# return {MODE_OFF: LIGHT_DISPLAY_INV_OFF, MODE_ON: LIGHT_DISPLAY_INV_ON}
Comment on lines +613 to +614
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you comment this?

Copy link
Author

@andrei-croitor andrei-croitor Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
For me, RAC_88_DISPLAY_CONTROL displayed correctly the light on switch (not inverted as I saw others users reported). Because of the "inverted" code part, in my app the values were inverted. With that code commented, it displays fine for me.
Anyway, the commit d757db5 was not part of the original pull request, after around 2 weeks I thought the pull request is not accepted so I used this fork to add some changes for my personal needs and use it on my HA.

The original pull request was only for commit https://github.com/ollo69/ha-smartthinq-sensors/pull/739/commits/4ee1db93944a204fd13fcfad13d54ca3053cf6fc1.

Thanks and regards,
Andrei

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, RAC_88_DISPLAY_CONTROL displayed correctly the light on switch (not inverted as I saw others users reported). Because of the "inverted" code part, in my app the values were inverted. With that code commented, it displays fine for me.

This is the real problem in integration development, found the correct way to make it work properly for all possible devices. We should find a way to make this option work correctly for your device without breaking others.

after around 2 weeks I thought the pull request is not accepted so I used this fork to add some changes for my personal needs and use it on my HA.

The only problem is that this year my time to work on this integration is very limited, but there are no reason to reject a PR without at least a feedback. If there are no answer just means that I had no time to analyze it, but PR are always welcome.

Please attach your device diagnostics so that I will also take a look to the display settings available to try to found a possible solution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks for your reply. I have attached the device diagnostics, and looking into it I realised I remembered incorrectly the light problem. The "@RAC_88_DISPLAY_CONTROL" is not supported at all and "@BRIGHTNESS_CONTROL" that is used in integration's code as inverted value, for me it doesn't need to be inverted.
If you prefer, I could make a new pull request with only the Energy saving mode switch stuff, but not sure when, as I don't have a lot of time until the end of the month.

Thanks and regards,
Andrei

smartthinq_sensors-26b2987ca676674af931188bf04abf81-AC Second Bedroom-09980ad75b0c1297483b0edf664cf99f.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to figure out how to manage the light option more efficiently, as it seems that each device works differently (when it works at all)

return None

@cached_property
Expand Down Expand Up @@ -750,6 +766,26 @@ async def set_mode_airclean(self, status: bool):
mode = self.model_info.enum_value(keys[2], mode_key)
await self.set(keys[0], keys[1], key=keys[2], value=mode)

async def set_mode_remove_moisture(self, status: bool):
"""Set the RemoveMoisture mode on or off."""
if not self.is_mode_remove_moisture_supported:
raise ValueError("RemoveMoisture mode not supported")

keys = self._get_cmd_keys(CMD_STATE_MODE_REMOVE_MOISTURE)
mode_key = MODE_ON if status else MODE_OFF
mode = self.model_info.enum_value(keys[2], mode_key)
await self.set(keys[0], keys[1], key=keys[2], value=mode)

async def set_mode_power_save(self, status: bool):
"""Set the PowerSave mode on or off."""
if not self.is_mode_power_save_supported:
raise ValueError("PowerSave mode not supported")

keys = self._get_cmd_keys(CMD_STATE_MODE_POWER_SAVE)
mode_key = MODE_ON if status else MODE_OFF
mode = self.model_info.enum_value(keys[2], mode_key)
await self.set(keys[0], keys[1], key=keys[2], value=mode)

async def set_mode_jet(self, status: bool):
"""Set the Jet mode on or off."""
if self.supported_mode_jet == JetModeSupport.NONE:
Expand Down Expand Up @@ -1188,6 +1224,28 @@ def mode_airclean(self):
status = value == MODE_AIRCLEAN_ON
return self._update_feature(AirConditionerFeatures.MODE_AIRCLEAN, status, False)

@property
def mode_remove_moisture(self):
"""Return RemoveMoisture Mode status."""
if not self._device.is_mode_remove_moisture_supported:
return None
key = self._get_state_key(STATE_MODE_REMOVE_MOISTURE)
if (value := self.lookup_enum(key, True)) is None:
return None
status = value == MODE_ON
return self._update_feature(AirConditionerFeatures.MODE_REMOVE_MOISTURE, status, False)

@property
def mode_power_save(self):
"""Return PowerSave Mode status."""
if not self._device.is_mode_power_save_supported:
return None
key = self._get_state_key(STATE_MODE_POWER_SAVE)
if (value := self.lookup_enum(key, True)) is None:
return None
status = value == MODE_ON
return self._update_feature(AirConditionerFeatures.MODE_POWER_SAVE, status, False)

@property
def mode_jet(self):
"""Return Jet Mode status."""
Expand Down Expand Up @@ -1397,6 +1455,8 @@ def _update_features(self):
self.pm25,
self.pm1,
self.mode_airclean,
self.mode_remove_moisture,
self.mode_power_save,
self.mode_jet,
self.lighting_display,
self.water_in_current_temp,
Expand Down