ESPHome 2025.6.3
Loading...
Searching...
No Matches
number.cpp
Go to the documentation of this file.
1#include "number.h"
2
3namespace esphome {
4namespace opentherm {
5
6static const char *const TAG = "opentherm.number";
7
8void 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,
35 " Restore value: %d\n"
36 " Initial value: %.2f\n"
37 " Current value: %.2f",
38 this->restore_value_, this->initial_value_, this->state);
39}
40
41} // namespace opentherm
42} // namespace esphome
bool save(const T *src)
Definition preferences.h:21
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_object_id_hash()
void publish_state(float state)
Definition number.cpp:9
NumberTraits traits
Definition number.h:49
ESPPreferenceObject pref_
Definition number.h:21
void control(float value) override
Definition number.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
ESPPreferences * global_preferences