ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
nextion_component.cpp
Go to the documentation of this file.
1#include "nextion_component.h"
2
3namespace esphome {
4namespace nextion {
5
7 if (this->variable_name_ == this->variable_name_to_send_) {
8 return; // This is a variable. no need to set color
9 }
10 this->bco_ = bco;
12 this->component_flags_.bco_is_set = true;
14}
15
17 if (this->variable_name_ == this->variable_name_to_send_) {
18 return; // This is a variable. no need to set color
19 }
20
21 this->bco2_ = bco2;
23 this->component_flags_.bco2_is_set = true;
25}
26
28 if (this->variable_name_ == this->variable_name_to_send_) {
29 return; // This is a variable. no need to set color
30 }
31 this->pco_ = pco;
33 this->component_flags_.pco_is_set = true;
35}
36
38 if (this->variable_name_ == this->variable_name_to_send_) {
39 return; // This is a variable. no need to set color
40 }
41 this->pco2_ = pco2;
43 this->component_flags_.pco2_is_set = true;
45}
46
47void NextionComponent::set_font_id(uint8_t font_id) {
48 if (this->variable_name_ == this->variable_name_to_send_) {
49 return; // This is a variable. no need to set color
50 }
51 this->font_id_ = font_id;
55}
56
58 if (this->variable_name_ == this->variable_name_to_send_) {
59 return; // This is a variable. no need to set color
60 }
61 this->component_flags_.visible = visible;
65}
66
68 if (this->nextion_->is_sleeping() || !this->nextion_->is_setup() || !this->component_flags_.visible_is_set ||
69 (!this->component_flags_.visible_needs_update && !this->component_flags_.visible)) {
70 this->needs_to_send_update_ = true;
71 return;
72 }
73
74 if (this->component_flags_.visible_needs_update || (force_update && this->component_flags_.visible_is_set)) {
75 std::string name_to_send = this->variable_name_;
76
77 size_t pos = name_to_send.find_last_of('.');
78 if (pos != std::string::npos) {
79 name_to_send = name_to_send.substr(pos + 1);
80 }
81
83
84 if (this->component_flags_.visible) {
85 this->nextion_->show_component(name_to_send.c_str());
87 } else {
88 this->nextion_->hide_component(name_to_send.c_str());
89 return;
90 }
91 }
92
93 if (this->component_flags_.bco_needs_update || (force_update && this->component_flags_.bco2_is_set)) {
94 this->nextion_->set_component_background_color(this->variable_name_.c_str(), this->bco_);
96 }
97 if (this->component_flags_.bco2_needs_update || (force_update && this->component_flags_.bco2_is_set)) {
98 this->nextion_->set_component_pressed_background_color(this->variable_name_.c_str(), this->bco2_);
100 }
101 if (this->component_flags_.pco_needs_update || (force_update && this->component_flags_.pco_is_set)) {
102 this->nextion_->set_component_foreground_color(this->variable_name_.c_str(), this->pco_);
104 }
105 if (this->component_flags_.pco2_needs_update || (force_update && this->component_flags_.pco2_is_set)) {
106 this->nextion_->set_component_pressed_foreground_color(this->variable_name_.c_str(), this->pco2_);
108 }
109
110 if (this->component_flags_.font_id_needs_update || (force_update && this->component_flags_.font_id_is_set)) {
111 this->nextion_->set_component_font(this->variable_name_.c_str(), this->font_id_);
113 }
114}
115} // namespace nextion
116} // namespace esphome
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_pressed_foreground_color(const char *component, Color color)=0
virtual void hide_component(const char *component)=0
virtual void show_component(const char *component)=0
struct esphome::nextion::NextionComponent::ComponentState component_flags_
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7