Merge pull request #227 from hybridgroup/fix/connect-and-start

Remove default Adaptor#connect and Device#start methods
This commit is contained in:
Adrian Zankich 2014-09-08 09:39:50 -07:00
commit c443b486cc
10 changed files with 16 additions and 80 deletions

View File

@ -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.
//

View File

@ -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

View File

@ -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();

View File

@ -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();
};

View File

@ -20,4 +20,8 @@ module.exports = Loopback = function Loopback() {
Utils.subclass(Loopback, Adaptor);
Loopback.prototype.connect = function(callback) {
callback();
};
Loopback.adaptor = function(opts) { return new Loopback(opts); };

View File

@ -26,6 +26,10 @@ Ping.prototype.ping = function() {
return "pong";
};
Ping.prototype.start = function(callback) {
callback();
};
Ping.driver = function(opts) {
return new Ping(opts);
};

View File

@ -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;

View File

@ -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();
});

View File

@ -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() {

View File

@ -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;
});
});
});