use configTopic as a temporary object
This commit is contained in:
parent
adf1629aad
commit
962300712f
15
src/ha.h
15
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user