ESPHome 2025.5.0
Loading...
Searching...
No Matches
modbus_select.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4#include <vector>
5
9
10namespace esphome {
11namespace modbus_controller {
12
13class ModbusSelect : public Component, public select::Select, public SensorItem {
14 public:
16 bool force_new_range, std::vector<int64_t> mapping) {
17 this->register_type = ModbusRegisterType::HOLDING; // not configurable
18 this->sensor_value_type = sensor_value_type;
19 this->start_address = start_address;
20 this->offset = 0; // not configurable
21 this->bitmask = 0xFFFFFFFF; // not configurable
22 this->register_count = register_count;
23 this->response_bytes = 0; // not configurable
24 this->skip_updates = skip_updates;
25 this->force_new_range = force_new_range;
26 this->mapping_ = std::move(mapping);
27 }
28
30 std::function<optional<std::string>(ModbusSelect *const, int64_t, const std::vector<uint8_t> &)>;
32 std::function<optional<int64_t>(ModbusSelect *const, const std::string &, int64_t, std::vector<uint16_t> &)>;
33
34 void set_parent(ModbusController *const parent) { this->parent_ = parent; }
35 void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
36 void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
39
40 void dump_config() override;
41 void parse_and_publish(const std::vector<uint8_t> &data) override;
42 void control(const std::string &value) override;
43
44 protected:
45 std::vector<int64_t> mapping_{};
48 bool optimistic_{false};
51};
52
53} // namespace modbus_controller
54} // namespace esphome
optional< write_transform_func_t > write_transform_func_
void parse_and_publish(const std::vector< uint8_t > &data) override
void set_write_template(write_transform_func_t &&f)
void set_use_write_mutiple(bool use_write_multiple)
void set_template(transform_func_t &&f)
std::function< optional< int64_t >(ModbusSelect *const, const std::string &, int64_t, std::vector< uint16_t > &)> write_transform_func_t
optional< transform_func_t > transform_func_
std::function< optional< std::string >(ModbusSelect *const, int64_t, const std::vector< uint8_t > &)> transform_func_t
void set_parent(ModbusController *const parent)
void control(const std::string &value) override
ModbusSelect(SensorValueType sensor_value_type, uint16_t start_address, uint8_t register_count, uint16_t skip_updates, bool force_new_range, std::vector< int64_t > mapping)
Base-class for all selects.
Definition select.h:31
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
const nullopt_t nullopt((nullopt_t::init()))