ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
modbus_textsensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <span>
8
10
11enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2, ANSI = 3 };
12
13class ModbusTextSensor final : public Component, public text_sensor::TextSensor, public SensorItem {
14 public:
17 this->register_type = register_type;
18 this->set_address(start_address);
20 this->response_bytes = response_bytes;
21 this->encode_ = encode;
22 this->bitmask = 0xFFFFFFFF;
24 this->reuse_previous_range = reuse_previous_range;
25 }
26
27 void dump_config() override;
28
29 void parse_and_publish(std::span<const uint8_t> data) override;
30 using transform_func_t = optional<std::string> (*)(ModbusTextSensor *, std::string, std::span<const uint8_t>);
32
33 protected:
34 optional<transform_func_t> transform_func_{nullopt};
35
37};
38
39} // namespace esphome::modbus_controller
optional< std::string >(*)(ModbusTextSensor *, std::string, std::span< const uint8_t >) transform_func_t
ModbusTextSensor(modbus::EntityType register_type, uint16_t start_address, uint8_t offset, uint16_t response_bytes, RawEncoding encode, RangeReuse reuse_previous_range)
void parse_and_publish(std::span< const uint8_t > data) override
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,...
const std::vector< uint8_t > & data
RangeReuse
How an item relates to the register range built just before it (same register type,...