[tuya] Fixed hysteresis bug for Tuya climate (#16832)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
i-am-no-magic
2026-06-05 23:37:40 +02:00
committed by GitHub
parent b63e327ae3
commit 913b9f5ca4

View File

@@ -513,14 +513,14 @@ void TuyaClimate::compute_state_() {
} else {
// Fallback to active state calc based on temp and hysteresis
const float temp_diff = this->target_temperature - this->current_temperature;
if (std::abs(temp_diff) > this->hysteresis_) {
if (this->supports_heat_ && temp_diff > 0) {
target_action = climate::CLIMATE_ACTION_HEATING;
this->mode = climate::CLIMATE_MODE_HEAT;
} else if (this->supports_cool_ && temp_diff < 0) {
target_action = climate::CLIMATE_ACTION_COOLING;
this->mode = climate::CLIMATE_MODE_COOL;
}
if ((this->supports_heat_ && temp_diff >= this->hysteresis_) ||
(this->action == climate::CLIMATE_ACTION_HEATING && temp_diff > 0)) {
target_action = climate::CLIMATE_ACTION_HEATING;
this->mode = climate::CLIMATE_MODE_HEAT;
} else if ((this->supports_cool_ && temp_diff <= -this->hysteresis_) ||
(this->action == climate::CLIMATE_ACTION_COOLING && temp_diff < 0)) {
target_action = climate::CLIMATE_ACTION_COOLING;
this->mode = climate::CLIMATE_MODE_COOL;
}
}