From 493c7265ab412393ec138978bc81071590add4e0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 31 Aug 2026 20:44:29 -0400 Subject: [PATCH] Fix the IPv6 target guard so it actually compiles in --- esphome/components/api/api_outgoing_connection.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_outgoing_connection.cpp b/esphome/components/api/api_outgoing_connection.cpp index 1bdf451245..a2f7e47e35 100644 --- a/esphome/components/api/api_outgoing_connection.cpp +++ b/esphome/components/api/api_outgoing_connection.cpp @@ -22,17 +22,21 @@ void OutgoingConnectionManager::setup() { #ifndef API_OUTGOING_CONNECTION_HOST this->target_pref_ = global_preferences->make_preference(629847102UL, true); if (!this->target_pref_.load(&this->saved_)) { + ESP_LOGD(TAG, "No saved target"); this->saved_ = {}; } // Defend against a corrupt or truncated preference blob this->saved_.host[socket::SOCKADDR_STR_LEN - 1] = '\0'; -#ifndef USE_NETWORK_IPV6 + // The macro is defined with a true/false value, not conditionally +#if !USE_NETWORK_IPV6 if (strchr(this->saved_.host, ':') != nullptr) { // Remembered by an earlier IPv6 build; set_sockaddr() would silently // turn it into 255.255.255.255 ESP_LOGW(TAG, "Clearing unusable IPv6 target %s", this->saved_.host); this->saved_ = {}; - this->target_pref_.save(&this->saved_); + if (!this->target_pref_.save(&this->saved_) || !global_preferences->sync()) { + ESP_LOGW(TAG, "Failed to clear target"); + } } #endif #endif