ESPHome 2026.5.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);
19 LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj);
20}
21
23 this->set_has_state(true);
24 this->state = state;
25 ESP_LOGV(TAG, "'%s' >> %.2f", this->get_name().c_str(), state);
26 this->state_callback_.call(state);
27#if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY)
28 ControllerRegistry::notify_number_update(this);
29#endif
30}
31
32} // namespace esphome::number
const StringRef & get_name() const
Definition entity_base.h:71
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
LazyCallbackManager< void(float)> state_callback_
Definition number.h:54
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
const char * tag
Definition log.h:74