ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
nextion_component.cpp
Go to the documentation of this file.
1#include "nextion_component.h"
2
3namespace esphome::nextion {
4
6 if (this->variable_name_ == this->variable_name_to_send_) {
7 return; // This is a variable. no need to set color
8 }
9 this->bco_ = bco;
11 this->component_flags_.bco_is_set = true;
13}
14
16 if (this->variable_name_ == this->variable_name_to_send_) {
17 return; // This is a variable. no need to set color
18 }
19
20 this->bco2_ = bco2;
22 this->component_flags_.bco2_is_set = true;
24}
25
27 if (this->variable_name_ == this->variable_name_to_send_) {
28 return; // This is a variable. no need to set color
29 }
30 this->pco_ = pco;
32 this->component_flags_.pco_is_set = true;
34}
35
37 if (this->variable_name_ == this->variable_name_to_send_) {
38 return; // This is a variable. no need to set color
39 }
40 this->pco2_ = pco2;
42 this->component_flags_.pco2_is_set = true;
44}
45
46void NextionComponent::set_font_id(uint8_t font_id) {
47 if (this->variable_name_ == this->variable_name_to_send_) {
48 return; // This is a variable. no need to set color
49 }
50 this->font_id_ = font_id;
54}
55
57 if (this->variable_name_ == this->variable_name_to_send_) {
58 return; // This is a variable. no need to set color
59 }
60 this->component_flags_.visible = visible;
64}
65
67 if (this->nextion_->is_sleeping() || !this->nextion_->is_setup() || !this->component_flags_.visible_is_set ||
68 (!this->component_flags_.visible_needs_update && !this->component_flags_.visible)) {
69 this->needs_to_send_update_ = true;
70 return;
71 }
72
73 if (this->component_flags_.visible_needs_update || (force_update && this->component_flags_.visible_is_set)) {
74 std::string name_to_send = this->variable_name_;
75
76 size_t pos = name_to_send.find_last_of('.');
77 if (pos != std::string::npos) {
78 name_to_send = name_to_send.substr(pos + 1);
79 }
80
82
83 this->nextion_->set_component_visibility(name_to_send.c_str(), this->component_flags_.visible);
84 if (!this->component_flags_.visible) {
85 return;
86 }
88 }
89
90 if (this->component_flags_.bco_needs_update || (force_update && this->component_flags_.bco_is_set)) {
91 this->nextion_->set_component_background_color(this->variable_name_.c_str(), this->bco_);
93 }
94 if (this->component_flags_.bco2_needs_update || (force_update && this->component_flags_.bco2_is_set)) {
95 this->nextion_->set_component_pressed_background_color(this->variable_name_.c_str(), this->bco2_);
97 }
98 if (this->component_flags_.pco_needs_update || (force_update && this->component_flags_.pco_is_set)) {
99 this->nextion_->set_component_foreground_color(this->variable_name_.c_str(), this->pco_);
101 }
102 if (this->component_flags_.pco2_needs_update || (force_update && this->component_flags_.pco2_is_set)) {
103 this->nextion_->set_component_pressed_foreground_color(this->variable_name_.c_str(), this->pco2_);
105 }
106
107 if (this->component_flags_.font_id_needs_update || (force_update && this->component_flags_.font_id_is_set)) {
108 this->nextion_->set_component_font(this->variable_name_.c_str(), this->font_id_);
110 }
111}
112} // 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
struct esphome::nextion::NextionComponent::ComponentState component_flags_
size_t size_t pos
Definition helpers.h:1082