Merge branch 'doorbell' into huzzah
This commit is contained in:
commit
8d893645fe
@ -16,12 +16,10 @@ namespace Ha {
|
||||
const char* model = nullptr;
|
||||
const char* manufacturer = nullptr;
|
||||
const char* area = nullptr;
|
||||
DeviceConfig* parent = nullptr;
|
||||
const DeviceConfig* parent = nullptr;
|
||||
|
||||
DeviceConfig(const char* id) : id(id) {}
|
||||
|
||||
static DeviceConfig* create(const char* id) {
|
||||
return new DeviceConfig{ id };
|
||||
static DeviceConfig& create(const char* id) {
|
||||
return *(new DeviceConfig{ id });
|
||||
}
|
||||
|
||||
void buildConfig(JsonDocument& jsonDoc) {
|
||||
@ -35,30 +33,33 @@ namespace Ha {
|
||||
identifiers.add(id);
|
||||
}
|
||||
|
||||
DeviceConfig* withName(const char* value) {
|
||||
DeviceConfig& withName(const char* value) {
|
||||
name = value;
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DeviceConfig* withModel(const char* value) {
|
||||
DeviceConfig& withModel(const char* value) {
|
||||
model = value;
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DeviceConfig* withManufacturer(const char* value) {
|
||||
DeviceConfig& withManufacturer(const char* value) {
|
||||
manufacturer = value;
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DeviceConfig* withArea(const char* value) {
|
||||
DeviceConfig& withArea(const char* value) {
|
||||
area = value;
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DeviceConfig* withParent(DeviceConfig* deviceConfig) {
|
||||
DeviceConfig& withParent(const DeviceConfig* deviceConfig) {
|
||||
parent = deviceConfig;
|
||||
return this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
DeviceConfig(const char* id) : id(id) {}
|
||||
};
|
||||
|
||||
struct Component {
|
||||
@ -108,7 +109,6 @@ namespace Ha {
|
||||
publisher(configTopic, "");
|
||||
}
|
||||
};
|
||||
List<Component> Component::components;
|
||||
|
||||
struct AbstractBuilder {
|
||||
static List<AbstractBuilder> builders;
|
||||
@ -122,7 +122,6 @@ namespace Ha {
|
||||
builders.empty();
|
||||
}
|
||||
};
|
||||
List<AbstractBuilder> AbstractBuilder::builders;
|
||||
|
||||
template <class T>
|
||||
struct Builder : AbstractBuilder {
|
||||
@ -161,15 +160,14 @@ namespace Ha {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder& withSecondary(Component* c) {
|
||||
c->mainDevice = new DeviceConfig{ cmp->id };
|
||||
Builder& asSecondary(Component* c) {
|
||||
c->mainDevice = &DeviceConfig::create(cmp->id);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder& withDiagnostic(Component* c) {
|
||||
Builder& asDiagnostic(Component* c) {
|
||||
c->entityCategory = "diagnostic";
|
||||
c->mainDevice = new DeviceConfig{ cmp->id };
|
||||
return *this;
|
||||
return asSecondary(c);
|
||||
}
|
||||
|
||||
Builder& asDevice(DeviceConfig* deviceConfig) {
|
||||
@ -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