From 9ac38ff8d025f4bf9739721dcf3695d67f09fc6d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 25 Jul 2025 13:25:46 -1000 Subject: [PATCH] [api] Add missing USE_API_PASSWORD guards to reduce flash usage --- esphome/components/api/api_connection.cpp | 2 ++ esphome/components/api/api_connection.h | 2 ++ esphome/components/api/proto.h | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 76713c54c8..58f10464c3 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1590,10 +1590,12 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) { // Do not set last_traffic_ on send return true; } +#ifdef USE_API_PASSWORD void APIConnection::on_unauthenticated_access() { this->on_fatal_error(); ESP_LOGD(TAG, "%s access without authentication", this->get_client_combined_info().c_str()); } +#endif void APIConnection::on_no_setup_connection() { this->on_fatal_error(); ESP_LOGD(TAG, "%s access without full connection", this->get_client_combined_info().c_str()); diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 6214d5ba82..2c6074c046 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -228,7 +228,9 @@ class APIConnection : public APIServerConnection { } uint8_t get_log_subscription_level() const { return this->flags_.log_subscription; } void on_fatal_error() override; +#ifdef USE_API_PASSWORD void on_unauthenticated_access() override; +#endif void on_no_setup_connection() override; ProtoWriteBuffer create_buffer(uint32_t reserve_size) override { // FIXME: ensure no recursive writes can happen diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 44f9716516..7db4b65d55 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -860,7 +860,9 @@ class ProtoService { virtual bool is_authenticated() = 0; virtual bool is_connection_setup() = 0; virtual void on_fatal_error() = 0; +#ifdef USE_API_PASSWORD virtual void on_unauthenticated_access() = 0; +#endif virtual void on_no_setup_connection() = 0; /** * Create a buffer with a reserved size. @@ -901,10 +903,12 @@ class ProtoService { if (!this->check_connection_setup_()) { return false; } +#ifdef USE_API_PASSWORD if (!this->is_authenticated()) { this->on_unauthenticated_access(); return false; } +#endif return true; } };