Devices will only be started up once, and can be added dynamically
This commit is contained in:
parent
9cdbdd1d37
commit
4ec19961f8
|
@ -319,6 +319,10 @@ Robot.prototype.startDevices = function(callback) {
|
||||||
this[name] = device;
|
this[name] = device;
|
||||||
|
|
||||||
return function(cb) {
|
return function(cb) {
|
||||||
|
if (device.started === true) {
|
||||||
|
return cb.call(device);
|
||||||
|
}
|
||||||
|
|
||||||
var str = "Starting device '" + name + "'";
|
var str = "Starting device '" + name + "'";
|
||||||
|
|
||||||
if (device.pin) {
|
if (device.pin) {
|
||||||
|
@ -326,6 +330,8 @@ Robot.prototype.startDevices = function(callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log(str + ".");
|
log(str + ".");
|
||||||
|
device.started = true;
|
||||||
|
|
||||||
return device.start.call(device, cb);
|
return device.start.call(device, cb);
|
||||||
};
|
};
|
||||||
}, this);
|
}, this);
|
||||||
|
|
|
@ -442,6 +442,25 @@ describe("Robot", function() {
|
||||||
expect(bot.devices.alpha.start).to.be.called;
|
expect(bot.devices.alpha.start).to.be.called;
|
||||||
expect(bot.devices.bravo.start).to.be.called;
|
expect(bot.devices.bravo.start).to.be.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("runs #start on each device only once", function() {
|
||||||
|
bot.startDevices();
|
||||||
|
bot.startDevices();
|
||||||
|
|
||||||
|
expect(bot.devices.alpha.start).to.be.called.once;
|
||||||
|
expect(bot.devices.bravo.start).to.be.called.once;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs #start on a newly added device", function() {
|
||||||
|
bot.startDevices();
|
||||||
|
bot.device("charlie", { driver: "ping" });
|
||||||
|
stub(bot.devices.charlie, "start").returns(true);
|
||||||
|
bot.startDevices();
|
||||||
|
|
||||||
|
expect(bot.devices.alpha.start).to.be.called.once;
|
||||||
|
expect(bot.devices.bravo.start).to.be.called.once;
|
||||||
|
expect(bot.devices.charlie.start).to.be.called.once;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#halt", function() {
|
describe("#halt", function() {
|
||||||
|
|
Loading…
Reference in New Issue