From c88e832fbebf71c02ff59d351aefdebf7464f5dd Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 15 May 2024 11:15:12 +0200 Subject: [PATCH] cleanup --- gateway/include/ha.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 8ee972d..f5a4685 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -8,6 +8,7 @@ namespace Ha { uint16_t (*publisher)(const char* topic, const char* message); + typedef void (*onMessage)(const char* msg); struct DeviceConfig { const char* id = nullptr; @@ -17,7 +18,6 @@ namespace Ha { const char* area = nullptr; DeviceConfig* parent = nullptr; - DeviceConfig() {} DeviceConfig(const char* id) : id(id) {} DeviceConfig(DeviceConfig& d) : id(d.id), name(d.name), model(d.model), manufacturer(d.manufacturer), area(d.area), parent(d.parent) {} @@ -107,7 +107,6 @@ namespace Ha { publisher(configTopic, ""); } }; - List Component::components; struct AbstractBuilder { @@ -124,20 +123,16 @@ namespace Ha { }; List AbstractBuilder::builders; - template + template struct Builder : AbstractBuilder { T* cmp; - Builder() : AbstractBuilder() {} Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {} + Builder(const char* id) : AbstractBuilder() { cmp = new T{id}; } - static Builder& instance() { - return *(new Builder()); - } - static Builder& instance(T* c) { return *(new Builder(c)); } @@ -167,7 +162,6 @@ namespace Ha { } }; - typedef void (*onMessage)(const char* msg); struct Command : Component { char commandTopic[TOPIC_SIZE]; onMessage f; @@ -285,20 +279,18 @@ namespace Ha { }; struct HumiditySensor : Sensor { - HumiditySensor(const char* name, const char* id) : Sensor(name, id) { - name = "Humidity"; + HumiditySensor(const char* id, const char* name = "Humidity") : Sensor(name, id) { deviceClass = "humidity"; unitMeasure = "%"; - valueTemplate = "{{ value_json.sensor.humidity }}"; + // valueTemplate = "{{ value_json.sensor.humidity }}"; } }; struct PressureSensor : Sensor { - PressureSensor(const char* name, const char* id) : Sensor(name, id) { - name = "Pressure"; + PressureSensor(const char* id, const char* name = "Pressure") : Sensor(name, id) { deviceClass = "pressure"; unitMeasure = "hPa"; - valueTemplate = "{{ value_json.sensor.pressure }}"; + // valueTemplate = "{{ value_json.sensor.pressure }}"; } }; }