ESPHome  2022.6.3
nextion_binarysensor.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 NextionBinarySensor;
10 
13  public PollingComponent {
14  public:
15  NextionBinarySensor(NextionBase *nextion) { this->nextion_ = nextion; }
16 
17  void update_component() override { this->update(); }
18  void update() override;
19  void send_state_to_nextion() override { this->set_state(this->state, false); };
20  void process_bool(const std::string &variable_name, bool state) override;
21  void process_touch(uint8_t page_id, uint8_t component_id, bool state) override;
22 
23  // Set the components page id for Nextion Touch Component
24  void set_page_id(uint8_t page_id) { page_id_ = page_id; }
25  // Set the components component id for Nextion Touch Component
26  void set_component_id(uint8_t component_id) { component_id_ = component_id; }
27 
28  void set_state(bool state) override { this->set_state(state, true, true); }
29  void set_state(bool state, bool publish) override { this->set_state(state, publish, true); }
30  void set_state(bool state, bool publish, bool send_to_nextion) override;
31 
33  void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override {}
34  void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override {
35  this->set_state(state_value != 0, publish, send_to_nextion);
36  }
37 
38  protected:
39  uint8_t page_id_;
40 };
41 } // namespace nextion
42 } // namespace esphome
This class simplifies creating components that periodically check a state.
Definition: component.h:266
void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override
NextionQueueType get_queue_type() override
void process_bool(const std::string &variable_name, bool state) override
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:50
void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override
void process_touch(uint8_t page_id, uint8_t component_id, bool state) override
void set_component_id(uint8_t component_id)
Definition: a4988.cpp:4
void set_state(bool state, bool publish) override