ESPHome 2025.7.4
Loading...
Searching...
No Matches
nextion_component_base.h
Go to the documentation of this file.
1#pragma once
2#include <utility>
3#include <vector>
5
6namespace esphome {
7namespace nextion {
8
17
18static const char *const NEXTION_QUEUE_TYPE_STRINGS[] = {"NO_RESULT", "SENSOR", "BINARY_SENSOR",
19 "SWITCH", "TEXT_SENSOR", "WAVEFORM_SENSOR"};
20
21class NextionComponentBase;
22
24 public:
25 virtual ~NextionQueue() = default;
27 uint32_t queue_time = 0;
28
29 // Store command for retry if spacing blocked it
30 std::string pending_command; // Empty if command was sent successfully
31};
32
34 public:
35 virtual ~NextionComponentBase() = default;
36
37 void set_variable_name(const std::string &variable_name, const std::string &variable_name_to_send = "") {
38 variable_name_ = variable_name;
39 if (variable_name_to_send.empty()) {
40 variable_name_to_send_ = variable_name;
41 } else {
42 variable_name_to_send_ = variable_name_to_send;
43 }
44 }
45
46 virtual void update_component_settings(){};
47 virtual void update_component_settings(bool force_update){};
48
49 virtual void update_component(){};
50 virtual void process_sensor(const std::string &variable_name, int state){};
51 virtual void process_touch(uint8_t page_id, uint8_t component_id, bool on){};
52 virtual void process_text(const std::string &variable_name, const std::string &text_value){};
53 virtual void process_bool(const std::string &variable_name, bool on){};
54
55 virtual void set_state(float state){};
56 virtual void set_state(float state, bool publish){};
57 virtual void set_state(float state, bool publish, bool send_to_nextion){};
58
59 virtual void set_state(bool state){};
60 virtual void set_state(bool state, bool publish){};
61 virtual void set_state(bool state, bool publish, bool send_to_nextion){};
62
63 virtual void set_state(const std::string &state) {}
64 virtual void set_state(const std::string &state, bool publish) {}
65 virtual void set_state(const std::string &state, bool publish, bool send_to_nextion){};
66
67 uint8_t get_component_id() { return this->component_id_; }
68 void set_component_id(uint8_t component_id) { component_id_ = component_id; }
69
70 uint8_t get_wave_channel_id() { return this->wave_chan_id_; }
71 void set_wave_channel_id(uint8_t wave_chan_id) { this->wave_chan_id_ = wave_chan_id; }
72
73 std::vector<uint8_t> get_wave_buffer() { return this->wave_buffer_; }
74 size_t get_wave_buffer_size() { return this->wave_buffer_.size(); }
75 void clear_wave_buffer(size_t buffer_sent) {
76 if (this->wave_buffer_.size() <= buffer_sent) {
77 this->wave_buffer_.clear();
78 } else {
79 this->wave_buffer_.erase(this->wave_buffer_.begin(), this->wave_buffer_.begin() + buffer_sent);
80 }
81 }
82
83 std::string get_variable_name() { return this->variable_name_; }
84 std::string get_variable_name_to_send() { return this->variable_name_to_send_; }
86 virtual std::string get_queue_type_string() { return NEXTION_QUEUE_TYPE_STRINGS[this->get_queue_type()]; }
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(){};
91 uint8_t get_wave_chan_id() { return this->wave_chan_id_; }
92 void set_wave_max_length(int wave_max_length) { this->wave_max_length_ = wave_max_length; }
93
94 protected:
95 std::string variable_name_;
97
98 uint8_t component_id_ = 0;
99 uint8_t wave_chan_id_ = UINT8_MAX;
100 std::vector<uint8_t> wave_buffer_;
102
104};
105} // namespace nextion
106} // namespace esphome
virtual void set_state(bool state, bool publish, bool send_to_nextion)
virtual void set_state(const std::string &state, bool publish)
virtual void process_sensor(const std::string &variable_name, int state)
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)
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)
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)
virtual ~NextionQueue()=default
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7