use precise length for storing state topic
This commit is contained in:
parent
130f4eb6a2
commit
12663901ab
9
src/ha.h
9
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user