ESPHome  2024.11.0
number.cpp
Go to the documentation of this file.
1 #include "number.h"
2 
3 namespace esphome {
4 namespace opentherm {
5 
6 static const char *const TAG = "opentherm.number";
7 
8 void OpenthermNumber::control(float value) {
9  this->publish_state(value);
10 
11  if (this->restore_value_)
12  this->pref_.save(&value);
13 }
14 
16  float value;
17  if (!this->restore_value_) {
18  value = this->initial_value_;
19  } else {
21  if (!this->pref_.load(&value)) {
22  if (!std::isnan(this->initial_value_)) {
23  value = this->initial_value_;
24  } else {
25  value = this->traits.get_min_value();
26  }
27  }
28  }
29  this->publish_state(value);
30 }
31 
33  LOG_NUMBER("", "OpenTherm Number", this);
34  ESP_LOGCONFIG(TAG, " Restore value: %d", this->restore_value_);
35  ESP_LOGCONFIG(TAG, " Initial value: %.2f", this->initial_value_);
36  ESP_LOGCONFIG(TAG, " Current value: %.2f", this->state);
37 }
38 
39 } // namespace opentherm
40 } // namespace esphome
void publish_state(float state)
Definition: number.cpp:9
bool save(const T *src)
Definition: preferences.h:21
ESPPreferences * global_preferences
ESPPreferenceObject pref_
Definition: number.h:21
NumberTraits traits
Definition: number.h:49
void control(float value) override
Definition: number.cpp:8
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint32_t get_object_id_hash()
Definition: entity_base.cpp:76