/**
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/


"use strict";
var Tinkerforge = require('tinkerforge');
var devices = require('../lib/devices');

module.exports = function(RED) { 

	function tinkerForgeRemoteSwitchB(n) {
        RED.nodes.createNode(this,n);
        this.device = n.device;
        this.sensor = n.sensor;
        this.name = n.name;
	this.address = n.address;
	this.unit = n.unit;
        this.topic = n.topic;
        var node = this;

        node.ipcon = new Tinkerforge.IPConnection(); //devices[this.device].ipcon;
        node.ipcon.setAutoReconnect(true);
        var devs = devices.getDevices();
        node.ipcon.connect(devs[node.device].host, devs[node.device].port,function(error){
            if(error) {
                node.warn("couldn't connect");
            }
        });

        node.ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
        function(connectReason) {
            node.md = new Tinkerforge.BrickletRemoteSwitch(node.sensor, node.ipcon);
        });

	node.on('input', function(msg){             
	    if(node.md) {                 
	      if (typeof msg.payload === 'number') {                     
	        if (msg.payload == 1) {                         
		  node.md.switchSocketB(node.md.address, node.md.unit, Tinkerforge.BrickletRemoteSwitch.SWITCH_TO_ON);
		}
		else {
	          node.md.switchSocketB(node.md.address, node.md.unit, Tinkerforge.BrickletRemoteSwitch.SWITCH_TO_OFF);
 		}
	      }             
	    }         
        });

        node.on('close',function() {
            node.ipcon.disconnect();
        });
    }

    RED.nodes.registerType('RemoteSwitch Type B', tinkerForgeRemoteSwitchB);
}
@@ -1750,35 +1750,32 @@
 tchSocketB(node.
-md.
 address, node.md
@@ -1764,35 +1764,32 @@
 e.address, node.
-md.
 unit, Tinkerforg
@@ -1877,19 +1877,16 @@
 tB(node.
-md.
 address,
@@ -1891,19 +1891,16 @@
 s, node.
-md.
 unit, Ti

Update RemoteSwitchB.js