ESPHome  2022.8.0
modbus_textsensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace modbus_controller {
9 
10 enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2 };
11 
13  public:
14  ModbusTextSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint8_t register_count,
15  uint16_t response_bytes, RawEncoding encode, uint8_t skip_updates, bool force_new_range) {
16  this->register_type = register_type;
17  this->start_address = start_address;
18  this->offset = offset;
19  this->response_bytes = response_bytes;
20  this->register_count = register_count;
21  this->encode_ = encode;
22  this->skip_updates = skip_updates;
23  this->bitmask = 0xFFFFFFFF;
24  this->sensor_value_type = SensorValueType::RAW;
25  this->force_new_range = force_new_range;
26  }
27 
28  void dump_config() override;
29 
30  void parse_and_publish(const std::vector<uint8_t> &data) override;
31  using transform_func_t =
32  std::function<optional<std::string>(ModbusTextSensor *, std::string, const std::vector<uint8_t> &)>;
33  void set_template(transform_func_t &&f) { this->transform_func_ = f; }
34 
35  protected:
37 
39 };
40 
41 } // namespace modbus_controller
42 } // namespace esphome
ModbusTextSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint8_t register_count, uint16_t response_bytes, RawEncoding encode, uint8_t skip_updates, bool force_new_range)
const nullopt_t nullopt((nullopt_t::init()))
std::function< optional< std::string >(ModbusTextSensor *, std::string, const std::vector< uint8_t > &)> transform_func_t
Definition: a4988.cpp:4