diff --git a/src/ha.h b/src/ha.h index d89a6be..4f43010 100644 --- a/src/ha.h +++ b/src/ha.h @@ -186,14 +186,17 @@ namespace Ha { }; struct State : Config { - char topic[TOPIC_SIZE] = {}; + char* topic; const char* jsonAttributesTemplate = nullptr; const char* valueTemplate = nullptr; - State(Component* cmp) : cmp(cmp) {} + State(Component* cmp) : cmp(cmp) { + auto len = snprintf(nullptr, 0, BASE_TOPIC"/state", cmp->id); + topic = new char[len + 1]; + } void withStateTopic() { - snprintf(topic, sizeof(topic), BASE_TOPIC"/state", cmp->id); + sprintf(topic, BASE_TOPIC"/state", cmp->id); } void updateState(const char* message) {