ESPHome  2024.3.1
nextion_switch.h
Go to the documentation of this file.
1 #pragma once
4 #include "../nextion_component.h"
5 #include "../nextion_base.h"
6 
7 namespace esphome {
8 namespace nextion {
9 class NextionSwitch;
10 
12  public:
13  NextionSwitch(NextionBase *nextion) { this->nextion_ = nextion; }
14 
15  void update() override;
16  void update_component() override { this->update(); }
17  void process_bool(const std::string &variable_name, bool on) override;
18 
19  void set_state(bool state) override { this->set_state(state, true, true); }
20  void set_state(bool state, bool publish) override { this->set_state(state, publish, true); }
21  void set_state(bool state, bool publish, bool send_to_nextion) override;
22 
23  void send_state_to_nextion() override { this->set_state(this->state, false, true); };
25  void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override {}
26  void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override {
27  this->set_state(state_value != 0, publish, send_to_nextion);
28  }
29 
30  protected:
31  void write_state(bool state) override;
32 };
33 } // namespace nextion
34 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
void set_state(bool state) override
void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void send_state_to_nextion() override
void set_state(bool state, bool publish) override
void write_state(bool state) override
NextionQueueType get_queue_type() override
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
NextionSwitch(NextionBase *nextion)
void process_bool(const std::string &variable_name, bool on) override
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override