From 962300712fc1d82abde307b3a8c0fb8868668515 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 10 Oct 2025 18:28:27 +0200 Subject: [PATCH] use configTopic as a temporary object --- src/ha.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ha.h b/src/ha.h index 8ebbc6b..ad94e11 100644 --- a/src/ha.h +++ b/src/ha.h @@ -96,11 +96,15 @@ namespace Ha { char message[JSON_SIZE] = {}; serializeJson(jsonDoc, message); + auto configTopic = buildConfigTopic(); publisher(configTopic, message); + delete configTopic; } void publishCleanupConfig() { + auto configTopic = buildConfigTopic(); publisher(configTopic, ""); + delete configTopic; } void toJson(JsonDocument& jsonDoc) { @@ -119,11 +123,8 @@ namespace Ha { jsonDoc["name"] = name; buildUniqueId(jsonDoc); - buildConfigTopic(); } private: - char configTopic[TOPIC_SIZE] = {}; - void buildUniqueId(JsonDocument& jsonDoc) { char uniqueId[50]; if (multiValueComponent && deviceClass) { @@ -134,12 +135,14 @@ namespace Ha { jsonDoc["unique_id"] = uniqueId; } - void buildConfigTopic() { + const char* buildConfigTopic() { + char* configTopic = new char[TOPIC_SIZE]; if (multiValueComponent && deviceClass) { - snprintf(configTopic, sizeof(configTopic), CONFIG_TOPIC"_%s""/config", type, deviceClass, id); + snprintf(configTopic, TOPIC_SIZE, CONFIG_TOPIC"_%s""/config", type, deviceClass, id); } else { - snprintf(configTopic, sizeof(configTopic), CONFIG_TOPIC"/config", type, id); + snprintf(configTopic, TOPIC_SIZE, CONFIG_TOPIC"/config", type, id); } + return configTopic; } };