ESPHome  2024.10.2
pylontech_text_sensor.cpp
Go to the documentation of this file.
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace pylontech {
7 
8 static const char *const TAG = "pylontech.textsensor";
9 
10 PylontechTextSensor::PylontechTextSensor(int8_t bat_num) { this->bat_num_ = bat_num; }
11 
13  ESP_LOGCONFIG(TAG, "Pylontech Text Sensor:");
14  ESP_LOGCONFIG(TAG, " Battery %d", this->bat_num_);
15  LOG_TEXT_SENSOR(" ", "Base state", this->base_state_text_sensor_);
16  LOG_TEXT_SENSOR(" ", "Voltage state", this->voltage_state_text_sensor_);
17  LOG_TEXT_SENSOR(" ", "Current state", this->current_state_text_sensor_);
18  LOG_TEXT_SENSOR(" ", "Temperature state", this->temperature_state_text_sensor_);
19 }
20 
22  if (this->bat_num_ != line->bat_num) {
23  return;
24  }
25  if (this->base_state_text_sensor_ != nullptr) {
26  this->base_state_text_sensor_->publish_state(std::string(line->base_st));
27  }
28  if (this->voltage_state_text_sensor_ != nullptr) {
29  this->voltage_state_text_sensor_->publish_state(std::string(line->volt_st));
30  }
31  if (this->current_state_text_sensor_ != nullptr) {
32  this->current_state_text_sensor_->publish_state(std::string(line->curr_st));
33  }
34  if (this->temperature_state_text_sensor_ != nullptr) {
35  this->temperature_state_text_sensor_->publish_state(std::string(line->temp_st));
36  }
37 }
38 
39 } // namespace pylontech
40 } // namespace esphome
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void on_line_read(LineContents *line)