From aa4132db63f361b2d7efb1acadcd0297cb3f8eec Mon Sep 17 00:00:00 2001 From: fbuedding <100070891+fbuedding@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:04:45 +0200 Subject: [PATCH] update MQTTBindings.js --- lib/bindings/MQTTBinding.js | 168 ++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 93 deletions(-) diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index 6874ecc7..0c6b96eb 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -45,104 +45,86 @@ function generateTopics(callback) { const topics = []; config.getLogger().debug(context, 'Generating topics'); + + let MQTT_SHARE_SUBSCRIPTION_GROUP_VAR = ''; if (config.getConfig().mqtt.sharedSubscriptionsDisabled === true) { - // With leading slashes - topics.push('/+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push('/+/+/' + constants.MEASURES_SUFIX); - topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX); - topics.push('/+/+/' + constants.CONFIGURATION_SUFIX + '/' + constants.CONFIGURATION_COMMAND_SUFIX); - topics.push( - '/' + - constants.MQTT_TOPIC_PROTOCOL + - '/+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push('/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - - //Without leading slashes - topics.push('+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push('+/+/' + constants.MEASURES_SUFIX); - topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX); - topics.push('+/+/' + constants.CONFIGURATION_SUFIX + '/' + constants.CONFIGURATION_COMMAND_SUFIX); - topics.push( - constants.MQTT_TOPIC_PROTOCOL + - '/+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push('+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - } else { - let shareSubscriptionGroup = constants.MQTT_SHARE_SUBSCRIPTION_GROUP; + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR = constants.MQTT_SHARE_SUBSCRIPTION_GROUP; if (config.getConfig().mqtt.groupIdSufix !== undefined) { - shareSubscriptionGroup = - shareSubscriptionGroup.slice(0, -1) + + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR = + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR.slice(0, -1) + config.getConfig().mqtt.groupIdSufix + - shareSubscriptionGroup.slice(-1); + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR.slice(-1); } - // With leading slashes - topics.push(shareSubscriptionGroup + '/+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push( - shareSubscriptionGroup + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+' - ); - topics.push(shareSubscriptionGroup + '/+/+/' + constants.MEASURES_SUFIX); - topics.push(shareSubscriptionGroup + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX); - topics.push( - shareSubscriptionGroup + - '/+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push( - shareSubscriptionGroup + - '/' + - constants.MQTT_TOPIC_PROTOCOL + - '/+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push(shareSubscriptionGroup + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - topics.push( - shareSubscriptionGroup + - '/' + - constants.MQTT_TOPIC_PROTOCOL + - '/+/+/' + - constants.CONFIGURATION_COMMAND_UPDATE - ); - - //Without leading slashes - topics.push(shareSubscriptionGroup + '+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push(shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+'); - topics.push(shareSubscriptionGroup + '+/+/' + constants.MEASURES_SUFIX); - topics.push(shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX); - topics.push( - shareSubscriptionGroup + - '+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push( - shareSubscriptionGroup + - constants.MQTT_TOPIC_PROTOCOL + - '/+/+/' + - constants.CONFIGURATION_SUFIX + - '/' + - constants.CONFIGURATION_COMMAND_SUFIX - ); - topics.push(shareSubscriptionGroup + '+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); - topics.push( - shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE - ); } + // With leading slashes + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.MEASURES_SUFIX + '/+'); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + '/' + + constants.MQTT_TOPIC_PROTOCOL + + '/+/+/' + + constants.MEASURES_SUFIX + + '/+' + ); + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.MEASURES_SUFIX); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + ); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + '/+/+/' + + constants.CONFIGURATION_SUFIX + + '/' + + constants.CONFIGURATION_COMMAND_SUFIX + ); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + '/' + + constants.MQTT_TOPIC_PROTOCOL + + '/+/+/' + + constants.CONFIGURATION_SUFIX + + '/' + + constants.CONFIGURATION_COMMAND_SUFIX + ); + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + '/' + + constants.MQTT_TOPIC_PROTOCOL + + '/+/+/' + + constants.CONFIGURATION_COMMAND_UPDATE + ); + + //Without leading slashes + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.MEASURES_SUFIX + '/+'); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+' + ); + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.MEASURES_SUFIX); + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + '+/+/' + + constants.CONFIGURATION_SUFIX + + '/' + + constants.CONFIGURATION_COMMAND_SUFIX + ); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + constants.MQTT_TOPIC_PROTOCOL + + '/+/+/' + + constants.CONFIGURATION_SUFIX + + '/' + + constants.CONFIGURATION_COMMAND_SUFIX + ); + topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.CONFIGURATION_COMMAND_UPDATE); + topics.push( + MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + + constants.MQTT_TOPIC_PROTOCOL + + '/+/+/' + + constants.CONFIGURATION_COMMAND_UPDATE + ); + callback(null, topics); }