mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[nextion] Keep the queue type name table in flash
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <vector>
|
||||
#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(){};
|
||||
|
||||
Reference in New Issue
Block a user