From 2d71abfaebf4afa12f33dccd3d7b953de0581b03 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Thu, 16 May 2024 10:05:24 +0200 Subject: [PATCH] use same Builder for sensor specific fields --- gateway/include/ha.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index f5a4685..1897ea7 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -145,6 +145,21 @@ namespace Ha { return static_cast(cmp); } + Builder& withDeviceClass(const char* value) { + cmp->deviceClass = value; + return *this; + } + + Builder& withUnitMseasure(const char* value) { + cmp->unitMeasure = value; + return *this; + } + + Builder& withValueTemplate(const char* value) { + cmp->valueTemplate = value; + return *this; + } + Builder& withSecondary(Component* c) { c->mainDevice = new DeviceConfig{ cmp->id }; return *this; @@ -255,10 +270,9 @@ namespace Ha { }; struct TemperatureSensor : Sensor { - TemperatureSensor(const char* id) : Sensor("Temperature", id) { + TemperatureSensor(const char* id, const char* name = "Temperature") : Sensor(name, id) { deviceClass = "temperature"; unitMeasure = "°C"; - valueTemplate = "{{ value_json.sensor.temperature }}"; } };