ESPHome 2025.7.4
Loading...
Searching...
No Matches
nextion_binarysensor.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 {
7
8static const char *const TAG = "nextion_binarysensor";
9
10void NextionBinarySensor::process_bool(const std::string &variable_name, bool state) {
11 if (!this->nextion_->is_setup())
12 return;
13
14 if (this->variable_name_.empty()) // This is a touch component
15 return;
16
17 if (this->variable_name_ == variable_name) {
18 this->publish_state(state);
19 ESP_LOGD(TAG, "Binary sensor: %s=%s", variable_name.c_str(), ONOFF(state));
20 }
21}
22
23void NextionBinarySensor::process_touch(uint8_t page_id, uint8_t component_id, bool state) {
24 if (this->page_id_ == page_id && this->component_id_ == component_id) {
25 this->publish_state(state);
26 }
27}
28
30 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
31 return;
32
33 if (this->variable_name_.empty()) // This is a touch component
34 return;
35
36 this->nextion_->add_to_get_queue(this);
37}
38
39void NextionBinarySensor::set_state(bool state, bool publish, bool send_to_nextion) {
40 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
41 return;
42
43 if (this->component_id_ == 0) // This is a legacy touch component
44 return;
45
46 if (send_to_nextion) {
47 if (this->nextion_->is_sleeping() || !this->component_flags_.visible) {
48 this->needs_to_send_update_ = true;
49 } else {
50 this->needs_to_send_update_ = false;
51 this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
52 }
53 }
54
55 if (publish) {
56 this->publish_state(state);
57 } else {
58 this->state = state;
59 this->set_has_state(true);
60 }
61
63
64 ESP_LOGN(TAG, "Write: %s=%s", this->variable_name_.c_str(), ONOFF(this->state));
65}
66
67} // namespace nextion
68} // namespace esphome
void set_has_state(bool state)
Definition entity_base.h:73
void publish_state(bool new_state)
Publish a new state to the front-end.
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_bool(const std::string &variable_name, bool state) override
void process_touch(uint8_t page_id, uint8_t component_id, bool state) override
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7