ESPHome 2025.5.0
Loading...
Searching...
No Matches
nextion_textsensor.cpp
Go to the documentation of this file.
2#include "esphome/core/util.h"
3#include "esphome/core/log.h"
4
5namespace esphome {
6namespace nextion {
7static const char *const TAG = "nextion_textsensor";
8
9void NextionTextSensor::process_text(const std::string &variable_name, const std::string &text_value) {
10 if (!this->nextion_->is_setup())
11 return;
12 if (this->variable_name_ == variable_name) {
13 this->publish_state(text_value);
14 ESP_LOGD(TAG, "Processed text_sensor \"%s\" state \"%s\"", variable_name.c_str(), text_value.c_str());
15 }
16}
17
19 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
20 return;
21 this->nextion_->add_to_get_queue(this);
22}
23
24void NextionTextSensor::set_state(const std::string &state, bool publish, bool send_to_nextion) {
25 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
26 return;
27
28 if (send_to_nextion) {
29 if (this->nextion_->is_sleeping() || !this->visible_) {
30 this->needs_to_send_update_ = true;
31 } else {
32 this->nextion_->add_no_result_to_queue_with_set(this, state);
33 }
34 }
35
36 if (publish) {
37 this->publish_state(state);
38 } else {
39 this->state = state;
40 this->has_state_ = true;
41 }
42
44
45 ESP_LOGN(TAG, "Wrote state for text_sensor \"%s\" state \"%s\"", this->variable_name_.c_str(), state.c_str());
46}
47
48} // namespace nextion
49} // namespace esphome
virtual void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value)=0
virtual void add_to_get_queue(NextionComponentBase *component)=0
void process_text(const std::string &variable_name, const std::string &text_value) override
void set_state(const std::string &state, bool publish) override
void publish_state(const std::string &state)
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7