Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions homeassistant/components/tuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,23 @@ def target_humidity(self) -> int | None:
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:
Expand Down
6 changes: 3 additions & 3 deletions tests/components/tuya/snapshots/test_climate.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d7woucobqi8ncacf does not expose switch or mode wrapper.

})
# ---
# name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-entry]
Expand Down Expand Up @@ -713,7 +713,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

B0eP8qYAdpUo4yR9 does not expose switch or mode wrapper.

})
# ---
# name: test_platform_setup_and_discovery[climate.kabinet-entry]
Expand Down Expand Up @@ -1007,7 +1007,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5ls2jw49hpczwqng does not expose switch or mode wrapper.

})
# ---
# name: test_platform_setup_and_discovery[climate.polotentsosushitel-entry]
Expand Down
Loading