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] = {};
|
char message[JSON_SIZE] = {};
|
||||||
serializeJson(jsonDoc, message);
|
serializeJson(jsonDoc, message);
|
||||||
|
|
||||||
|
auto configTopic = buildConfigTopic();
|
||||||
publisher(configTopic, message);
|
publisher(configTopic, message);
|
||||||
|
delete configTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishCleanupConfig() {
|
void publishCleanupConfig() {
|
||||||
|
auto configTopic = buildConfigTopic();
|
||||||
publisher(configTopic, "");
|
publisher(configTopic, "");
|
||||||
|
delete configTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void toJson(JsonDocument& jsonDoc) {
|
void toJson(JsonDocument& jsonDoc) {
|
||||||
@ -119,11 +123,8 @@ namespace Ha {
|
|||||||
jsonDoc["name"] = name;
|
jsonDoc["name"] = name;
|
||||||
|
|
||||||
buildUniqueId(jsonDoc);
|
buildUniqueId(jsonDoc);
|
||||||
buildConfigTopic();
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
char configTopic[TOPIC_SIZE] = {};
|
|
||||||
|
|
||||||
void buildUniqueId(JsonDocument& jsonDoc) {
|
void buildUniqueId(JsonDocument& jsonDoc) {
|
||||||
char uniqueId[50];
|
char uniqueId[50];
|
||||||
if (multiValueComponent && deviceClass) {
|
if (multiValueComponent && deviceClass) {
|
||||||
@ -134,12 +135,14 @@ namespace Ha {
|
|||||||
jsonDoc["unique_id"] = uniqueId;
|
jsonDoc["unique_id"] = uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildConfigTopic() {
|
const char* buildConfigTopic() {
|
||||||
|
char* configTopic = new char[TOPIC_SIZE];
|
||||||
if (multiValueComponent && deviceClass) {
|
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 {
|
} 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