From 88be4c0389c4d0734a1d4e590ba0f0786f11ffad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Oct 2026 09:56:53 -1000 Subject: [PATCH] [nextion] Keep the queue type name table in flash --- esphome/components/nextion/nextion.cpp | 11 ++++++----- esphome/components/nextion/nextion_component.cpp | 9 +++++++++ esphome/components/nextion/nextion_component_base.h | 9 +++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index b9194b3f31c..ae92117bb03 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -326,7 +326,7 @@ void Nextion::print_queue_members_() { ESP_LOGN(TAG, "Queue null"); } else { ESP_LOGN(TAG, "Queue type: %d:%s, name: %s", i->component->get_queue_type(), - i->component->get_queue_type_string(), i->component->get_variable_name().c_str()); + LOG_STR_ARG(i->component->get_queue_type_string()), i->component->get_variable_name().c_str()); } } ESP_LOGN(TAG, "*******************************************"); @@ -672,7 +672,7 @@ void Nextion::process_nextion_commands_() { ESP_LOGE(TAG, "String return but '%s' not text sensor", component->get_variable_name().c_str()); } else { ESP_LOGN(TAG, "String resp: '%s' id: %s type: %s", to_process.c_str(), component->get_variable_name().c_str(), - component->get_queue_type_string()); + LOG_STR_ARG(component->get_queue_type_string())); component->set_state_from_string(to_process, true, false); } @@ -718,7 +718,7 @@ void Nextion::process_nextion_commands_() { component->get_queue_type()); } else { ESP_LOGN(TAG, "Numeric: %s type %d:%s val %d", component->get_variable_name().c_str(), - component->get_queue_type(), component->get_queue_type_string(), value); + component->get_queue_type(), LOG_STR_ARG(component->get_queue_type_string()), value); component->set_state_from_int(value, true, false); } @@ -936,7 +936,7 @@ void Nextion::purge_stale_queue_entries_() { for (auto it = this->nextion_queue_.begin(); it != this->nextion_queue_.end();) { if (ms - (*it)->queue_time > this->max_q_age_ms_) { NextionComponentBase *component = (*it)->component; - ESP_LOGV(TAG, "Remove old queue '%s':'%s'", component->get_queue_type_string(), + ESP_LOGV(TAG, "Remove old queue '%s':'%s'", LOG_STR_ARG(component->get_queue_type_string()), component->get_variable_name().c_str()); if (is_sleep_wake_command(component)) { @@ -1313,7 +1313,8 @@ void Nextion::add_to_get_queue(NextionComponentBase *component) { nextion_queue->component = component; nextion_queue->queue_time = App.get_loop_component_start_time(); - ESP_LOGN(TAG, "Queue %s: %s", component->get_queue_type_string(), component->get_variable_name().c_str()); + ESP_LOGN(TAG, "Queue %s: %s", LOG_STR_ARG(component->get_queue_type_string()), + component->get_variable_name().c_str()); std::string command = "get " + component->get_variable_name_to_send(); diff --git a/esphome/components/nextion/nextion_component.cpp b/esphome/components/nextion/nextion_component.cpp index f4571256165..4c0c36c6202 100644 --- a/esphome/components/nextion/nextion_component.cpp +++ b/esphome/components/nextion/nextion_component.cpp @@ -1,7 +1,16 @@ #include "nextion_component.h" +#include "esphome/core/progmem.h" namespace esphome::nextion { +PROGMEM_STRING_TABLE(NextionQueueTypeStrings, "NO_RESULT", "SENSOR", "BINARY_SENSOR", "SWITCH", "TEXT_SENSOR", + "WAVEFORM_SENSOR"); +static_assert(NextionQueueTypeStrings::COUNT == NextionQueueType::WAVEFORM_SENSOR + 1, "queue type names out of sync"); + +const LogString *NextionComponentBase::get_queue_type_string() const { + return NextionQueueTypeStrings::get_log_str(this->get_queue_type(), 0); +} + void NextionComponent::set_background_color(Color bco) { if (this->variable_name_ == this->variable_name_to_send_) { return; // This is a variable. no need to set color diff --git a/esphome/components/nextion/nextion_component_base.h b/esphome/components/nextion/nextion_component_base.h index b66c0b9e4e0..e9bdb6501d2 100644 --- a/esphome/components/nextion/nextion_component_base.h +++ b/esphome/components/nextion/nextion_component_base.h @@ -5,6 +5,10 @@ #include #include "esphome/core/defines.h" +namespace esphome { +struct LogString; +} // namespace esphome + namespace esphome::nextion { enum NextionQueueType { @@ -16,9 +20,6 @@ enum NextionQueueType { WAVEFORM_SENSOR = 5, }; -static const char *const NEXTION_QUEUE_TYPE_STRINGS[] = {"NO_RESULT", "SENSOR", "BINARY_SENSOR", - "SWITCH", "TEXT_SENSOR", "WAVEFORM_SENSOR"}; - class NextionComponentBase; class NextionQueue { @@ -82,7 +83,7 @@ class NextionComponentBase { const std::string &get_variable_name() const { return this->variable_name_; } const std::string &get_variable_name_to_send() const { return this->variable_name_to_send_; } virtual NextionQueueType get_queue_type() const { return NextionQueueType::NO_RESULT; } - virtual const char *get_queue_type_string() const { return NEXTION_QUEUE_TYPE_STRINGS[this->get_queue_type()]; } + const LogString *get_queue_type_string() const; virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion){}; virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion){}; virtual void send_state_to_nextion(){};