From 857c8be1c90bae40613134a3649e4fa69de79b64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Feb 2026 14:32:05 +0100 Subject: [PATCH] Revert "tidy" This reverts commit 9d43a9326e37364e925e3cfb088dd14ffc444a82. --- esphome/components/api/api_connection.cpp | 10 +++------- esphome/components/api/api_connection.h | 2 +- esphome/components/api/api_pb2_service.h | 8 ++++++++ esphome/components/api/proto.h | 2 +- script/api_protobuf/api_protobuf.py | 9 +++++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index b3c008d71c..c377645f51 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1035,7 +1035,7 @@ void APIConnection::try_send_camera_image_() { msg.device_id = camera::Camera::instance()->get_device_id(); #endif - if (!this->send_message(msg, CameraImageResponse::MESSAGE_TYPE)) { + if (!this->send_message_(msg, CameraImageResponse::MESSAGE_TYPE)) { return; // Send failed, try again later } this->image_reader_->consume_data(to_send); @@ -1443,7 +1443,7 @@ bool APIConnection::try_send_log_message(int level, const char *tag, const char SubscribeLogsResponse msg; msg.level = static_cast(level); msg.set_message(reinterpret_cast(line), message_len); - return this->send_message(msg, SubscribeLogsResponse::MESSAGE_TYPE); + return this->send_message_(msg, SubscribeLogsResponse::MESSAGE_TYPE); } void APIConnection::complete_authentication_() { @@ -1768,11 +1768,7 @@ bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { } return false; } -bool APIConnection::send_message(const ProtoMessage &msg, uint8_t message_type) { -#ifdef HAS_PROTO_MESSAGE_DUMP - DumpBuffer dump_buf; - this->log_send_message_(msg.message_name(), msg.dump_to(dump_buf)); -#endif +bool APIConnection::send_message_(const ProtoMessage &msg, uint8_t message_type) { ProtoSize size; msg.calculate_size(size); std::vector &shared_buf = this->parent_->get_shared_buffer_ref(); diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 14cafe184e..156ccdb57c 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -255,7 +255,7 @@ class APIConnection final : public APIServerConnection { void on_fatal_error() override; void on_no_setup_connection() override; - bool send_message(const ProtoMessage &msg, uint8_t message_type) override; + bool send_message_(const ProtoMessage &msg, uint8_t message_type) override; void prepare_first_message_buffer(std::vector &shared_buf, size_t header_padding, size_t total_size) { shared_buf.clear(); diff --git a/esphome/components/api/api_pb2_service.h b/esphome/components/api/api_pb2_service.h index dff89a95cf..80a61c1041 100644 --- a/esphome/components/api/api_pb2_service.h +++ b/esphome/components/api/api_pb2_service.h @@ -18,6 +18,14 @@ class APIServerConnectionBase : public ProtoService { public: #endif + bool send_message(const ProtoMessage &msg, uint8_t message_type) { +#ifdef HAS_PROTO_MESSAGE_DUMP + DumpBuffer dump_buf; + this->log_send_message_(msg.message_name(), msg.dump_to(dump_buf)); +#endif + return this->send_message_(msg, message_type); + } + virtual void on_hello_request(const HelloRequest &value){}; virtual void on_disconnect_request(const DisconnectRequest &value){}; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index f651c6e7d5..2614af294e 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -965,7 +965,7 @@ class ProtoService { * @param message_type The message type identifier. * @return True if the message was sent successfully, false otherwise. */ - virtual bool send_message(const ProtoMessage &msg, uint8_t message_type) = 0; + virtual bool send_message_(const ProtoMessage &msg, uint8_t message_type) = 0; // Authentication helper methods inline bool check_connection_setup_() { diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 2df38b0eb0..8baf6acf11 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -2842,6 +2842,15 @@ static const char *const TAG = "api.service"; hpp += " public:\n" hpp += "#endif\n\n" + # Add non-template send_message method + hpp += " bool send_message(const ProtoMessage &msg, uint8_t message_type) {\n" + hpp += "#ifdef HAS_PROTO_MESSAGE_DUMP\n" + hpp += " DumpBuffer dump_buf;\n" + hpp += " this->log_send_message_(msg.message_name(), msg.dump_to(dump_buf));\n" + hpp += "#endif\n" + hpp += " return this->send_message_(msg, message_type);\n" + hpp += " }\n\n" + # Add logging helper method implementations to cpp cpp += "#ifdef HAS_PROTO_MESSAGE_DUMP\n" cpp += (