fix bug when generating mqtt configuration - a secondary component must have a device_class otherwise it will override the main component configuration

This commit is contained in:
Nicu Hodos 2025-06-07 10:41:59 +02:00
parent 4e12ca89eb
commit 0a7554d843

View File

@ -38,16 +38,16 @@ namespace OilTank {
.withModel("Pro Mini")
.withArea("Basement")
.withParent(gatewayDevice);
return Builder<Sensor>::instance(new Sensor{ "Depth", id })
return Builder<Sensor>::instance(new Sensor{ "Level", id })
.asDevice(device)
.withDeviceClass("distance")
.withUnitMeasure("cm")
.withValueTemplate("{{ value_json.sensor.value }}")
.withUnitMeasure("%")
.withIcon("mdi:hydraulic-oil-level")
.withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}")
.addSecondary(
Builder<Sensor>::instance(new Sensor{ "Level", id })
.withUnitMeasure("%")
.withIcon("mdi:hydraulic-oil-level")
.withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}")
Builder<Sensor>::instance(new Sensor{ "Depth", id })
.withDeviceClass("distance")
.withUnitMeasure("cm")
.withValueTemplate("{{ value_json.sensor.value }}")
.build()
)
.addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})