Skip to content

Commit

Permalink
Refactor hvac mode and action states check. #146
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Feb 24, 2024
1 parent 1b8b196 commit bcf5358
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions custom_components/localtuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ def max_temp(self):
@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
if not self._state:
return HVACMode.OFF

return self._hvac_mode

@property
Expand All @@ -276,6 +279,9 @@ def hvac_modes(self):
@property
def hvac_action(self):
"""Return the current running hvac operation if supported."""
if not self._state:
return HVACAction.OFF

if not self._conf_hvac_action_dp:
if self._hvac_mode == HVACMode.COOL:
self._hvac_action = HVACAction.COOLING
Expand Down Expand Up @@ -421,27 +427,23 @@ def status_updated(self):
else:
self._preset_mode = PRESET_NONE

# If device is off there is no needs to check the states.
if not self._state:
return

# Update the HVAC Mode
if self.has_config(CONF_HVAC_MODE_DP):
if not self._state:
self._hvac_mode = HVACMode.OFF
else:
for ha_hvac, tuya_value in self._hvac_mode_set.items():
if self.dp_value(CONF_HVAC_MODE_DP) == tuya_value:
self._hvac_mode = ha_hvac
break
else:
# in case hvac mode and preset share the same dp
self._hvac_mode = HVACMode.AUTO
for ha_hvac, tuya_value in self._hvac_mode_set.items():
if self.dp_value(CONF_HVAC_MODE_DP) == tuya_value:
self._hvac_mode = ha_hvac
break

# Update the current action
if not self._state:
self._hvac_action = HVACAction.OFF
else:
if self.has_config(CONF_HVAC_ACTION_DP):
for ha_action, tuya_value in self._conf_hvac_action_set.items():
if self.dp_value(CONF_HVAC_ACTION_DP) == tuya_value:
self._hvac_action = ha_action
if self.has_config(CONF_HVAC_ACTION_DP):
for ha_action, tuya_value in self._conf_hvac_action_set.items():
if self.dp_value(CONF_HVAC_ACTION_DP) == tuya_value:
self._hvac_action = ha_action
break


async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaClimate, flow_schema)

0 comments on commit bcf5358

Please sign in to comment.