From 60e9ad224029595a321a62349f01d26f62dccc8f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 14 Jul 2025 21:22:45 -1000 Subject: [PATCH] Skip API log message calls for unsubscribed log levels --- esphome/components/api/api_connection.cpp | 3 --- esphome/components/api/api_connection.h | 1 + esphome/components/api/api_server.cpp | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index ea3268a583..c2f527417d 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1410,9 +1410,6 @@ void APIConnection::update_command(const UpdateCommandRequest &msg) { #endif bool APIConnection::try_send_log_message(int level, const char *tag, const char *line, size_t message_len) { - if (this->flags_.log_subscription < level) - return false; - // Pre-calculate message size to avoid reallocations uint32_t msg_size = 0; diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 0051a143de..1c9bf2ef21 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -209,6 +209,7 @@ class APIConnection : public APIServerConnection { return static_cast(this->flags_.connection_state) == ConnectionState::CONNECTED || this->is_authenticated(); } + uint8_t get_log_subscription_level() const { return this->flags_.log_subscription; } void on_fatal_error() override; void on_unauthenticated_access() override; void on_no_setup_connection() override; diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index f5be672c9a..0041c19905 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -105,7 +105,7 @@ void APIServer::setup() { return; } for (auto &c : this->clients_) { - if (!c->flags_.remove) + if (!c->flags_.remove && c->get_log_subscription_level() >= level) c->try_send_log_message(level, tag, message, message_len); } });