valueTemplate is specific to all state components
This commit is contained in:
parent
94ff72aefc
commit
5d9b0862bf
4
src/ha.h
4
src/ha.h
@ -161,6 +161,7 @@ namespace Ha {
|
||||
struct State : Config {
|
||||
char stateTopic[TOPIC_SIZE] = {};
|
||||
const char* jsonAttributesTemplate = nullptr;
|
||||
const char* valueTemplate = nullptr;
|
||||
|
||||
State(Component* cmp) : cmp(cmp) {}
|
||||
|
||||
@ -180,6 +181,7 @@ namespace Ha {
|
||||
jsonDoc["json_attributes_template"] = jsonAttributesTemplate;
|
||||
jsonDoc["json_attributes_topic"] = (const char*)stateTopic;
|
||||
}
|
||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||
}
|
||||
}
|
||||
private:
|
||||
@ -286,7 +288,6 @@ namespace Ha {
|
||||
|
||||
struct Sensor : Component, State {
|
||||
const char* unitMeasure = nullptr;
|
||||
const char* valueTemplate = nullptr;
|
||||
unsigned int precision = 2;
|
||||
inline static unordered_map<string, Sensor*> mapSensors;
|
||||
|
||||
@ -299,7 +300,6 @@ namespace Ha {
|
||||
Component::buildConfig(jsonDoc);
|
||||
State::buildConfig(jsonDoc);
|
||||
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||
if (isNumericSensor()) jsonDoc["suggested_display_precision"] = precision;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user