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 {
|
struct State : Config {
|
||||||
char stateTopic[TOPIC_SIZE] = {};
|
char topic[TOPIC_SIZE] = {};
|
||||||
const char* jsonAttributesTemplate = nullptr;
|
const char* jsonAttributesTemplate = nullptr;
|
||||||
const char* valueTemplate = nullptr;
|
const char* valueTemplate = nullptr;
|
||||||
|
|
||||||
State(Component* cmp) : cmp(cmp) {}
|
State(Component* cmp) : cmp(cmp) {}
|
||||||
|
|
||||||
void withStateTopic() {
|
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) {
|
void updateState(const char* message) {
|
||||||
if (stateTopic[0]) publisher(stateTopic, message);
|
if (topic[0]) publisher(topic, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void buildConfig(JsonDocument& jsonDoc) override {
|
void buildConfig(JsonDocument& jsonDoc) override {
|
||||||
if (stateTopic[0]) {
|
if (topic[0]) {
|
||||||
jsonDoc["state_topic"] = (const char*)stateTopic;
|
jsonDoc["state_topic"] = (const char*)topic;
|
||||||
if (jsonAttributesTemplate) {
|
if (jsonAttributesTemplate) {
|
||||||
jsonDoc["json_attributes_template"] = 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;
|
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||||
}
|
}
|
||||||
@ -220,9 +220,9 @@ namespace Ha {
|
|||||||
|
|
||||||
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
|
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
|
||||||
|
|
||||||
void restoreStateFromCommand() {
|
void restoreStateFromTopic() {
|
||||||
withStateTopic();
|
withStateTopic();
|
||||||
mapRestoreStateTopics.insert({stateTopic, this});
|
mapRestoreStateTopics.insert({State::topic, this});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -519,12 +519,12 @@ namespace Ha {
|
|||||||
|
|
||||||
[[deprecated("Use restoreStateFromCommand() instead")]]
|
[[deprecated("Use restoreStateFromCommand() instead")]]
|
||||||
Builder& restoreFromState() {
|
Builder& restoreFromState() {
|
||||||
cmp->restoreStateFromCommand();
|
cmp->restoreStateFromTopic();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder& restoreStateFromCommand() {
|
Builder& restoreStateFromTopic() {
|
||||||
cmp->restoreStateFromCommand();
|
cmp->restoreStateFromTopic();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user