ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
number.cpp
Go to the documentation of this file.
1#include "number.h"
4#include "esphome/core/log.h"
5
6namespace esphome::number {
7
8static const char *const TAG = "number";
9
10// Function implementation of LOG_NUMBER macro to reduce code size
11void log_number(const char *tag, const char *prefix, const char *type, Number *obj) {
12 if (obj == nullptr) {
13 return;
14 }
15
16 ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
17 LOG_ENTITY_ICON(tag, prefix, *obj);
18 LOG_ENTITY_UNIT_OF_MEASUREMENT(tag, prefix, obj->traits);
19 LOG_ENTITY_DEVICE_CLASS(tag, prefix, obj->traits);
20}
21
23 this->set_has_state(true);
24 this->state = state;
25 ESP_LOGD(TAG, "'%s' >> %.2f", this->get_name().c_str(), state);
26 this->state_callback_.call(state);
27#if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY)
29#endif
30}
31
32void Number::add_on_state_callback(std::function<void(float)> &&callback) {
33 this->state_callback_.add(std::move(callback));
34}
35
36} // namespace esphome::number
static void notify_number_update(number::Number *obj)
const StringRef & get_name() const
void set_has_state(bool state)
constexpr const char * c_str() const
Definition string_ref.h:73
Base-class for all numbers.
Definition number.h:29
void publish_state(float state)
Definition number.cpp:22
NumberTraits traits
Definition number.h:39
void add_on_state_callback(std::function< void(float)> &&callback)
Definition number.cpp:32
LazyCallbackManager< void(float)> state_callback_
Definition number.h:52
uint16_t type
bool state
Definition fan.h:2
void log_number(const char *tag, const char *prefix, const char *type, Number *obj)
Definition number.cpp:11