ESPHome 2026.8.2
Loading...
Searching...
No Matches
modbus_number.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8
10
11using value_to_data_t = std::function<float>(float);
12
13class ModbusNumber final : public number::Number, public Component, public SensorItem {
14 public:
16 SensorValueType value_type, int register_count, uint16_t skip_updates, bool force_new_range) {
17 this->register_type = register_type;
18 this->set_address(start_address);
20 this->bitmask = bitmask;
21 this->sensor_value_type = value_type;
22 this->register_count = register_count;
23 this->skip_updates = skip_updates;
24 this->force_new_range = force_new_range;
25 };
26
27 void dump_config() override;
28 void parse_and_publish(std::span<const uint8_t> data) override;
29 float get_setup_priority() const override { return setup_priority::HARDWARE; }
30 void set_parent(ModbusController *parent) { this->parent_ = parent; }
31 void set_write_multiply(float factor) { this->multiply_by_ = factor; }
32
33 using transform_func_t = optional<float> (*)(ModbusNumber *, float, std::span<const uint8_t>);
34 using write_transform_func_t = optional<float> (*)(ModbusNumber *, float, std::vector<uint16_t> &);
37 void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
38
39 protected:
40 void control(float value) override;
41 optional<transform_func_t> transform_func_{nullopt};
42 optional<write_transform_func_t> write_transform_func_{nullopt};
44 float multiply_by_{1.0};
46};
47
48} // namespace esphome::modbus_controller
optional< float >(*)(ModbusNumber *, float, std::span< const uint8_t >) transform_func_t
optional< write_transform_func_t > write_transform_func_
void parse_and_publish(std::span< const uint8_t > data) override
optional< transform_func_t > transform_func_
void set_template(transform_func_t f)
void set_parent(ModbusController *parent)
void set_use_write_mutiple(bool use_write_multiple)
float get_setup_priority() const override
ModbusNumber(modbus::EntityType 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)
optional< float >(*)(ModbusNumber *, float, std::vector< uint16_t > &) write_transform_func_t
void set_write_template(write_transform_func_t f)
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 numbers.
Definition number.h:29
std::function< float >(float) value_to_data_t
const std::vector< uint8_t > & data
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:43
static void uint32_t