ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
float_output.cpp
Go to the documentation of this file.
1#include "float_output.h"
3#include "esphome/core/log.h"
4
5namespace esphome::output {
6
7static const char *const TAG = "output.float";
8
9#ifdef USE_OUTPUT_FLOAT_POWER_SCALING
10void FloatOutput::set_max_power(float max_power) {
11 this->max_power_ = clamp(max_power, this->min_power_, 1.0f); // Clamp to min_power <= max <= 1.0
12}
13
14void FloatOutput::set_min_power(float min_power) {
15 this->min_power_ = clamp(min_power, 0.0f, this->max_power_); // Clamp to 0.0 <= min <= max_power
16}
17#endif
18
20 state = clamp(state, 0.0f, 1.0f);
21
22#ifdef USE_POWER_SUPPLY
23 if (state > 0.0f) { // ON
24 this->power_.request();
25 } else { // OFF
26 this->power_.unrequest();
27 }
28#endif
29
30#ifdef USE_OUTPUT_FLOAT_POWER_SCALING
31 if (state != 0.0f || !this->zero_means_zero_) // regardless of min_power_, 0.0 means off
32 state = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
33#endif
34
35 if (this->is_inverted())
36 state = 1.0f - state;
37 this->write_state(state);
38}
39
40void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); }
41
42} // namespace esphome::output
power_supply::PowerSupplyRequester power_
bool is_inverted() const
Return whether this binary output is inverted.
void set_level(float state)
Set the level of this float output, this is called from the front-end.
void set_max_power(float max_power)
Set the maximum power output of this component.
void write_state(bool state) override
Implement BinarySensor's write_enabled; this should never be called.
void set_min_power(float min_power)
Set the minimum power output of this component.
bool state
Definition fan.h:2