diff --git a/homeassistant/components/tuya/climate.py b/homeassistant/components/tuya/climate.py index 30f2238628b..74395d43d41 100644 --- a/homeassistant/components/tuya/climate.py +++ b/homeassistant/components/tuya/climate.py @@ -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: diff --git a/tests/components/tuya/snapshots/test_climate.ambr b/tests/components/tuya/snapshots/test_climate.ambr index 9937b680b2e..286f04b649f 100644 --- a/tests/components/tuya/snapshots/test_climate.ambr +++ b/tests/components/tuya/snapshots/test_climate.ambr @@ -651,7 +651,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'off', + 'state': 'unknown', }) # --- # name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-entry] @@ -713,7 +713,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'off', + 'state': 'unknown', }) # --- # name: test_platform_setup_and_discovery[climate.kabinet-entry] @@ -1007,7 +1007,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'off', + 'state': 'unknown', }) # --- # name: test_platform_setup_and_discovery[climate.polotentsosushitel-entry]