ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
nextion_component_base.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <utility>
5#include <vector>
7
8namespace esphome {
9struct LogString;
10} // namespace esphome
11
12namespace esphome::nextion {
13
22
23class NextionComponentBase;
24
26 public:
29
30 // Store command for retry if spacing blocked it
31 std::string pending_command; // Empty if command was sent successfully
32};
33
35 public:
36 virtual ~NextionComponentBase() = default;
37
38 void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send = "") {
39 this->variable_name_ = variable_name;
40 this->variable_name_to_send_ = variable_name_to_send.empty() ? variable_name : variable_name_to_send;
41 }
42
43 virtual void update_component_settings() {};
44 virtual void update_component_settings(bool force_update) {};
45
46 virtual void update_component() {};
47 virtual void process_sensor(const std::string &variable_name, int state) {};
48 virtual void process_touch(uint8_t page_id, uint8_t component_id, bool on) {};
49 virtual void process_text(const std::string &variable_name, const std::string &text_value) {};
50 virtual void process_bool(const std::string &variable_name, bool on) {};
51
52 virtual void set_state(float state) {};
53 virtual void set_state(float state, bool publish) {};
54 virtual void set_state(float state, bool publish, bool send_to_nextion) {};
55
56 virtual void set_state(bool state) {};
57 virtual void set_state(bool state, bool publish) {};
58 virtual void set_state(bool state, bool publish, bool send_to_nextion) {};
59
60 virtual void set_state(const std::string &state) {}
61 virtual void set_state(const std::string &state, bool publish) {}
62 virtual void set_state(const std::string &state, bool publish, bool send_to_nextion) {};
63
64 uint8_t get_component_id() const { return this->component_id_; }
65 void set_component_id(uint8_t component_id) { this->component_id_ = component_id; }
66
67#ifdef USE_NEXTION_WAVEFORM
68 uint8_t get_wave_channel_id() const { return this->wave_chan_id_; }
69 void set_wave_channel_id(uint8_t wave_chan_id) { this->wave_chan_id_ = wave_chan_id; }
70 void set_wave_max_length(int wave_max_length) { this->wave_max_length_ = wave_max_length; }
71
72 const std::vector<uint8_t> &get_wave_buffer() const { return this->wave_buffer_; }
73 size_t get_wave_buffer_size() const { return this->wave_buffer_.size(); }
74 void clear_wave_buffer(size_t buffer_sent) {
75 if (this->wave_buffer_.size() <= buffer_sent) {
76 this->wave_buffer_.clear();
77 } else {
78 this->wave_buffer_.erase(this->wave_buffer_.begin(), this->wave_buffer_.begin() + buffer_sent);
79 }
80 }
81#endif // USE_NEXTION_WAVEFORM
82
83 const std::string &get_variable_name() const { return this->variable_name_; }
84 const std::string &get_variable_name_to_send() const { return this->variable_name_to_send_; }
86 const LogString *get_queue_type_string() const;
87 virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion) {};
88 virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) {};
89 virtual void send_state_to_nextion() {};
90 bool get_needs_to_send_update() const { return this->needs_to_send_update_; }
91
92 protected:
93 std::string variable_name_;
95
96 uint8_t component_id_ = 0;
97#ifdef USE_NEXTION_WAVEFORM
98 uint8_t wave_chan_id_ = UINT8_MAX;
99 std::vector<uint8_t> wave_buffer_;
101#endif // USE_NEXTION_WAVEFORM
102
104};
105} // namespace esphome::nextion
virtual void set_state(bool state, bool publish, bool send_to_nextion)
const std::string & get_variable_name() const
virtual void set_state(const std::string &state, bool publish)
const LogString * get_queue_type_string() const
virtual void process_sensor(const std::string &variable_name, int state)
virtual NextionQueueType get_queue_type() const
virtual void process_touch(uint8_t page_id, uint8_t component_id, bool on)
virtual void set_state_from_int(int state_value, bool publish, bool send_to_nextion)
virtual void set_state(bool state, bool publish)
virtual void set_state(const std::string &state, bool publish, bool send_to_nextion)
const std::vector< uint8_t > & get_wave_buffer() const
virtual void set_state(float state, bool publish)
virtual void process_bool(const std::string &variable_name, bool on)
virtual void set_state(float state, bool publish, bool send_to_nextion)
virtual void process_text(const std::string &variable_name, const std::string &text_value)
virtual void set_state(const std::string &state)
const std::string & get_variable_name_to_send() const
void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send="")
virtual void update_component_settings(bool force_update)
virtual void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion)
bool state
Definition fan.h:2
static void uint32_t