Skip to content

Commit

Permalink
Use awhpTempSwitch to determinate climate temperature control (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 committed Dec 17, 2023
1 parent 87f4883 commit e4a6c05
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
11 changes: 1 addition & 10 deletions custom_components/smartthinq_sensors/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,7 @@ def preset_modes(self) -> list[str] | None:
@property
def current_temperature(self) -> float:
"""Return the current temperature."""
curr_temp = None
if self._device.is_air_to_water:
curr_temp = self._api.state.device_features.get(
AirConditionerFeatures.WATER_OUT_TEMP
)
if curr_temp is None:
curr_temp = self._api.state.device_features.get(
AirConditionerFeatures.ROOM_TEMP
)
return curr_temp
return self._api.state.current_temp

@property
def current_humidity(self) -> int | None:
Expand Down
8 changes: 5 additions & 3 deletions custom_components/smartthinq_sensors/wideq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def refresh(self, query_device=False) -> Any | None:
continue

except core_exc.FailedRequestError:
self._raise_error("Status update request failed", debug_count=3)
self._raise_error("Status update request failed", debug_count=2)

except core_exc.DeviceNotFound:
self._raise_error(
Expand Down Expand Up @@ -224,13 +224,15 @@ async def refresh(self, query_device=False) -> Any | None:
except (asyncio.TimeoutError, aiohttp.ServerTimeoutError) as exc:
# These are network errors, refresh client is not required
self._raise_error(
"Connection to ThinQ failed. Timeout error", exc=exc, debug_count=3
"Connection to ThinQ failed. Timeout error", exc=exc, debug_count=2
)

except aiohttp.ClientError as exc:
# These are network errors, refresh client is not required
self._raise_error(
"Connection to ThinQ failed. Network connection error", exc=exc
"Connection to ThinQ failed. Network connection error",
exc=exc,
debug_count=2,
)

except Exception as exc: # pylint: disable=broad-except
Expand Down
38 changes: 34 additions & 4 deletions custom_components/smartthinq_sensors/wideq/devices/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
CMD_RESERVATION_SLEEP_TIME = [CTRL_BASIC, "Set", STATE_RESERVATION_SLEEP_TIME]

# AWHP Section
STATE_AWHP_TEMP_MODE = ["AwhpTempSwitch", "airState.miscFuncState.awhpTempSwitch"]
STATE_WATER_IN_TEMP = ["WaterInTempCur", "airState.tempState.inWaterCurrent"]
STATE_WATER_OUT_TEMP = ["WaterTempCur", "airState.tempState.outWaterCurrent"]
STATE_WATER_MIN_TEMP = ["WaterTempCoolMin", "airState.tempState.waterTempCoolMin"]
Expand Down Expand Up @@ -150,6 +151,9 @@
MODE_AIRCLEAN_OFF = "@AC_MAIN_AIRCLEAN_OFF_W"
MODE_AIRCLEAN_ON = "@AC_MAIN_AIRCLEAN_ON_W"

AWHP_MODE_AIR = "@AIR"
AWHP_MODE_WATER = "@WATER"

ZONE_OFF = "0"
ZONE_ON = "1"
ZONE_ST_CUR = "current"
Expand Down Expand Up @@ -374,7 +378,8 @@ def _supported_on_operation(self):
def _temperature_range(self):
"""Get valid temperature range for model."""

if self.is_air_to_water:
temp_mode = self._status.awhp_temp_mode
if temp_mode and temp_mode == AWHP_MODE_WATER:
min_temp = self._status.water_target_min_temp or AWHP_MIN_TEMP
max_temp = self._status.water_target_max_temp or AWHP_MAX_TEMP
else:
Expand Down Expand Up @@ -967,6 +972,7 @@ def __init__(self, device: AirConditionerDevice, data: dict | None = None):
self._operation = None
self._airmon_on = None
self._filter_use_time_inverted = True
self._current_temp = None

def _str_to_temp(self, str_temp):
"""Convert a string to either an `int` or a `float` temperature."""
Expand Down Expand Up @@ -1107,12 +1113,25 @@ def is_vertical_swing_on(self):
return value == MODE_ON

@property
def current_temp(self):
"""Return current temperature."""
def room_temp(self):
"""Return room temperature."""
key = self._get_state_key(STATE_CURRENT_TEMP)
value = self._str_to_temp(self._data.get(key))
return self._update_feature(AirConditionerFeatures.ROOM_TEMP, value, False)

@property
def current_temp(self):
"""Return current temperature."""
if self._current_temp is None:
curr_temp = None
mode = self.awhp_temp_mode
if mode and mode == AWHP_MODE_WATER:
curr_temp = self.water_out_current_temp
if curr_temp is None:
curr_temp = self.room_temp
self._current_temp = curr_temp
return self._current_temp

@property
def target_temp(self):
"""Return target temperature."""
Expand Down Expand Up @@ -1266,6 +1285,17 @@ def pm25(self):
AirConditionerFeatures.PM25, value, False, allow_none=True
)

@property
def awhp_temp_mode(self):
"""Return if AWHP is set in air or water mode."""
if not self._device.is_air_to_water:
return None
key = self._get_state_key(STATE_AWHP_TEMP_MODE)
if (value := self.lookup_enum(key, True)) is not None:
if value == AWHP_MODE_AIR:
return AWHP_MODE_AIR
return AWHP_MODE_WATER

@property
def water_in_current_temp(self):
"""Return AWHP in water current temperature."""
Expand Down Expand Up @@ -1358,7 +1388,7 @@ def reservation_sleep_time(self):

def _update_features(self):
_ = [
self.current_temp,
self.room_temp,
self.energy_current,
self.filters_life,
self.humidity,
Expand Down

0 comments on commit e4a6c05

Please sign in to comment.