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