Stop giving robots random names, use inc. counter
This commit is contained in:
parent
952a25ac2c
commit
681e197ed9
15
lib/robot.js
15
lib/robot.js
|
@ -17,6 +17,9 @@ var initializer = require("./initializer"),
|
||||||
var Async = require("async"),
|
var Async = require("async"),
|
||||||
EventEmitter = require("events").EventEmitter;
|
EventEmitter = require("events").EventEmitter;
|
||||||
|
|
||||||
|
// used when creating default robot names
|
||||||
|
var ROBOT_ID = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Robot instance based on provided options
|
* Creates a new Robot instance based on provided options
|
||||||
*
|
*
|
||||||
|
@ -100,16 +103,6 @@ var Robot = module.exports = function Robot(opts) {
|
||||||
|
|
||||||
Utils.subclass(Robot, EventEmitter);
|
Utils.subclass(Robot, EventEmitter);
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random name for a Robot.
|
|
||||||
*
|
|
||||||
* @todo should perhaps just increment a counter as a global value?
|
|
||||||
* @returns {String} a robot name
|
|
||||||
*/
|
|
||||||
Robot.randomName = function() {
|
|
||||||
return "Robot " + (Math.floor(Math.random() * 100000));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Condenses information on a Robot to a JSON-serializable format
|
* Condenses information on a Robot to a JSON-serializable format
|
||||||
*
|
*
|
||||||
|
@ -159,7 +152,7 @@ Robot.prototype.connection = function(name, conn) {
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
Robot.prototype.initRobot = function(opts) {
|
Robot.prototype.initRobot = function(opts) {
|
||||||
this.name = opts.name || Robot.randomName();
|
this.name = opts.name || "Robot " + ROBOT_ID++;
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.devices = {};
|
this.devices = {};
|
||||||
this.adaptors = {};
|
this.adaptors = {};
|
||||||
|
|
|
@ -32,17 +32,8 @@ describe("Robot", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
context("if not provided", function() {
|
context("if not provided", function() {
|
||||||
beforeEach(function() {
|
it("is set to an incrementing name", function() {
|
||||||
stub(Robot, "randomName").returns("New Robot");
|
expect(new Robot({}).name).to.match(/Robot \d/);
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
Robot.randomName.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("is set to a random name", function() {
|
|
||||||
var bot = new Robot({});
|
|
||||||
expect(bot.name).to.be.eql("New Robot");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue