Skip to content

Commit bc031e7

Browse files
epenetCopilot
andauthored
Improve Tuya HVACMode handling (home-assistant#158042)
Co-authored-by: Copilot <[email protected]>
1 parent ad1ba62 commit bc031e7

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

homeassistant/components/tuya/climate.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,23 +476,23 @@ def target_humidity(self) -> int | None:
476476
return self._read_wrapper(self._target_humidity_wrapper)
477477

478478
@property
479-
def hvac_mode(self) -> HVACMode:
479+
def hvac_mode(self) -> HVACMode | None:
480480
"""Return hvac mode."""
481-
# If the switch is off, hvac mode is off as well.
482-
# Unless the switch doesn't exists of course...
481+
# If the switch is off, hvac mode is off.
482+
switch_status: bool | None
483483
if (switch_status := self._read_wrapper(self._switch_wrapper)) is False:
484484
return HVACMode.OFF
485485

486-
# If the mode is known and maps to an HVAC mode, return it.
487-
if (mode := self._read_wrapper(self._hvac_mode_wrapper)) and (
488-
hvac_mode := TUYA_HVAC_TO_HA.get(mode)
489-
):
490-
return hvac_mode
486+
# If we don't have a mode wrapper, return switch only mode.
487+
if self._hvac_mode_wrapper is None:
488+
if switch_status is True:
489+
return self.entity_description.switch_only_hvac_mode
490+
return None
491491

492-
# If hvac_mode is unknown, return the switch only mode.
493-
if switch_status:
494-
return self.entity_description.switch_only_hvac_mode
495-
return HVACMode.OFF
492+
# If we do have a mode wrapper, check if the mode maps to an HVAC mode.
493+
if (hvac_status := self._read_wrapper(self._hvac_mode_wrapper)) is None:
494+
return None
495+
return TUYA_HVAC_TO_HA.get(hvac_status)
496496

497497
@property
498498
def preset_mode(self) -> str | None:

tests/components/tuya/snapshots/test_climate.ambr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@
651651
'last_changed': <ANY>,
652652
'last_reported': <ANY>,
653653
'last_updated': <ANY>,
654-
'state': 'off',
654+
'state': 'unknown',
655655
})
656656
# ---
657657
# name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-entry]
@@ -713,7 +713,7 @@
713713
'last_changed': <ANY>,
714714
'last_reported': <ANY>,
715715
'last_updated': <ANY>,
716-
'state': 'off',
716+
'state': 'unknown',
717717
})
718718
# ---
719719
# name: test_platform_setup_and_discovery[climate.kabinet-entry]
@@ -1007,7 +1007,7 @@
10071007
'last_changed': <ANY>,
10081008
'last_reported': <ANY>,
10091009
'last_updated': <ANY>,
1010-
'state': 'off',
1010+
'state': 'unknown',
10111011
})
10121012
# ---
10131013
# name: test_platform_setup_and_discovery[climate.polotentsosushitel-entry]

0 commit comments

Comments
 (0)