ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
modbus_sensor.cpp
Go to the documentation of this file.
1
2#include "modbus_sensor.h"
3#include "esphome/core/log.h"
4
6
7static const char *const TAG = "modbus_controller.sensor";
8
9void ModbusSensor::dump_config() { LOG_SENSOR(TAG, "Modbus Controller Sensor", this); }
10
11void ModbusSensor::parse_and_publish(const std::vector<uint8_t> &data) {
12 float result = payload_to_float(data, *this);
13
14 // Is there a lambda registered
15 // call it with the pre converted value and the raw data array
16 if (this->transform_func_.has_value()) {
17 // the lambda can parse the response itself
18 auto val = (*this->transform_func_)(this, result, data);
19 if (val.has_value()) {
20 ESP_LOGV(TAG, "Value overwritten by lambda");
21 result = val.value();
22 }
23 }
24 ESP_LOGD(TAG, "Sensor new state: %.02f", result);
25 // this->sensor_->raw_state = result;
26 this->publish_state(result);
27}
28
29} // namespace esphome::modbus_controller
void parse_and_publish(const std::vector< uint8_t > &data) override
optional< transform_func_t > transform_func_
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
mopeka_std_values val[3]
float payload_to_float(const std::vector< uint8_t > &data, const SensorItem &item)
Convert vector<uint8_t> response payload to float.
const std::vector< uint8_t > & data