use same Builder for sensor specific fields
This commit is contained in:
parent
44d14d9a09
commit
6ebe06344c
@ -18,6 +18,7 @@ struct OilTankRoomSensorBuilder {
|
||||
->withParent(gatewayDevice);
|
||||
return Builder<TemperatureSensor>::instance(id)
|
||||
.asDevice(device)
|
||||
.withValueTemplate("{{ value_json.sensor.temperature }}")
|
||||
.withDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
|
||||
.withDiagnostic(new BatterySensor{id, "Battery level", "{{ ((states('sensor.oil_tank_room_battery_voltage')|float-2.5)|round(2)*100/2)|int }}"})
|
||||
.build();
|
||||
|
||||
@ -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 }}";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user