use map to find sensors
This commit is contained in:
parent
13bbb5ffc4
commit
8428c702f7
@ -109,7 +109,6 @@ namespace Ha {
|
||||
publisher(configTopic, "");
|
||||
}
|
||||
};
|
||||
List<Component> Component::components;
|
||||
|
||||
struct AbstractBuilder {
|
||||
static List<AbstractBuilder> builders;
|
||||
@ -123,7 +122,6 @@ namespace Ha {
|
||||
builders.empty();
|
||||
}
|
||||
};
|
||||
List<AbstractBuilder> AbstractBuilder::builders;
|
||||
|
||||
template <class T>
|
||||
struct Builder : AbstractBuilder {
|
||||
@ -198,7 +196,6 @@ namespace Ha {
|
||||
}
|
||||
|
||||
};
|
||||
unordered_map<string, Command*> Command::mapCommands;
|
||||
|
||||
struct Button : Command {
|
||||
|
||||
@ -227,7 +224,7 @@ namespace Ha {
|
||||
if (stateTopic[0]) jsonDoc["state_topic"] = stateTopic;
|
||||
}
|
||||
|
||||
void publishState(bool state) {
|
||||
void updateState(bool state) {
|
||||
publisher(stateTopic, state ? "ON" : "OFF");
|
||||
}
|
||||
};
|
||||
@ -235,13 +232,11 @@ namespace Ha {
|
||||
struct Sensor : Component, StateConfig<Sensor> {
|
||||
const char* unitMeasure = nullptr;
|
||||
const char* valueTemplate = nullptr;
|
||||
|
||||
Sensor() : Component(name, id, "sensor") {
|
||||
withStateTopic();
|
||||
}
|
||||
static unordered_map<string, Sensor*> mapSensors;
|
||||
|
||||
Sensor(const char* name, const char* id) : Component(name, id, "sensor") {
|
||||
withStateTopic();
|
||||
mapSensors.insert({ id, this });
|
||||
}
|
||||
|
||||
void buildUniqueId(char* uniqueId) override {
|
||||
@ -267,6 +262,10 @@ namespace Ha {
|
||||
jsonDoc["state_topic"] = stateTopic;
|
||||
jsonDoc["suggested_display_precision"] = 2;
|
||||
}
|
||||
|
||||
void updateState(const char* message) {
|
||||
publisher(stateTopic, message);
|
||||
}
|
||||
};
|
||||
|
||||
struct TemperatureSensor : Sensor {
|
||||
@ -307,4 +306,9 @@ namespace Ha {
|
||||
// valueTemplate = "{{ value_json.sensor.pressure }}";
|
||||
}
|
||||
};
|
||||
|
||||
List<Component> Component::components;
|
||||
List<AbstractBuilder> AbstractBuilder::builders;
|
||||
unordered_map<string, Command*> Command::mapCommands;
|
||||
unordered_map<string, Sensor*> Sensor::mapSensors;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user