mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Make pid cimate respect mode
This commit is contained in:
parent
0a92405f2d
commit
31939918dc
2 changed files with 16 additions and 5 deletions
|
@ -90,6 +90,18 @@ void PIDClimate::dump_config() {
|
|||
this->autotuner_->dump_config();
|
||||
}
|
||||
}
|
||||
float PIDClimate::value_by_mode_(float value) {
|
||||
switch (this->mode) {
|
||||
case climate::CLIMATE_MODE_OFF:
|
||||
return 0.0f;
|
||||
case climate::CLIMATE_MODE_HEAT:
|
||||
return std::max(0.0f, value);
|
||||
case climate::CLIMATE_MODE_COOL:
|
||||
return std::min(0.0f, value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
void PIDClimate::write_output_(float value) {
|
||||
this->output_value_ = value;
|
||||
|
||||
|
@ -147,11 +159,7 @@ void PIDClimate::update_pid_() {
|
|||
}
|
||||
}
|
||||
|
||||
if (this->mode == climate::CLIMATE_MODE_OFF) {
|
||||
this->write_output_(0.0);
|
||||
} else {
|
||||
this->write_output_(value);
|
||||
}
|
||||
this->write_output_(this->value_by_mode_(value));
|
||||
|
||||
if (this->do_publish_)
|
||||
this->publish_state();
|
||||
|
|
|
@ -84,6 +84,9 @@ class PIDClimate : public climate::Climate, public Component {
|
|||
bool supports_cool_() const { return this->cool_output_ != nullptr; }
|
||||
bool supports_heat_() const { return this->heat_output_ != nullptr; }
|
||||
|
||||
/// Return cloest possible output value with respect to mode
|
||||
float value_by_mode_(float value) const;
|
||||
|
||||
void write_output_(float value);
|
||||
|
||||
/// The sensor used for getting the current temperature
|
||||
|
|
Loading…
Reference in a new issue