From 6babe516aca9eab192399fb43657ed36ff0fc9f7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Jun 2025 06:05:19 -0500 Subject: [PATCH] move to proto.h to have less generated code --- esphome/components/api/api_pb2_service.h | 19 ------------------- esphome/components/api/proto.h | 20 ++++++++++++++++++++ script/api_protobuf/api_protobuf.py | 21 +-------------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/esphome/components/api/api_pb2_service.h b/esphome/components/api/api_pb2_service.h index 6d399554b5..c3f4a101b0 100644 --- a/esphome/components/api/api_pb2_service.h +++ b/esphome/components/api/api_pb2_service.h @@ -17,25 +17,6 @@ class APIServerConnectionBase : public ProtoService { public: #endif - protected: - bool check_connection_setup_() { - if (!this->is_connection_setup()) { - this->on_no_setup_connection(); - return false; - } - return true; - } - bool check_authenticated_() { - if (!this->check_connection_setup_()) { - return false; - } - if (!this->is_authenticated()) { - this->on_unauthenticated_access(); - return false; - } - return true; - } - public: template bool send_message(const T &msg) { #ifdef HAS_PROTO_MESSAGE_DUMP diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index eb0dbc151b..77ef475758 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -377,6 +377,26 @@ class ProtoService { // Send the buffer return this->send_buffer(buffer, message_type); } + + // Authentication helper methods + bool check_connection_setup_() { + if (!this->is_connection_setup()) { + this->on_no_setup_connection(); + return false; + } + return true; + } + + bool check_authenticated_() { + if (!this->check_connection_setup_()) { + return false; + } + if (!this->is_authenticated()) { + this->on_unauthenticated_access(); + return false; + } + return true; + } }; } // namespace api diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index fba008dc62..7fac4ca4cc 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1353,26 +1353,7 @@ def main() -> None: hpp += " public:\n" hpp += "#endif\n\n" - # Add authentication check helper methods - hpp += " protected:\n" - hpp += " bool check_connection_setup_() {\n" - hpp += " if (!this->is_connection_setup()) {\n" - hpp += " this->on_no_setup_connection();\n" - hpp += " return false;\n" - hpp += " }\n" - hpp += " return true;\n" - hpp += " }\n" - hpp += " bool check_authenticated_() {\n" - hpp += " if (!this->check_connection_setup_()) {\n" - hpp += " return false;\n" - hpp += " }\n" - hpp += " if (!this->is_authenticated()) {\n" - hpp += " this->on_unauthenticated_access();\n" - hpp += " return false;\n" - hpp += " }\n" - hpp += " return true;\n" - hpp += " }\n" - hpp += " public:\n\n" + hpp += " public:\n" # Add generic send_message method hpp += " template\n"