mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 23:45:40 -07:00
[modbus_controller] Add on_command_sent trigger (#7078)
Co-authored-by: Leo Schelvis <leo.schelvis@gmail.com>
This commit is contained in:
@@ -43,7 +43,11 @@ bool ModbusController::send_next_command_() {
|
||||
ESP_LOGV(TAG, "Sending next modbus command to device %d register 0x%02X count %d", this->address_,
|
||||
command->register_address, command->register_count);
|
||||
command->send();
|
||||
|
||||
this->last_command_timestamp_ = millis();
|
||||
|
||||
this->command_sent_callback_.call((int) command->function_code, command->register_address);
|
||||
|
||||
// remove from queue if no handler is defined
|
||||
if (!command->on_data_func) {
|
||||
command_queue_.pop_front();
|
||||
@@ -659,5 +663,9 @@ int64_t payload_to_number(const std::vector<uint8_t> &data, SensorValueType sens
|
||||
return value;
|
||||
}
|
||||
|
||||
void ModbusController::add_on_command_sent_callback(std::function<void(int, int)> &&callback) {
|
||||
this->command_sent_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
} // namespace modbus_controller
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user