1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Improve Tuya HVACMode handling (#158042)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
epenet
2025-12-09 21:17:57 +01:00
committed by GitHub
parent ad1ba629c5
commit bc031e7a81
2 changed files with 15 additions and 15 deletions

View File

@@ -476,23 +476,23 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
return self._read_wrapper(self._target_humidity_wrapper)
@property
def hvac_mode(self) -> HVACMode:
def hvac_mode(self) -> HVACMode | None:
"""Return hvac mode."""
# If the switch is off, hvac mode is off as well.
# Unless the switch doesn't exists of course...
# If the switch is off, hvac mode is off.
switch_status: bool | None
if (switch_status := self._read_wrapper(self._switch_wrapper)) is False:
return HVACMode.OFF
# If the mode is known and maps to an HVAC mode, return it.
if (mode := self._read_wrapper(self._hvac_mode_wrapper)) and (
hvac_mode := TUYA_HVAC_TO_HA.get(mode)
):
return hvac_mode
# If we don't have a mode wrapper, return switch only mode.
if self._hvac_mode_wrapper is None:
if switch_status is True:
return self.entity_description.switch_only_hvac_mode
return None
# If hvac_mode is unknown, return the switch only mode.
if switch_status:
return self.entity_description.switch_only_hvac_mode
return HVACMode.OFF
# If we do have a mode wrapper, check if the mode maps to an HVAC mode.
if (hvac_status := self._read_wrapper(self._hvac_mode_wrapper)) is None:
return None
return TUYA_HVAC_TO_HA.get(hvac_status)
@property
def preset_mode(self) -> str | None:

View File

@@ -651,7 +651,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
})
# ---
# name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-entry]
@@ -713,7 +713,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
})
# ---
# name: test_platform_setup_and_discovery[climate.kabinet-entry]
@@ -1007,7 +1007,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
})
# ---
# name: test_platform_setup_and_discovery[climate.polotentsosushitel-entry]