server.js
function migrateState (version) {
    // Make sure the object exists
    if (!config.mqtt) {
        config.mqtt = {};
    }

    // This is the previous default, but it's totally wrong
    if (!config.mqtt.preface) {
        config.mqtt.preface = '/smartthings';
    }

    // Default Suffixes
    if (!config.mqtt[SUFFIX_READ_STATE]) {
        config.mqtt[SUFFIX_READ_STATE] = '';
    }
    if (!config.mqtt[SUFFIX_COMMAND]) {
        config.mqtt[SUFFIX_COMMAND] = '';
    }
    if (!config.mqtt[SUFFIX_WRITE_STATE]) {
        config.mqtt[SUFFIX_WRITE_STATE] = '';
    }

    // Default retain
    if (config.mqtt[RETAIN] !== false) {
        config.mqtt[RETAIN] = true;
    }

    // Default port
    if (!config.port) {
        config.port = 8080;
    }

    // Default protocol
    if (!url.parse(config.mqtt.host).protocol) {
        config.mqtt.host = 'mqtt://' + config.mqtt.host;
    }

    // Stuff was previously in subscription.json, load that and migrate it
    var SUBSCRIPTION_FILE = path.join(CONFIG_DIR, 'subscription.json');
    if (semver.lt(version, '1.1.0') && fs.existsSync(SUBSCRIPTION_FILE)) {
        var oldState = jsonfile.readFileSync(SUBSCRIPTION_FILE);
        callback = oldState.callback;
        subscriptions = oldState.topics;
    }

    saveState();
}
function migrateState (version) {
    // Make sure the object exists
    if (!config.mqtt) {
        config.mqtt = {};
    }

    // This is the previous default, but it's totally wrong
    if (!config.mqtt.preface) {
        config.mqtt.preface = '/smartthings';
    }

    // Default Suffixes
    if (!config.mqtt[SUFFIX_READ_STATE]) {
        config.mqtt[SUFFIX_READ_STATE] = '';
    }
    if (!config.mqtt[SUFFIX_COMMAND]) {
        config.mqtt[SUFFIX_COMMAND] = '';
    }
    if (!config.mqtt[SUFFIX_WRITE_STATE]) {
        config.mqtt[SUFFIX_WRITE_STATE] = '';
    }

    // Default retain
    if (config.mqtt[RETAIN] !== false) {
        config.mqtt[RETAIN] = true;
    }

    // Default port
    if (!config.port) {
        config.port = 8080;
    }

    // Default protocol
    if (!url.parse(config.mqtt.host).protocol) {
        config.mqtt.host = 'mqtt://' + config.mqtt.host;
    }

    // Stuff was previously in subscription.json, load that and migrate it
    var SUBSCRIPTION_FILE = path.join(CONFIG_DIR, 'subscription.json');
    if (semver.lt(version, '1.1.0') && fs.existsSync(SUBSCRIPTION_FILE)) {
        var oldState = jsonfile.readFileSync(SUBSCRIPTION_FILE);
        callback = oldState.callback;
        subscriptions = oldState.topics;
    }

    saveState();
}
function migrateState ( version ) { // Make sure the object exists if ( ! config . mqtt ) { config . mqtt = { } ; } // This is the previous default, but it's totally wrong if ( ! config . mqtt . preface ) { config . mqtt . preface = '/smartthings' ; } // Default Suffixes if ( ! config . mqtt [ SUFFIX_READ_STATE ] ) { config . mqtt [ SUFFIX_READ_STATE ] = '' ; } if ( ! config . mqtt [ SUFFIX_COMMAND ] ) { config . mqtt [ SUFFIX_COMMAND ] = '' ; } if ( ! config . mqtt [ SUFFIX_WRITE_STATE ] ) { config . mqtt [ SUFFIX_WRITE_STATE ] = '' ; } // Default retain if ( config . mqtt [ RETAIN ] !== false ) { config . mqtt [ RETAIN ] = true ; } // Default port if ( ! config . port ) { config . port = 8080 ; } // Default protocol if ( ! url . parse ( config . mqtt . host ) . protocol ) { config . mqtt . host = 'mqtt://' + config . mqtt . host ; } // Stuff was previously in subscription.json, load that and migrate it var SUBSCRIPTION_FILE = path . join ( CONFIG_DIR , 'subscription.json' ) ; if ( semver . lt ( version , '1.1.0' ) && fs . existsSync ( SUBSCRIPTION_FILE ) ) { var oldState = jsonfile . readFileSync ( SUBSCRIPTION_FILE ) ; callback = oldState . callback ; subscriptions = oldState . topics ; } saveState ( ) ; }
Migrate the configuration from the current version to the latest version
@method migrateState
@param  {String}     version Version the state was written in before
Migrate the configuration from the current version to the latest version