change parameters' order in Component constructor - id is mandatory

This commit is contained in:
Nicu Hodos 2024-10-28 12:05:34 +01:00
parent 1787f20ddb
commit 92b5837538

View File

@ -87,11 +87,12 @@ namespace Ha {
}
};
const char* entityCategory = nullptr;
const char* deviceClass = nullptr;
const char* name = nullptr;
const char* id = nullptr;
const char* type = nullptr;
const char* name = nullptr;
const char* entityCategory = nullptr;
const char* deviceClass = nullptr;
char configTopic[TOPIC_SIZE];
JsonPairs<bool> jsonBooleans;
JsonPairs<float> jsonNumbers;
@ -100,7 +101,7 @@ namespace Ha {
static List<Component> components;
bool multiValueComponent = false;
Component(const char* name, const char* id, const char* type) : name(name), id(id), type(type) {
Component(const char* id, const char* name, const char* type) : id(id), type(type), name(name) {
components.add(this);
}
@ -297,7 +298,7 @@ namespace Ha {
struct Button : Component, Command {
Button(const char* name, const char* id, onMessage f = nullptr) : Component(name, id, "button"), Command(this, f) {}
Button(const char* name, const char* id, onMessage f = nullptr) : Component(id, name, "button"), Command(this, f) {}
void buildConfig(JsonDocument& jsonDoc) override {
Component::buildConfig(jsonDoc);
@ -344,7 +345,7 @@ namespace Ha {
struct Switch : Component, StatefulCommand {
Switch(const char* name, const char* id, onMessage f = nullptr) : Component(name, id, "switch"), StatefulCommand(this, f) {}
Switch(const char* name, const char* id, onMessage f = nullptr) : Component(id, name, "switch"), StatefulCommand(this, f) {}
void updateState(bool state) {
State::updateState(state ? "ON" : "OFF");
@ -359,7 +360,7 @@ namespace Ha {
struct Number : Component, StatefulCommand {
unsigned int min, max, step;
Number(const char* name, const char* id, onMessage f) : Component(name, id, "number"), StatefulCommand(this, f) {}
Number(const char* name, const char* id, onMessage f) : Component(id, name, "number"), StatefulCommand(this, f) {}
void updateState(unsigned int value) {
State::updateState(to_string(value).c_str());
@ -380,7 +381,7 @@ namespace Ha {
unsigned int precision = 2;
static unordered_map<string, Sensor*> mapSensors;
Sensor(const char* name, const char* id) : Component(name, id, "sensor"), State(this) {
Sensor(const char* name, const char* id) : Component(id, name, "sensor"), State(this) {
withStateTopic();
mapSensors.insert({ string(id), this });
}