diff --git a/lib/robot.js b/lib/robot.js index 2d46660..b62ba0c 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -172,11 +172,7 @@ Robot.prototype.initConnections = function(opts) { Logger.warn(str); - _.forEach(opts.connections, function(conn, key) { - var name = _.isString(key) ? key : conn.name; - this.connection(name, conn); - }, this); - + this.performArraySetup(opts.connections, "connection"); return this.connections; } @@ -269,11 +265,7 @@ Robot.prototype.initDevices = function(opts) { Logger.warn(str); - _.forEach(opts.devices, function(device, key) { - var name = _.isString(key) ? key : device.name; - this.device(name, device); - }, this); - + this.performArraySetup(opts.devices, "device"); return this.devices; } @@ -421,3 +413,10 @@ Robot.prototype.halt = function(callback) { Robot.prototype.toString = function() { return "[Robot name='" + this.name + "']"; }; + +Robot.prototype.performArraySetup = function(things, typeOfThing) { + _.forEach(things, function(t, key) { + var name = _.isString(key) ? key : t.name; + this[typeOfThing](name, t); + }, this); +};