From 0a7554d843917a5ca35c1e40b8eb1ce17181ed6f Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sat, 7 Jun 2025 10:41:59 +0200 Subject: [PATCH] fix bug when generating mqtt configuration - a secondary component must have a device_class otherwise it will override the main component configuration --- gateway/include/devices.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gateway/include/devices.h b/gateway/include/devices.h index 342ab7d..494b156 100644 --- a/gateway/include/devices.h +++ b/gateway/include/devices.h @@ -38,16 +38,16 @@ namespace OilTank { .withModel("Pro Mini") .withArea("Basement") .withParent(gatewayDevice); - return Builder::instance(new Sensor{ "Depth", id }) + return Builder::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::instance(new Sensor{ "Level", id }) - .withUnitMeasure("%") - .withIcon("mdi:hydraulic-oil-level") - .withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}") + Builder::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 }}"})