From 4dbe19a56eb2bba16528dfe8afee77da1cd10167 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 11 Jul 2025 09:22:40 -1000 Subject: [PATCH] Auto auth if no password is required Next step in password deprecation --- esphome/components/api/api_connection.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 3df01d0977..b7ace1265f 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1467,15 +1467,22 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) { resp.invalid_password = !correct; if (correct) { ESP_LOGD(TAG, "%s connected", this->get_client_combined_info().c_str()); + + // Check if we're already authenticated (e.g., from auto-auth during hello) + bool was_authenticated = this->flags_.connection_state == static_cast(ConnectionState::AUTHENTICATED); this->flags_.connection_state = static_cast(ConnectionState::AUTHENTICATED); + + // Only trigger events if we weren't already authenticated + if (!was_authenticated) { #ifdef USE_API_CLIENT_CONNECTED_TRIGGER - this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_); + this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_); #endif #ifdef USE_HOMEASSISTANT_TIME - if (homeassistant::global_homeassistant_time != nullptr) { - this->send_time_request(); - } + if (homeassistant::global_homeassistant_time != nullptr) { + this->send_time_request(); + } #endif + } } return resp; }