From 3e87d6043435f3b4cf4579618a8c46f996dccb8e Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 19 May 2024 01:31:41 +0200 Subject: [PATCH] use reference when building DeviceConfig --- gateway/include/ha.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 6c856ff..ef64de7 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -16,10 +16,10 @@ namespace Ha { const char* model = nullptr; const char* manufacturer = nullptr; const char* area = nullptr; - DeviceConfig* parent = nullptr; + const DeviceConfig* parent = nullptr; - static DeviceConfig* create(const char* id) { - return new DeviceConfig{ id }; + static DeviceConfig& create(const char* id) { + return *(new DeviceConfig{ id }); } void buildConfig(JsonDocument& jsonDoc) { @@ -33,29 +33,29 @@ 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: @@ -163,13 +163,13 @@ namespace Ha { } Builder& withSecondary(Component* c) { - c->mainDevice = DeviceConfig::create(cmp->id); + c->mainDevice = &DeviceConfig::create(cmp->id); return *this; } Builder& withDiagnostic(Component* c) { c->entityCategory = "diagnostic"; - c->mainDevice = DeviceConfig::create(cmp->id); + c->mainDevice = &DeviceConfig::create(cmp->id); return *this; }