From 946f8deb3d8a884c4562f33d68fb98bb7d11fbc8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Nov 2025 07:22:27 -0600 Subject: [PATCH] tweak naming --- esphome/components/api/api_server.cpp | 10 +++++----- esphome/components/api/api_server.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index 54b8a58de6..225ed5178c 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -436,7 +436,7 @@ void APIServer::add_state_subscription_(const char *entity_id, const char *attri std::function f, bool once) { this->state_subs_.push_back(HomeAssistantStateSubscription{ .entity_id_ = entity_id, .attribute_ = attribute, .callback_ = std::move(f), .once_ = once, - // entity_id_copy_ and attribute_copy_ remain nullptr (no heap allocation) + // entity_id_dynamic_storage_ and attribute_dynamic_storage_ remain nullptr (no heap allocation) }); } @@ -445,12 +445,12 @@ void APIServer::add_state_subscription_(std::string entity_id, optional f, bool once) { HomeAssistantStateSubscription sub; // Allocate heap storage for the strings - sub.entity_id_copy_ = std::make_unique(std::move(entity_id)); - sub.entity_id_ = sub.entity_id_copy_->c_str(); + sub.entity_id_dynamic_storage_ = std::make_unique(std::move(entity_id)); + sub.entity_id_ = sub.entity_id_dynamic_storage_->c_str(); if (attribute.has_value()) { - sub.attribute_copy_ = std::make_unique(std::move(attribute.value())); - sub.attribute_ = sub.attribute_copy_->c_str(); + sub.attribute_dynamic_storage_ = std::make_unique(std::move(attribute.value())); + sub.attribute_ = sub.attribute_dynamic_storage_->c_str(); } else { sub.attribute_ = nullptr; } diff --git a/esphome/components/api/api_server.h b/esphome/components/api/api_server.h index be69153a27..547a978d50 100644 --- a/esphome/components/api/api_server.h +++ b/esphome/components/api/api_server.h @@ -159,10 +159,10 @@ class APIServer : public Component, public Controller { std::function callback_; bool once_; - // Storage for external components using std::string API (custom_api_device.h) - // These are only allocated when using the std::string overload - std::unique_ptr entity_id_copy_; - std::unique_ptr attribute_copy_; + // Dynamic storage for external components using std::string API (custom_api_device.h) + // These are only allocated when using the std::string overload (nullptr for const char* overload) + std::unique_ptr entity_id_dynamic_storage_; + std::unique_ptr attribute_dynamic_storage_; }; // New const char* overload (for internal components - zero allocation)