8 static const char *
const TAG =
"number";
41 const auto *
name = parent->get_name().c_str();
42 const auto &traits = parent->traits;
45 ESP_LOGW(TAG,
"'%s' - NumberCall performed without selecting an operation",
name);
49 float target_value = NAN;
50 float min_value = traits.get_min_value();
51 float max_value = traits.get_max_value();
54 ESP_LOGD(TAG,
"'%s' - Setting number value",
name);
56 ESP_LOGW(TAG,
"'%s' - No value set for NumberCall",
name);
61 if (std::isnan(min_value)) {
62 ESP_LOGW(TAG,
"'%s' - Can't set to min value through NumberCall: no min_value defined",
name);
64 target_value = min_value;
67 if (std::isnan(max_value)) {
68 ESP_LOGW(TAG,
"'%s' - Can't set to max value through NumberCall: no max_value defined",
name);
70 target_value = max_value;
73 ESP_LOGD(TAG,
"'%s' - Increment number, with%s cycling",
name, this->
cycle_ ?
"" :
"out");
74 if (!parent->has_state()) {
75 ESP_LOGW(TAG,
"'%s' - Can't increment number through NumberCall: no active state to modify",
name);
78 auto step = traits.get_step();
79 target_value = parent->state + (std::isnan(step) ? 1 : step);
80 if (target_value > max_value) {
81 if (this->
cycle_ && !std::isnan(min_value)) {
82 target_value = min_value;
84 target_value = max_value;
88 ESP_LOGD(TAG,
"'%s' - Decrement number, with%s cycling",
name, this->
cycle_ ?
"" :
"out");
89 if (!parent->has_state()) {
90 ESP_LOGW(TAG,
"'%s' - Can't decrement number through NumberCall: no active state to modify",
name);
93 auto step = traits.get_step();
94 target_value = parent->state - (std::isnan(step) ? 1 : step);
95 if (target_value < min_value) {
96 if (this->
cycle_ && !std::isnan(max_value)) {
97 target_value = max_value;
99 target_value = min_value;
104 if (target_value < min_value) {
105 ESP_LOGW(TAG,
"'%s' - Value %f must not be less than minimum %f",
name, target_value, min_value);
108 if (target_value > max_value) {
109 ESP_LOGW(TAG,
"'%s' - Value %f must not be greater than maximum %f",
name, target_value, max_value);
113 ESP_LOGD(TAG,
" New number value: %f", target_value);
value_type const & value() const
NumberCall & with_cycle(bool cycle)
NumberCall & with_operation(NumberOperation operation)
NumberCall & set_value(float value)
NumberOperation operation_
virtual void control(float value)=0
Set the value of the number, this is a virtual method that each number integration must implement...
NumberCall & number_decrement(bool cycle)
NumberCall & number_to_min()
NumberCall & with_value(float value)
Implementation of SPI Controller mode.
NumberCall & number_to_max()
NumberCall & number_increment(bool cycle)