ESPHome 2025.5.0
Loading...
Searching...
No Matches
modbus_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8
9namespace esphome {
10namespace modbus_controller {
11
12class 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
void parse_and_publish(const std::vector< uint8_t > &data) override
optional< transform_func_t > transform_func_
void set_template(transform_func_t &&f)
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)
std::function< optional< float >(ModbusSensor *, float, const std::vector< uint8_t > &)> transform_func_t
Base-class for all sensors.
Definition sensor.h:57
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
const nullopt_t nullopt((nullopt_t::init()))