diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 11106b32a1..e44fbab603 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -59,6 +59,18 @@ class APIConnection final : public APIServerConnectionBase { // compiler can devirtualize and inline on_* handler calls within this class. void read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) override; + // Auth helpers defined here (not in ProtoService) so the compiler can + // devirtualize is_connection_setup()/on_no_setup_connection() calls + // within this final class. + inline bool check_connection_setup_() { + if (!this->is_connection_setup()) { + this->on_no_setup_connection(); + return false; + } + return true; + } + inline bool check_authenticated_() { return this->check_connection_setup_(); } + public: bool send_list_info_done() { return this->schedule_message_(nullptr, ListEntitiesDoneResponse::MESSAGE_TYPE, diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index d6e993d3a5..a1826742a5 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -706,17 +706,6 @@ class ProtoService { virtual void on_no_setup_connection() = 0; virtual bool send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) = 0; virtual void read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) = 0; - - // Authentication helper methods - inline bool check_connection_setup_() { - if (!this->is_connection_setup()) { - this->on_no_setup_connection(); - return false; - } - return true; - } - - inline bool check_authenticated_() { return this->check_connection_setup_(); } }; } // namespace esphome::api