use same Builder for sensor specific fields

This commit is contained in:
Nicu Hodos 2024-05-16 10:05:24 +02:00
parent c88e832fbe
commit 2d71abfaeb

View File

@ -145,6 +145,21 @@ namespace Ha {
return static_cast<T*>(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 }}";
}
};