ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
modbus_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <span>
8
10
11class ModbusSensor final : public Component, public sensor::Sensor, public SensorItem {
12 public:
15 this->register_type = register_type;
16 this->set_address(start_address);
18 this->bitmask = bitmask;
19 this->sensor_value_type = value_type;
20 this->reuse_previous_range = reuse_previous_range;
21 }
22
23 void parse_and_publish(std::span<const uint8_t> data) override;
24 void dump_config() override;
25 using transform_func_t = optional<float> (*)(ModbusSensor *, float, std::span<const uint8_t>);
26
28
29 protected:
30 optional<transform_func_t> transform_func_{nullopt};
31};
32
33} // namespace esphome::modbus_controller
void set_template(transform_func_t f)
optional< float >(*)(ModbusSensor *, float, std::span< const uint8_t >) transform_func_t
void parse_and_publish(std::span< const uint8_t > data) override
optional< transform_func_t > transform_func_
ModbusSensor(modbus::EntityType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, SensorValueType value_type, RangeReuse reuse_previous_range)
void set_address(uint16_t address)
Sets the configured address, and points the range base at it.
void set_offset_from_start_address(uint8_t offset)
Records the offset as configured, and seeds the resolved position with it.
uint8_t offset
Position of this sensor's data within its range's response - a byte offset for registers,...
Base-class for all sensors.
Definition sensor.h:47
const std::vector< uint8_t > & data
RangeReuse
How an item relates to the register range built just before it (same register type,...
static void uint32_t