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