From ade84dc6c08e6639c0d02e28be7a0111c72ebf4f Mon Sep 17 00:00:00 2001 From: Koenkk Date: Thu, 20 Sep 2018 16:16:57 +0200 Subject: [PATCH] Fix MQTT command with prefix, introduced in #c22f8b3. #387 --- lib/controller.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index fc914993..78443f6a 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -10,8 +10,7 @@ const objectAssignDeep = require(`object-assign-deep`); const mqttConfigRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/\\w+`, 'g'); const mqttDeviceRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-]+/set`, 'g'); -const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-] - +/[\\w\\s\\d.-]+/set`, 'g'); +const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-]+/[\\w\\s\\d.-]+/set`, 'g'); const pollInterval = 60 * 1000; // seconds * 1000. const softResetTimeout = 3600 * 1000; // seconds * 1000. @@ -479,7 +478,7 @@ class Controller { } handleMQTTMessageDevice(topic, message, withPrefix) { - const friendlyName = topic.split('/').slice(-2)[0]; + const friendlyName = topic.split('/').slice(withPrefix ? -3 : -2)[0]; const topicPrefix = withPrefix ? topic.split('/').slice(-3)[0] : ''; // Map friendlyName to deviceID.