1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-01 09:32:21 +01:00

[number] Convert LOG_NUMBER macro to function to reduce flash usage (#10293)

This commit is contained in:
J. Nick Koston
2025-08-19 21:36:05 -05:00
committed by GitHub
parent 4ccc6aee09
commit e2a9b85924
2 changed files with 25 additions and 13 deletions

View File

@@ -6,6 +6,27 @@ namespace 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) {
this->set_has_state(true);
this->state = state;