ESPHome  2022.11.3
nextion_component_base.h
Go to the documentation of this file.
1 #pragma once
2 #include <utility>
3 #include "esphome/core/defines.h"
4 
5 namespace esphome {
6 namespace nextion {
7 
9  NO_RESULT = 0,
10  SENSOR = 1,
12  SWITCH = 3,
15 };
16 
17 static const char *const NEXTION_QUEUE_TYPE_STRINGS[] = {"NO_RESULT", "SENSOR", "BINARY_SENSOR",
18  "SWITCH", "TEXT_SENSOR", "WAVEFORM_SENSOR"};
19 
21 
22 class NextionQueue {
23  public:
24  virtual ~NextionQueue() = default;
26  uint32_t queue_time = 0;
27 };
28 
30  public:
31  virtual ~NextionComponentBase() = default;
32 
33  void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send = "") {
34  variable_name_ = variable_name;
35  if (variable_name_to_send.empty()) {
36  variable_name_to_send_ = variable_name;
37  } else {
38  variable_name_to_send_ = variable_name_to_send;
39  }
40  }
41 
42  virtual void update_component_settings(){};
43  virtual void update_component_settings(bool force_update){};
44 
45  virtual void update_component(){};
46  virtual void process_sensor(const std::string &variable_name, int state){};
47  virtual void process_touch(uint8_t page_id, uint8_t component_id, bool on){};
48  virtual void process_text(const std::string &variable_name, const std::string &text_value){};
49  virtual void process_bool(const std::string &variable_name, bool on){};
50 
51  virtual void set_state(float state){};
52  virtual void set_state(float state, bool publish){};
53  virtual void set_state(float state, bool publish, bool send_to_nextion){};
54 
55  virtual void set_state(bool state){};
56  virtual void set_state(bool state, bool publish){};
57  virtual void set_state(bool state, bool publish, bool send_to_nextion){};
58 
59  virtual void set_state(const std::string &state) {}
60  virtual void set_state(const std::string &state, bool publish) {}
61  virtual void set_state(const std::string &state, bool publish, bool send_to_nextion){};
62 
63  uint8_t get_component_id() { return this->component_id_; }
64  void set_component_id(uint8_t component_id) { component_id_ = component_id; }
65 
66  uint8_t get_wave_channel_id() { return this->wave_chan_id_; }
67  void set_wave_channel_id(uint8_t wave_chan_id) { this->wave_chan_id_ = wave_chan_id; }
68 
69  std::vector<uint8_t> get_wave_buffer() { return this->wave_buffer_; }
70  size_t get_wave_buffer_size() { return this->wave_buffer_.size(); }
71 
72  std::string get_variable_name() { return this->variable_name_; }
73  std::string get_variable_name_to_send() { return this->variable_name_to_send_; }
75  virtual std::string get_queue_type_string() { return NEXTION_QUEUE_TYPE_STRINGS[this->get_queue_type()]; }
76  virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion){};
77  virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion){};
78  virtual void send_state_to_nextion(){};
79  bool get_needs_to_send_update() { return this->needs_to_send_update_; }
80  uint8_t get_wave_chan_id() { return this->wave_chan_id_; }
81  void set_wave_max_length(int wave_max_length) { this->wave_max_length_ = wave_max_length; }
82 
83  protected:
84  std::string variable_name_;
86 
87  uint8_t component_id_ = 0;
88  uint8_t wave_chan_id_ = UINT8_MAX;
89  std::vector<uint8_t> wave_buffer_;
90  int wave_max_length_ = 255;
91 
93 };
94 } // namespace nextion
95 } // namespace esphome
virtual void process_text(const std::string &variable_name, const std::string &text_value)
virtual void set_state(const std::string &state, bool publish)
virtual ~NextionQueue()=default
virtual void process_bool(const std::string &variable_name, bool on)
virtual void process_sensor(const std::string &variable_name, int state)
virtual void set_state(bool state, bool publish, bool send_to_nextion)
virtual void update_component_settings(bool force_update)
void set_wave_channel_id(uint8_t wave_chan_id)
virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion)
virtual void set_state(bool state, bool publish)
virtual void set_state(const std::string &state)
virtual void set_state(float state, bool publish, bool send_to_nextion)
virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion)
Definition: a4988.cpp:4
virtual void set_state(float state, bool publish)
virtual void set_state(const std::string &state, bool publish, bool send_to_nextion)
void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send="")
virtual void process_touch(uint8_t page_id, uint8_t component_id, bool on)
bool state
Definition: fan.h:34