ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
pylontech
pylontech.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/core/defines.h
"
5
#include "
esphome/components/uart/uart.h
"
6
7
namespace
esphome::pylontech
{
8
9
static
const
uint8_t NUM_BUFFERS = 20;
10
static
const
uint8_t TEXT_SENSOR_MAX_LEN = 14;
11
12
class
PylontechListener
{
13
public
:
14
struct
LineContents
{
15
int
bat_num
= 0,
volt
,
curr
,
tempr
,
tlow
,
thigh
,
vlow
,
vhigh
,
coulomb
,
mostempr
;
16
char
base_st
[TEXT_SENSOR_MAX_LEN] = {0},
volt_st
[TEXT_SENSOR_MAX_LEN] = {0},
curr_st
[TEXT_SENSOR_MAX_LEN] = {0},
17
temp_st
[TEXT_SENSOR_MAX_LEN] = {0};
18
};
19
20
virtual
void
on_line_read
(
LineContents
*
line
);
21
virtual
void
dump_config
();
22
};
23
24
class
PylontechComponent
:
public
PollingComponent
,
public
uart::UARTDevice
{
25
public
:
26
PylontechComponent
();
27
29
void
update
()
override
;
31
void
loop
()
override
;
33
void
setup
()
override
;
34
void
dump_config
()
override
;
35
36
void
register_listener
(
PylontechListener
*listener) { this->
listeners_
.push_back(listener); }
37
38
protected
:
39
void
process_line_
(std::string &buffer);
40
41
// ring buffer
42
std::string
buffer_
[NUM_BUFFERS];
43
int
buffer_index_write_
= 0;
44
int
buffer_index_read_
= 0;
45
bool
has_tlow_id_
=
false
;
46
47
std::vector<PylontechListener *>
listeners_
{};
48
};
49
50
}
// namespace esphome::pylontech
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:585
esphome::pylontech::PylontechComponent
Definition
pylontech.h:24
esphome::pylontech::PylontechComponent::loop
void loop() override
Read data once available.
Definition
pylontech.cpp:57
esphome::pylontech::PylontechComponent::has_tlow_id_
bool has_tlow_id_
Definition
pylontech.h:45
esphome::pylontech::PylontechComponent::buffer_index_write_
int buffer_index_write_
Definition
pylontech.h:43
esphome::pylontech::PylontechComponent::listeners_
std::vector< PylontechListener * > listeners_
Definition
pylontech.h:47
esphome::pylontech::PylontechComponent::process_line_
void process_line_(std::string &buffer)
Definition
pylontech.cpp:91
esphome::pylontech::PylontechComponent::PylontechComponent
PylontechComponent()
Definition
pylontech.cpp:33
esphome::pylontech::PylontechComponent::buffer_index_read_
int buffer_index_read_
Definition
pylontech.h:44
esphome::pylontech::PylontechComponent::update
void update() override
Schedule data readings.
Definition
pylontech.cpp:55
esphome::pylontech::PylontechComponent::setup
void setup() override
Setup the sensor and test for a connection.
Definition
pylontech.cpp:49
esphome::pylontech::PylontechComponent::register_listener
void register_listener(PylontechListener *listener)
Definition
pylontech.h:36
esphome::pylontech::PylontechComponent::buffer_
std::string buffer_[NUM_BUFFERS]
Definition
pylontech.h:42
esphome::pylontech::PylontechComponent::dump_config
void dump_config() override
Definition
pylontech.cpp:35
esphome::pylontech::PylontechListener
Definition
pylontech.h:12
esphome::pylontech::PylontechListener::dump_config
virtual void dump_config()
esphome::pylontech::PylontechListener::on_line_read
virtual void on_line_read(LineContents *line)
esphome::uart::UARTDevice
Definition
uart.h:11
component.h
defines.h
esphome::pylontech
Definition
pylontech.cpp:27
esphome::line
const char int line
Definition
log.h:74
esphome::pylontech::PylontechListener::LineContents
Definition
pylontech.h:14
esphome::pylontech::PylontechListener::LineContents::tlow
int tlow
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::coulomb
int coulomb
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::volt
int volt
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::base_st
char base_st[TEXT_SENSOR_MAX_LEN]
Definition
pylontech.h:16
esphome::pylontech::PylontechListener::LineContents::temp_st
char temp_st[TEXT_SENSOR_MAX_LEN]
Definition
pylontech.h:17
esphome::pylontech::PylontechListener::LineContents::vlow
int vlow
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::bat_num
int bat_num
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::curr_st
char curr_st[TEXT_SENSOR_MAX_LEN]
Definition
pylontech.h:16
esphome::pylontech::PylontechListener::LineContents::thigh
int thigh
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::mostempr
int mostempr
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::vhigh
int vhigh
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::volt_st
char volt_st[TEXT_SENSOR_MAX_LEN]
Definition
pylontech.h:16
esphome::pylontech::PylontechListener::LineContents::tempr
int tempr
Definition
pylontech.h:15
esphome::pylontech::PylontechListener::LineContents::curr
int curr
Definition
pylontech.h:15
uart.h
Generated by
1.12.0