Skip to content

Commit

Permalink
Tweak tire pressure message sensor names
Browse files Browse the repository at this point in the history
  • Loading branch information
BigThunderSR committed Apr 1, 2024
1 parent f044e7b commit 1ebd57d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,28 @@ 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`;
unique_id = MQTT.convertName(this.vehicle.vin) + '_' + sensor;
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} }}`;
}

Expand All @@ -558,6 +560,7 @@ class MQTT {
return { topic, payload };
}


/**
*
* @param {DiagnosticElement} diag
Expand Down

0 comments on commit 1ebd57d

Please sign in to comment.