use reference when building DeviceConfig

This commit is contained in:
Nicu Hodos 2024-05-19 01:31:41 +02:00
parent 07c2859400
commit 3e87d60434

View File

@ -16,10 +16,10 @@ namespace Ha {
const char* model = nullptr; const char* model = nullptr;
const char* manufacturer = nullptr; const char* manufacturer = nullptr;
const char* area = nullptr; const char* area = nullptr;
DeviceConfig* parent = nullptr; const DeviceConfig* parent = nullptr;
static DeviceConfig* create(const char* id) { static DeviceConfig& create(const char* id) {
return new DeviceConfig{ id }; return *(new DeviceConfig{ id });
} }
void buildConfig(JsonDocument& jsonDoc) { void buildConfig(JsonDocument& jsonDoc) {
@ -33,29 +33,29 @@ namespace Ha {
identifiers.add(id); identifiers.add(id);
} }
DeviceConfig* withName(const char* value) { DeviceConfig& withName(const char* value) {
name = value; name = value;
return this; return *this;
} }
DeviceConfig* withModel(const char* value) { DeviceConfig& withModel(const char* value) {
model = value; model = value;
return this; return *this;
} }
DeviceConfig* withManufacturer(const char* value) { DeviceConfig& withManufacturer(const char* value) {
manufacturer = value; manufacturer = value;
return this; return *this;
} }
DeviceConfig* withArea(const char* value) { DeviceConfig& withArea(const char* value) {
area = value; area = value;
return this; return *this;
} }
DeviceConfig* withParent(DeviceConfig* deviceConfig) { DeviceConfig& withParent(const DeviceConfig* deviceConfig) {
parent = deviceConfig; parent = deviceConfig;
return this; return *this;
} }
protected: protected:
@ -163,13 +163,13 @@ namespace Ha {
} }
Builder& withSecondary(Component* c) { Builder& withSecondary(Component* c) {
c->mainDevice = DeviceConfig::create(cmp->id); c->mainDevice = &DeviceConfig::create(cmp->id);
return *this; return *this;
} }
Builder& withDiagnostic(Component* c) { Builder& withDiagnostic(Component* c) {
c->entityCategory = "diagnostic"; c->entityCategory = "diagnostic";
c->mainDevice = DeviceConfig::create(cmp->id); c->mainDevice = &DeviceConfig::create(cmp->id);
return *this; return *this;
} }