ESPHome 2026.8.0b4
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:
16 uint16_t response_bytes, RawEncoding encode, uint16_t skip_updates, bool force_new_range) {
17 this->register_type = register_type;
18 this->set_address(start_address);
20 this->response_bytes = response_bytes;
21 this->register_count = register_count;
22 this->encode_ = encode;
23 this->skip_updates = skip_updates;
24 this->bitmask = 0xFFFFFFFF;
26 this->force_new_range = force_new_range;
27 }
28
29 void dump_config() override;
30
31 void parse_and_publish(std::span<const uint8_t> data) override;
32 using transform_func_t = optional<std::string> (*)(ModbusTextSensor *, std::string, std::span<const uint8_t>);
34
35 protected:
36 optional<transform_func_t> transform_func_{nullopt};
37
39};
40
41} // 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, uint8_t register_count, uint16_t response_bytes, RawEncoding encode, uint16_t skip_updates, bool force_new_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