mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 11:22:24 +01:00
[number] Convert LOG_NUMBER macro to function to reduce flash usage
This commit is contained in:
@@ -6,6 +6,27 @@ namespace number {
|
|||||||
|
|
||||||
static const char *const TAG = "number";
|
static const char *const TAG = "number";
|
||||||
|
|
||||||
|
// Function implementation of LOG_NUMBER macro to reduce code size
|
||||||
|
void log_number(const char *tag, const char *prefix, const char *type, Number *obj) {
|
||||||
|
if (obj == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||||
|
|
||||||
|
if (!obj->get_icon().empty()) {
|
||||||
|
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obj->traits.get_unit_of_measurement().empty()) {
|
||||||
|
ESP_LOGCONFIG(tag, "%s Unit of Measurement: '%s'", prefix, obj->traits.get_unit_of_measurement().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obj->traits.get_device_class().empty()) {
|
||||||
|
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->traits.get_device_class().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Number::publish_state(float state) {
|
void Number::publish_state(float state) {
|
||||||
this->set_has_state(true);
|
this->set_has_state(true);
|
||||||
this->state = state;
|
this->state = state;
|
||||||
|
@@ -9,19 +9,12 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace number {
|
namespace number {
|
||||||
|
|
||||||
#define LOG_NUMBER(prefix, type, obj) \
|
// Forward declaration
|
||||||
if ((obj) != nullptr) { \
|
class Number;
|
||||||
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
|
void log_number(const char *tag, const char *prefix, const char *type, Number *obj);
|
||||||
if (!(obj)->get_icon().empty()) { \
|
|
||||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
// Macro that calls the function - kept for backward compatibility
|
||||||
} \
|
#define LOG_NUMBER(prefix, type, obj) log_number(TAG, prefix, LOG_STR_LITERAL(type), obj)
|
||||||
if (!(obj)->traits.get_unit_of_measurement().empty()) { \
|
|
||||||
ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, (obj)->traits.get_unit_of_measurement().c_str()); \
|
|
||||||
} \
|
|
||||||
if (!(obj)->traits.get_device_class().empty()) { \
|
|
||||||
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->traits.get_device_class().c_str()); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SUB_NUMBER(name) \
|
#define SUB_NUMBER(name) \
|
||||||
protected: \
|
protected: \
|
||||||
|
Reference in New Issue
Block a user