ESPHome  2024.11.0
nextion_textsensor.cpp
Go to the documentation of this file.
1 #include "nextion_textsensor.h"
2 #include "esphome/core/util.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace nextion {
7 static const char *const TAG = "nextion_textsensor";
8 
9 void 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 
24 void 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
void set_state(const std::string &state, bool publish) override
void publish_state(const std::string &state)
Definition: text_sensor.cpp:9
virtual void add_to_get_queue(NextionComponentBase *component)=0
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void process_text(const std::string &variable_name, const std::string &text_value) override
virtual void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value)=0