stjohnjohnson / smartthings-mqtt-bridge

Bridge between SmartThings and MQTT
https://hub.docker.com/r/stjohnjohnson/smartthings-mqtt-bridge/
MIT License
363 stars 242 forks source link

Duplicate subscriptions being made #191

Open iprak opened 5 years ago

iprak commented 5 years ago

The config values for SUFFIX_COMMAND and SUFFIX_WRITE_STATE are empty string by default, this causes handleSubscribeEvent to add duplicate subscriptions. I think we can just can just make one subscription if getTopicFor value is the same?

function handleSubscribeEvent (req, res) {
    // Subscribe to all events
    subscriptions = [];
    Object.keys(req.body.devices).forEach(function (property) {
        req.body.devices[property].forEach(function (device) {
            subscriptions.push(getTopicFor(device, property, TOPIC_COMMAND));
            subscriptions.push(getTopicFor(device, property, TOPIC_WRITE_STATE));
        });
    });