ESPHome 2026.5.0-dev
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::nextion {
6
7static const char *const TAG = "nextion_binarysensor";
8
9void NextionBinarySensor::process_bool(const std::string &variable_name, bool state) {
10 if (!this->nextion_->is_setup())
11 return;
12
13 if (this->variable_name_.empty()) // This is a touch component
14 return;
15
16 if (this->variable_name_ == variable_name) {
17 this->publish_state(state);
18 ESP_LOGD(TAG, "Binary sensor: %s=%s", variable_name.c_str(), ONOFF(state));
19 }
20}
21
22void NextionBinarySensor::process_touch(uint8_t page_id, uint8_t component_id, bool state) {
23 if (this->page_id_ == page_id && this->component_id_ == component_id) {
24 this->publish_state(state);
25 }
26}
27
29 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
30 return;
31
32 if (this->variable_name_.empty()) // This is a touch component
33 return;
34
35 this->nextion_->add_to_get_queue(this);
36}
37
38void NextionBinarySensor::set_state(bool state, bool publish, bool send_to_nextion) {
39 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
40 return;
41
42 if (this->component_id_ == 0) // This is a legacy touch component
43 return;
44
45 if (send_to_nextion) {
46 if (this->nextion_->is_sleeping() || !this->component_flags_.visible) {
47 this->needs_to_send_update_ = true;
48 } else {
49 this->needs_to_send_update_ = false;
50 this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
51 }
52 }
53
54 if (publish) {
55 this->publish_state(state);
56 } else {
57 this->state = state;
58 this->set_has_state(true);
59 }
60
62
63 ESP_LOGN(TAG, "Write: %s=%s", this->variable_name_.c_str(), ONOFF(this->state));
64}
65
66} // namespace esphome::nextion
void set_has_state(bool state)
void publish_state(bool new_state)
Publish a new state to the front-end.
bool state
The current state of this binary sensor. Also used as the backing storage for StatefulEntityBase.
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:2