From 1ebd57dbe6fa9044a1e7abfa523de4ddb43579f9 Mon Sep 17 00:00:00 2001 From: BigThunderSR <17056173+BigThunderSR@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:04:06 -0500 Subject: [PATCH] Tweak tire pressure message sensor names --- src/mqtt.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/mqtt.js b/src/mqtt.js index 2d4d0a6f..60db3bac 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -513,8 +513,6 @@ class MQTT { } createSensorMessageConfigPayload(sensor, component, icon) { - //let topic = `${this.prefix}/sensor/${this.instance}/${sensor}_message/config`; - let topic, unique_id, sensor_name, value_template; if (!component) { topic = `${this.prefix}/sensor/${this.instance}/${sensor}_message/config`; @@ -522,17 +520,21 @@ class MQTT { sensor_name = `${sensor.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')} Message`; value_template = `{{ value_json.${sensor}_message }}`; } else { + let transformedComponent; + if (component === 'tire_pressure_rf_message') { + transformedComponent = 'Tire Pressure: Right Front Message'; + } else if (component === 'tire_pressure_lf_message') { + transformedComponent = 'Tire Pressure: Left Front Message'; + } else if (component === 'tire_pressure_lr_message') { + transformedComponent = 'Tire Pressure: Left Rear Message'; + } else if (component === 'tire_pressure_rr_message') { + transformedComponent = 'Tire Pressure: Right Rear Message'; + } else { + transformedComponent = component.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); + } topic = `${this.prefix}/sensor/${this.instance}/${sensor}_${component}_message/config`; unique_id = MQTT.convertName(this.vehicle.vin) + '_' + sensor + '_' + component; - let component_words = component.split('_'); - component_words = component_words.map(component_word => { - if (component_word === 'lf' || component_word === 'rf' || component_word === 'lr' || component_word === 'rr') { - return component_word.toUpperCase(); - } else { - return component_word.charAt(0).toUpperCase() + component_word.slice(1); - } - }); - sensor_name = component_words.join(' '); + sensor_name = `${transformedComponent}`; value_template = `{{ value_json.${component} }}`; } @@ -558,6 +560,7 @@ class MQTT { return { topic, payload }; } + /** * * @param {DiagnosticElement} diag