use a better name for restoreStateFrom...
This commit is contained in:
parent
149a722fc7
commit
130f4eb6a2
22
src/ha.h
22
src/ha.h
@ -186,27 +186,27 @@ namespace Ha {
|
||||
};
|
||||
|
||||
struct State : Config {
|
||||
char stateTopic[TOPIC_SIZE] = {};
|
||||
char topic[TOPIC_SIZE] = {};
|
||||
const char* jsonAttributesTemplate = nullptr;
|
||||
const char* valueTemplate = nullptr;
|
||||
|
||||
State(Component* cmp) : cmp(cmp) {}
|
||||
|
||||
void withStateTopic() {
|
||||
snprintf(stateTopic, sizeof(stateTopic), BASE_TOPIC"/state", cmp->id);
|
||||
snprintf(topic, sizeof(topic), BASE_TOPIC"/state", cmp->id);
|
||||
}
|
||||
|
||||
void updateState(const char* message) {
|
||||
if (stateTopic[0]) publisher(stateTopic, message);
|
||||
if (topic[0]) publisher(topic, message);
|
||||
}
|
||||
|
||||
protected:
|
||||
void buildConfig(JsonDocument& jsonDoc) override {
|
||||
if (stateTopic[0]) {
|
||||
jsonDoc["state_topic"] = (const char*)stateTopic;
|
||||
if (topic[0]) {
|
||||
jsonDoc["state_topic"] = (const char*)topic;
|
||||
if (jsonAttributesTemplate) {
|
||||
jsonDoc["json_attributes_template"] = jsonAttributesTemplate;
|
||||
jsonDoc["json_attributes_topic"] = (const char*)stateTopic;
|
||||
jsonDoc["json_attributes_topic"] = (const char*)topic;
|
||||
}
|
||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||
}
|
||||
@ -220,9 +220,9 @@ namespace Ha {
|
||||
|
||||
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
|
||||
|
||||
void restoreStateFromCommand() {
|
||||
void restoreStateFromTopic() {
|
||||
withStateTopic();
|
||||
mapRestoreStateTopics.insert({stateTopic, this});
|
||||
mapRestoreStateTopics.insert({State::topic, this});
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -519,12 +519,12 @@ namespace Ha {
|
||||
|
||||
[[deprecated("Use restoreStateFromCommand() instead")]]
|
||||
Builder& restoreFromState() {
|
||||
cmp->restoreStateFromCommand();
|
||||
cmp->restoreStateFromTopic();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder& restoreStateFromCommand() {
|
||||
cmp->restoreStateFromCommand();
|
||||
Builder& restoreStateFromTopic() {
|
||||
cmp->restoreStateFromTopic();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user