From 83884970384ba4a2923352100ad3b822fd364e73 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 25 Jun 2025 23:18:50 +0200 Subject: [PATCH 1/2] tidy issues --- esphome/components/api/api_connection.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index ea604e470e..0a1b1eeebc 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -505,15 +505,15 @@ class APIConnection : public APIServerConnection { // Destructor ~MessageCreator() { - if (has_tagged_string_ptr()) { - delete get_string_ptr(); + if (has_tagged_string_ptr_()) { + delete get_string_ptr_(); } } // Copy constructor MessageCreator(const MessageCreator &other) { - if (other.has_tagged_string_ptr()) { - auto *str = new std::string(*other.get_string_ptr()); + if (other.has_tagged_string_ptr_()) { + auto *str = new std::string(*other.get_string_ptr_()); data_.tagged = reinterpret_cast(str) | 1; } else { data_ = other.data_; @@ -527,12 +527,12 @@ class APIConnection : public APIServerConnection { MessageCreator &operator=(const MessageCreator &other) { if (this != &other) { // Clean up current string data if needed - if (has_tagged_string_ptr()) { - delete get_string_ptr(); + if (has_tagged_string_ptr_()) { + delete get_string_ptr_(); } // Copy new data - if (other.has_tagged_string_ptr()) { - auto *str = new std::string(*other.get_string_ptr()); + if (other.has_tagged_string_ptr_()) { + auto *str = new std::string(*other.get_string_ptr_()); data_.tagged = reinterpret_cast(str) | 1; } else { data_ = other.data_; @@ -544,8 +544,8 @@ class APIConnection : public APIServerConnection { MessageCreator &operator=(MessageCreator &&other) noexcept { if (this != &other) { // Clean up current string data if needed - if (has_tagged_string_ptr()) { - delete get_string_ptr(); + if (has_tagged_string_ptr_()) { + delete get_string_ptr_(); } // Move data data_ = other.data_; @@ -561,10 +561,10 @@ class APIConnection : public APIServerConnection { private: // Check if this contains a string pointer - bool has_tagged_string_ptr() const { return (data_.tagged & 1) != 0; } + bool has_tagged_string_ptr_() const { return (data_.tagged & 1) != 0; } // Get the actual string pointer (clears the tag bit) - std::string *get_string_ptr() const { return reinterpret_cast(data_.tagged & ~uintptr_t(1)); } + std::string *get_string_ptr_() const { return reinterpret_cast(data_.tagged & ~uintptr_t(1)); } union { MessageCreatorPtr ptr; From 6b5b0815d72a122165323a77894e0ede4136f5b9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 25 Jun 2025 23:26:57 +0200 Subject: [PATCH 2/2] tidy issues --- esphome/components/api/api_connection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 4b1ab73654..06ca3600ed 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1910,13 +1910,13 @@ void APIConnection::process_batch_() { uint16_t APIConnection::MessageCreator::operator()(EntityBase *entity, APIConnection *conn, uint32_t remaining_size, bool is_single, uint16_t message_type) const { - if (has_tagged_string_ptr()) { + if (has_tagged_string_ptr_()) { // Handle string-based messages switch (message_type) { #ifdef USE_EVENT case EventResponse::MESSAGE_TYPE: { auto *e = static_cast(entity); - return APIConnection::try_send_event_response(e, *get_string_ptr(), conn, remaining_size, is_single); + return APIConnection::try_send_event_response(e, *get_string_ptr_(), conn, remaining_size, is_single); } #endif default: