Remove default Adaptor#connect and Driver#start methods
Child classes should always implement these themselves.
This commit is contained in:
parent
174fe2416f
commit
cf643d9d70
|
@ -30,17 +30,6 @@ Utils.subclass(Adaptor, Basestar);
|
|||
|
||||
Adaptor.prototype.commands = [];
|
||||
|
||||
// Public: Connects to the adaptor, and triggers the provided callback when
|
||||
// done.
|
||||
//
|
||||
// callback - function to run when the adaptor is connected
|
||||
//
|
||||
// Returns nothing
|
||||
Adaptor.prototype.connect = function(callback) {
|
||||
Logger.info("Connecting to adaptor '" + this.name + "'.");
|
||||
callback(null);
|
||||
};
|
||||
|
||||
// Public: Voids all command functions so they do not interact
|
||||
// with anything after disconnect has been called.
|
||||
//
|
||||
|
|
|
@ -60,11 +60,11 @@ Connection.prototype.toJSON = function() {
|
|||
//
|
||||
// callback - callback function to run when the adaptor is connected
|
||||
//
|
||||
// Returns the result of the supplied callback function
|
||||
// Returns nothing
|
||||
Connection.prototype.connect = function(callback) {
|
||||
var msg = this._logstring("Connecting to");
|
||||
Logger.info(msg);
|
||||
return this.adaptor.connect(callback);
|
||||
this.adaptor.connect(callback);
|
||||
};
|
||||
|
||||
// Public: Disconnect the adaptor's connection
|
||||
|
@ -76,7 +76,7 @@ Connection.prototype.disconnect = function(callback) {
|
|||
var msg = this._logstring("Disconnecting from");
|
||||
Logger.info(msg);
|
||||
this.removeAllListeners();
|
||||
return this.adaptor.disconnect(callback);
|
||||
this.adaptor.disconnect(callback);
|
||||
};
|
||||
|
||||
// Public: sets up adaptor with @robot
|
||||
|
|
|
@ -58,7 +58,7 @@ Utils.subclass(Device, EventEmitter);
|
|||
//
|
||||
// callback - callback function to be executed by the driver start
|
||||
//
|
||||
// Returns result of supplied callback
|
||||
// Returns nothing
|
||||
Device.prototype.start = function(callback) {
|
||||
var msg = "Starting device '" + this.name + "'";
|
||||
|
||||
|
@ -69,14 +69,14 @@ Device.prototype.start = function(callback) {
|
|||
msg += ".";
|
||||
|
||||
Logger.info(msg);
|
||||
return this.driver.start(callback);
|
||||
this.driver.start(callback);
|
||||
};
|
||||
|
||||
// Public: Halt the device driver
|
||||
//
|
||||
// callback - function to trigger when the device has been halted
|
||||
//
|
||||
// Returns result of supplied callback
|
||||
// Returns nothing
|
||||
Device.prototype.halt = function(callback) {
|
||||
Logger.info("Halting device '" + this.name + "'.");
|
||||
this.removeAllListeners();
|
||||
|
|
|
@ -54,13 +54,3 @@ Driver.prototype.setupCommands = function(commands, proxy) {
|
|||
this.commands[snake_case] = this[command];
|
||||
}
|
||||
}
|
||||
|
||||
// Public: Starts up the driver, and triggers the provided callback when done.
|
||||
//
|
||||
// callback - function to run when the driver is started
|
||||
//
|
||||
// Returns nothing
|
||||
Driver.prototype.start = function(callback) {
|
||||
Logger.info("Driver " + this.name + " started.");
|
||||
callback();
|
||||
};
|
||||
|
|
|
@ -24,29 +24,6 @@ describe("Adaptor", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#connect", function() {
|
||||
var callback;
|
||||
|
||||
beforeEach(function() {
|
||||
callback = spy();
|
||||
stub(Logger, 'info');
|
||||
adaptor.connect(callback);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
Logger.info.restore();
|
||||
});
|
||||
|
||||
it("logs that it's connecting to the adaptor", function() {
|
||||
var string = "Connecting to adaptor 'adaptor'.";
|
||||
expect(Logger.info).to.be.calledWith(string);
|
||||
});
|
||||
|
||||
it("triggers the provided callback", function() {
|
||||
expect(callback).to.be.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#_noop", function() {
|
||||
var hello;
|
||||
|
||||
|
|
|
@ -51,13 +51,12 @@ describe("Connection", function() {
|
|||
|
||||
beforeEach(function() {
|
||||
stub(Logger, 'info').returns(true);
|
||||
stub(connection.adaptor, 'connect').returns(true);
|
||||
connection.adaptor.connect = stub().returns(true);
|
||||
|
||||
connection.connect(callback);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
connection.adaptor.connect.restore();
|
||||
Logger.info.restore();
|
||||
});
|
||||
|
||||
|
|
|
@ -72,11 +72,7 @@ describe("Device", function() {
|
|||
|
||||
describe("#start", function() {
|
||||
beforeEach(function() {
|
||||
stub(driver, 'start').returns(true);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
driver.start.restore();
|
||||
driver.start = stub().returns(true);
|
||||
});
|
||||
|
||||
it("starts the driver, passing along a callback", function() {
|
||||
|
|
|
@ -75,27 +75,4 @@ describe("Driver", function() {
|
|||
expect(Object.keys(driver.commands)).to.be.eql(snake_case);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#start", function() {
|
||||
var callback;
|
||||
|
||||
beforeEach(function() {
|
||||
callback = spy();
|
||||
stub(Logger, 'info');
|
||||
driver.start(callback);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
Logger.info.restore();
|
||||
});
|
||||
|
||||
it("logs that it's starting the driver", function() {
|
||||
var string = "Driver driver started.";
|
||||
expect(Logger.info).to.be.calledWith(string);
|
||||
});
|
||||
|
||||
it("triggers the provided callback", function() {
|
||||
expect(callback).to.be.called;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue