ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
nextion_component.cpp
Go to the documentation of this file.
1#include "nextion_component.h"
3
4namespace esphome::nextion {
5
6PROGMEM_STRING_TABLE(NextionQueueTypeStrings, "NO_RESULT", "SENSOR", "BINARY_SENSOR", "SWITCH", "TEXT_SENSOR",
7 "WAVEFORM_SENSOR");
8static_assert(NextionQueueTypeStrings::COUNT == NextionQueueType::WAVEFORM_SENSOR + 1, "queue type names out of sync");
9
11 return NextionQueueTypeStrings::get_log_str(this->get_queue_type(), 0);
12}
13
15 if (this->variable_name_ == this->variable_name_to_send_) {
16 return; // This is a variable. no need to set color
17 }
18 this->bco_ = bco;
20 this->component_flags_.bco_is_set = true;
22}
23
25 if (this->variable_name_ == this->variable_name_to_send_) {
26 return; // This is a variable. no need to set color
27 }
28
29 this->bco2_ = bco2;
31 this->component_flags_.bco2_is_set = true;
33}
34
36 if (this->variable_name_ == this->variable_name_to_send_) {
37 return; // This is a variable. no need to set color
38 }
39 this->pco_ = pco;
41 this->component_flags_.pco_is_set = true;
43}
44
46 if (this->variable_name_ == this->variable_name_to_send_) {
47 return; // This is a variable. no need to set color
48 }
49 this->pco2_ = pco2;
51 this->component_flags_.pco2_is_set = true;
53}
54
55void NextionComponent::set_font_id(uint8_t font_id) {
56 if (this->variable_name_ == this->variable_name_to_send_) {
57 return; // This is a variable. no need to set color
58 }
59 this->font_id_ = font_id;
63}
64
66 if (this->variable_name_ == this->variable_name_to_send_) {
67 return; // This is a variable. no need to set color
68 }
69 this->component_flags_.visible = visible;
73}
74
76 if (this->nextion_->is_sleeping() || !this->nextion_->is_setup() || !this->component_flags_.visible_is_set ||
77 (!this->component_flags_.visible_needs_update && !this->component_flags_.visible)) {
78 this->needs_to_send_update_ = true;
79 return;
80 }
81
82 if (this->component_flags_.visible_needs_update || (force_update && this->component_flags_.visible_is_set)) {
83 std::string name_to_send = this->variable_name_;
84
85 size_t pos = name_to_send.find_last_of('.');
86 if (pos != std::string::npos) {
87 name_to_send = name_to_send.substr(pos + 1);
88 }
89
91
92 this->nextion_->set_component_visibility(name_to_send.c_str(), this->component_flags_.visible);
93 if (!this->component_flags_.visible) {
94 return;
95 }
97 }
98
99 if (this->component_flags_.bco_needs_update || (force_update && this->component_flags_.bco_is_set)) {
100 this->nextion_->set_component_background_color(this->variable_name_.c_str(), this->bco_);
102 }
103 if (this->component_flags_.bco2_needs_update || (force_update && this->component_flags_.bco2_is_set)) {
104 this->nextion_->set_component_pressed_background_color(this->variable_name_.c_str(), this->bco2_);
106 }
107 if (this->component_flags_.pco_needs_update || (force_update && this->component_flags_.pco_is_set)) {
108 this->nextion_->set_component_foreground_color(this->variable_name_.c_str(), this->pco_);
110 }
111 if (this->component_flags_.pco2_needs_update || (force_update && this->component_flags_.pco2_is_set)) {
112 this->nextion_->set_component_pressed_foreground_color(this->variable_name_.c_str(), this->pco2_);
114 }
115
116 if (this->component_flags_.font_id_needs_update || (force_update && this->component_flags_.font_id_is_set)) {
117 this->nextion_->set_component_font(this->variable_name_.c_str(), this->font_id_);
119 }
120}
121} // namespace esphome::nextion
virtual void set_component_foreground_color(const char *component, Color color)=0
virtual void set_component_pressed_background_color(const char *component, Color color)=0
virtual void set_component_background_color(const char *component, Color color)=0
virtual void set_component_font(const char *component, uint8_t font_id)=0
virtual void set_component_visibility(const char *component, bool show)=0
virtual void set_component_pressed_foreground_color(const char *component, Color color)=0
const LogString * get_queue_type_string() const
virtual NextionQueueType get_queue_type() const
struct esphome::nextion::NextionComponent::ComponentState component_flags_
PROGMEM_STRING_TABLE(NextionQueueTypeStrings, "NO_RESULT", "SENSOR", "BINARY_SENSOR", "SWITCH", "TEXT_SENSOR", "WAVEFORM_SENSOR")
size_t size_t pos
Definition helpers.h:1333