ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
nextion_switch.cpp
Go to the documentation of this file.
1#include "nextion_switch.h"
2#include "esphome/core/util.h"
3#include "esphome/core/log.h"
4
5namespace esphome::nextion {
6
7static const char *const TAG = "nextion_switch";
8
9void NextionSwitch::process_bool(const std::string &variable_name, bool on) {
10 if (!this->nextion_->is_setup())
11 return;
12 if (this->variable_name_ == variable_name) {
13 this->publish_state(on);
14
15 ESP_LOGD(TAG, "Switch: %s=%s", variable_name.c_str(), ONOFF(on));
16 }
17}
18
20 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
21 return;
22 this->nextion_->add_to_get_queue(this);
23}
24
25void NextionSwitch::set_state(bool state, bool publish, bool send_to_nextion) {
26 if (!this->nextion_->is_setup() || this->nextion_->is_updating())
27 return;
28
29 if (send_to_nextion) {
30 if (this->nextion_->is_sleeping() || !this->component_flags_.visible) {
31 this->needs_to_send_update_ = true;
32 } else {
33 this->needs_to_send_update_ = false;
34 this->nextion_->add_no_result_to_queue_with_set(this, (int) state);
35 }
36 }
37 if (publish) {
38 this->publish_state(state);
39 } else {
40 this->state = state;
41 }
42
44
45 ESP_LOGN(TAG, "Write: %s=%s", this->variable_name_.c_str(), ONOFF(state));
46}
47
48void NextionSwitch::write_state(bool state) { this->set_state(state); }
49
50} // namespace esphome::nextion
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 write_state(bool state) override
void process_bool(const std::string &variable_name, bool on) override
void set_state(bool state) override
bool state
The current reported state of the binary sensor.
Definition switch.h:55
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:56
bool state
Definition fan.h:2