ESPHome 2025.5.0
Loading...
Searching...
No Matches
float_output.cpp
Go to the documentation of this file.
1#include "float_output.h"
2#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
14float FloatOutput::get_max_power() const { return this->max_power_; }
15
16void FloatOutput::set_min_power(float min_power) {
17 this->min_power_ = clamp(min_power, 0.0f, this->max_power_); // Clamp to 0.0>=MIN>=MAX
18}
19
20void FloatOutput::set_zero_means_zero(bool zero_means_zero) { this->zero_means_zero_ = zero_means_zero; }
21
22float FloatOutput::get_min_power() const { return this->min_power_; }
23
25 state = clamp(state, 0.0f, 1.0f);
26
27#ifdef USE_POWER_SUPPLY
28 if (state > 0.0f) { // ON
29 this->power_.request();
30 } else { // OFF
31 this->power_.unrequest();
32 }
33#endif
34
35 if (state != 0.0f || !this->zero_means_zero_) // regardless of min_power_, 0.0 means off
36 state = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
37
38 if (this->is_inverted())
39 state = 1.0f - state;
40 this->write_state(state);
41}
42
43void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); }
44
45} // namespace output
46} // 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.
float get_min_power() const
Get the minimum power output.
void set_max_power(float max_power)
Set the maximum power output of this component.
void set_zero_means_zero(bool zero_means_zero)
Sets this output to ignore min_power for a 0 state.
float get_max_power() const
Get the maximum power output.
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:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition helpers.h:101