Keep output_value_ unmodified from PID to match docs and be able to write correct output when user changes the mode.

This commit is contained in:
Anton Sergunov 2024-11-13 14:08:12 +00:00
parent 31939918dc
commit 204e72da35
2 changed files with 6 additions and 6 deletions

View file

@ -47,8 +47,7 @@ void PIDClimate::control(const climate::ClimateCall &call) {
this->target_temperature = *call.get_target_temperature();
// If switching to off mode, set output immediately
if (this->mode == climate::CLIMATE_MODE_OFF)
this->write_output_(0.0f);
this->write_output_();
this->publish_state();
}
@ -102,8 +101,8 @@ float PIDClimate::value_by_mode_(float value) {
return value;
}
}
void PIDClimate::write_output_(float value) {
this->output_value_ = value;
void PIDClimate::write_output_() {
const float value = this->value_by_mode_(this->output_value_);
// first ensure outputs are off (both outputs not active at the same time)
if (this->supports_cool_() && value >= 0)
@ -159,7 +158,8 @@ void PIDClimate::update_pid_() {
}
}
this->write_output_(this->value_by_mode_(value));
this->output_value_ = value;
this->write_output_();
if (this->do_publish_)
this->publish_state();

View file

@ -87,7 +87,7 @@ class PIDClimate : public climate::Climate, public Component {
/// Return cloest possible output value with respect to mode
float value_by_mode_(float value) const;
void write_output_(float value);
void write_output_();
/// The sensor used for getting the current temperature
sensor::Sensor *sensor_;