ESPHome 2026.5.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 {
6namespace output {
7
8static const char *const TAG = "output.float";
9
10void FloatOutput::set_max_power(float max_power) {
11 this->max_power_ = clamp(max_power, this->min_power_, 1.0f); // Clamp to MIN>=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
16}
17
19 state = clamp(state, 0.0f, 1.0f);
20
21#ifdef USE_POWER_SUPPLY
22 if (state > 0.0f) { // ON
23 this->power_.request();
24 } else { // OFF
25 this->power_.unrequest();
26 }
27#endif
28
29 if (state != 0.0f || !this->zero_means_zero_) // regardless of min_power_, 0.0 means off
30 state = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
31
32 if (this->is_inverted())
33 state = 1.0f - state;
34 this->write_state(state);
35}
36
37void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); }
38
39} // namespace output
40} // namespace esphome
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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7