ESPHome  2024.10.2
nextion_sensor.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 NextionSensor;
10 
12  public:
13  NextionSensor(NextionBase *nextion) { this->nextion_ = nextion; }
14  void send_state_to_nextion() override { this->set_state(this->state, false, true); };
15 
16  void update_component() override { this->update(); }
17  void update() override;
18  void add_to_wave_buffer(float state);
19  void set_precision(uint8_t precision) { this->precision_ = precision; }
20  void set_component_id(uint8_t component_id) { component_id_ = component_id; }
21  void set_wave_channel_id(uint8_t wave_chan_id) { this->wave_chan_id_ = wave_chan_id; }
22  void set_wave_max_value(uint32_t wave_maxvalue) { this->wave_maxvalue_ = wave_maxvalue; }
23  void process_sensor(const std::string &variable_name, int state) override;
24 
25  void set_state(float state) override { this->set_state(state, true, true); }
26  void set_state(float state, bool publish) override { this->set_state(state, publish, true); }
27  void set_state(float state, bool publish, bool send_to_nextion) override;
28 
29  void set_waveform_send_last_value(bool send_last_value) { this->send_last_value_ = send_last_value; }
30  uint8_t get_wave_chan_id() { return this->wave_chan_id_; }
31  void set_wave_max_length(int wave_max_length) { this->wave_max_length_ = wave_max_length; }
34  }
35  void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override {}
36  void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override {
37  this->set_state(state_value, publish, send_to_nextion);
38  }
39 
40  protected:
41  uint8_t precision_ = 0;
42  uint32_t wave_maxvalue_ = 255;
43 
44  float last_value_ = 0;
45  bool send_last_value_ = true;
46  void wave_update_();
47 };
48 } // namespace nextion
49 } // namespace esphome
void set_wave_channel_id(uint8_t wave_chan_id)
void add_to_wave_buffer(float state)
void set_waveform_send_last_value(bool send_last_value)
void set_precision(uint8_t precision)
void set_component_id(uint8_t component_id)
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_state(float state, bool publish) override
NextionSensor(NextionBase *nextion)
void set_state_from_int(int state_value, bool publish, bool send_to_nextion) override
void send_state_to_nextion() override
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
void process_sensor(const std::string &variable_name, int state) override
void set_wave_max_length(int wave_max_length)
void set_wave_max_value(uint32_t wave_maxvalue)
NextionQueueType get_queue_type() override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_state_from_string(const std::string &state_value, bool publish, bool send_to_nextion) override
Base-class for all sensors.
Definition: sensor.h:57
void set_state(float state) override