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