mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 20:15:17 +01:00
Correctly invert the float output state (#2368)
This commit is contained in:
parent
8e36e1b92e
commit
654e31124e
1 changed files with 5 additions and 6 deletions
|
@ -31,14 +31,13 @@ void FloatOutput::set_level(float state) {
|
||||||
this->power_.unrequest();
|
this->power_.unrequest();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!(state == 0.0f && this->zero_means_zero_)) // regardless of min_power_, 0.0 means off
|
||||||
|
state = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
|
||||||
|
|
||||||
if (this->is_inverted())
|
if (this->is_inverted())
|
||||||
state = 1.0f - state;
|
state = 1.0f - state;
|
||||||
if (state == 0.0f && this->zero_means_zero_) { // regardless of min_power_, 0.0 means off
|
this->write_state(state);
|
||||||
this->write_state(state);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float adjusted_value = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
|
|
||||||
this->write_state(adjusted_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); }
|
void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); }
|
||||||
|
|
Loading…
Add table
Reference in a new issue