ESPHome  2024.12.2
pylontech.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
6 
7 namespace esphome {
8 namespace pylontech {
9 
10 static const uint8_t NUM_BUFFERS = 20;
11 static const uint8_t TEXT_SENSOR_MAX_LEN = 8;
12 
14  public:
15  struct LineContents {
17  char base_st[TEXT_SENSOR_MAX_LEN], volt_st[TEXT_SENSOR_MAX_LEN], curr_st[TEXT_SENSOR_MAX_LEN],
18  temp_st[TEXT_SENSOR_MAX_LEN];
19  };
20 
21  virtual void on_line_read(LineContents *line);
22  virtual void dump_config();
23 };
24 
26  public:
28 
30  void update() override;
32  void loop() override;
34  void setup() override;
35  void dump_config() override;
36 
37  float get_setup_priority() const override;
38 
39  void register_listener(PylontechListener *listener) { this->listeners_.push_back(listener); }
40 
41  protected:
42  void process_line_(std::string &buffer);
43 
44  // ring buffer
45  std::string buffer_[NUM_BUFFERS];
46  int buffer_index_write_ = 0;
47  int buffer_index_read_ = 0;
48 
49  std::vector<PylontechListener *> listeners_{};
50 };
51 
52 } // namespace pylontech
53 } // namespace esphome
void setup()
void loop()
void register_listener(PylontechListener *listener)
Definition: pylontech.h:39
This class simplifies creating components that periodically check a state.
Definition: component.h:283
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void on_line_read(LineContents *line)