ESPHome  2022.9.1
modbus_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace modbus_controller {
9 
10 class ModbusSensor : public Component, public sensor::Sensor, public SensorItem {
11  public:
13  SensorValueType value_type, int register_count, uint8_t skip_updates, bool force_new_range) {
14  this->register_type = register_type;
15  this->start_address = start_address;
16  this->offset = offset;
17  this->bitmask = bitmask;
18  this->sensor_value_type = value_type;
19  this->register_count = register_count;
20  this->skip_updates = skip_updates;
21  this->force_new_range = force_new_range;
22  }
23 
24  void parse_and_publish(const std::vector<uint8_t> &data) override;
25  void dump_config() override;
26  using transform_func_t = std::function<optional<float>(ModbusSensor *, float, const std::vector<uint8_t> &)>;
27 
29 
30  protected:
32 };
33 
34 } // namespace modbus_controller
35 } // namespace esphome
optional< transform_func_t > transform_func_
Definition: modbus_sensor.h:31
void set_template(transform_func_t &&f)
Definition: modbus_sensor.h:28
const nullopt_t nullopt((nullopt_t::init()))
void parse_and_publish(const std::vector< uint8_t > &data) override
ModbusSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, SensorValueType value_type, int register_count, uint8_t skip_updates, bool force_new_range)
Definition: modbus_sensor.h:12
std::function< optional< float >(ModbusSensor *, float, const std::vector< uint8_t > &)> transform_func_t
Definition: modbus_sensor.h:26
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:48