From 07c28594002d4745435ab9542178a79bdfb8c78a Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 18 May 2024 22:37:58 +0200 Subject: [PATCH] allow creation of DeviceConfig only with factory method --- gateway/include/ha.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 26385c3..6c856ff 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -18,8 +18,6 @@ namespace Ha { const char* area = nullptr; DeviceConfig* parent = nullptr; - DeviceConfig(const char* id) : id(id) {} - static DeviceConfig* create(const char* id) { return new DeviceConfig{ id }; } @@ -59,6 +57,9 @@ namespace Ha { parent = deviceConfig; return this; } + + protected: + DeviceConfig(const char* id) : id(id) {} }; struct Component { @@ -162,13 +163,13 @@ namespace Ha { } Builder& withSecondary(Component* c) { - c->mainDevice = new DeviceConfig{ cmp->id }; + c->mainDevice = DeviceConfig::create(cmp->id); return *this; } Builder& withDiagnostic(Component* c) { c->entityCategory = "diagnostic"; - c->mainDevice = new DeviceConfig{ cmp->id }; + c->mainDevice = DeviceConfig::create(cmp->id); return *this; }