mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +01:00
Fix published state for modbus number (#2894)
This commit is contained in:
parent
6df1d5222d
commit
24ec5a6e9d
1 changed files with 5 additions and 4 deletions
|
@ -27,6 +27,7 @@ void ModbusNumber::parse_and_publish(const std::vector<uint8_t> &data) {
|
||||||
|
|
||||||
void ModbusNumber::control(float value) {
|
void ModbusNumber::control(float value) {
|
||||||
std::vector<uint16_t> data;
|
std::vector<uint16_t> data;
|
||||||
|
float write_value = value;
|
||||||
// Is there are lambda configured?
|
// Is there are lambda configured?
|
||||||
if (this->write_transform_func_.has_value()) {
|
if (this->write_transform_func_.has_value()) {
|
||||||
// data is passed by reference
|
// data is passed by reference
|
||||||
|
@ -35,23 +36,23 @@ void ModbusNumber::control(float value) {
|
||||||
auto val = (*this->write_transform_func_)(this, value, data);
|
auto val = (*this->write_transform_func_)(this, value, data);
|
||||||
if (val.has_value()) {
|
if (val.has_value()) {
|
||||||
ESP_LOGV(TAG, "Value overwritten by lambda");
|
ESP_LOGV(TAG, "Value overwritten by lambda");
|
||||||
value = val.value();
|
write_value = val.value();
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGV(TAG, "Communication handled by lambda - exiting control");
|
ESP_LOGV(TAG, "Communication handled by lambda - exiting control");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = multiply_by_ * value;
|
write_value = multiply_by_ * write_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lambda didn't set payload
|
// lambda didn't set payload
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
data = float_to_payload(value, this->sensor_value_type);
|
data = float_to_payload(write_value, this->sensor_value_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGD(TAG,
|
ESP_LOGD(TAG,
|
||||||
"Updating register: connected Sensor=%s start address=0x%X register count=%d new value=%.02f (val=%.02f)",
|
"Updating register: connected Sensor=%s start address=0x%X register count=%d new value=%.02f (val=%.02f)",
|
||||||
this->get_name().c_str(), this->start_address, this->register_count, value, value);
|
this->get_name().c_str(), this->start_address, this->register_count, write_value, write_value);
|
||||||
|
|
||||||
// Create and send the write command
|
// Create and send the write command
|
||||||
auto write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
|
auto write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
|
||||||
|
|
Loading…
Reference in a new issue