Add 'details' subsection to Device/Connection
This commit is contained in:
parent
8762820d0c
commit
029aca2e9e
|
@ -32,6 +32,14 @@ var Connection = module.exports = function Connection(opts) {
|
|||
this.port = opts.port;
|
||||
this.adaptor = this.initAdaptor(opts);
|
||||
|
||||
this.details = {};
|
||||
|
||||
for (var opt in opts) {
|
||||
if (['robot', 'name', 'adaptor'].indexOf(opt) < 0) {
|
||||
this.details[opt] = opts[opt];
|
||||
}
|
||||
}
|
||||
|
||||
Utils.proxyFunctionsToObject(this.adaptor.commands, this.adaptor, this);
|
||||
};
|
||||
|
||||
|
@ -43,8 +51,8 @@ Utils.subclass(Connection, EventEmitter);
|
|||
Connection.prototype.toJSON = function() {
|
||||
return {
|
||||
name: this.name,
|
||||
port: this.port,
|
||||
adaptor: this.adaptor.constructor.name || this.adaptor.name,
|
||||
details: this.details
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -37,6 +37,14 @@ var Device = module.exports = function Device(opts) {
|
|||
this.connection = this.determineConnection(opts.connection) || this.defaultConnection();
|
||||
this.driver = this.initDriver(opts);
|
||||
|
||||
this.details = {};
|
||||
|
||||
for (var opt in opts) {
|
||||
if (['robot', 'name', 'connection', 'driver'].indexOf(opt) < 0) {
|
||||
this.details[opt] = opts[opt];
|
||||
}
|
||||
}
|
||||
|
||||
Utils.proxyFunctionsToObject(this.driver.commands, this.driver, this);
|
||||
};
|
||||
|
||||
|
@ -77,9 +85,9 @@ Device.prototype.toJSON = function() {
|
|||
return {
|
||||
name: this.name,
|
||||
driver: this.driver.constructor.name || this.driver.name,
|
||||
pin: this.pin,
|
||||
connection: this.connection.name,
|
||||
commands: this.driver.commands
|
||||
commands: this.driver.commands,
|
||||
details: this.details
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ describe("Connection", function() {
|
|||
});
|
||||
|
||||
it("contains the connection's port", function() {
|
||||
expect(json.port).to.be.eql("/dev/null");
|
||||
expect(json.details.port).to.be.eql("/dev/null");
|
||||
});
|
||||
|
||||
it("contains the connection's adaptor name", function() {
|
||||
|
|
|
@ -118,7 +118,7 @@ describe("Device", function() {
|
|||
});
|
||||
|
||||
it("contains the device's pin", function() {
|
||||
expect(json.pin).to.be.eql(device.pin);
|
||||
expect(json.details.pin).to.be.eql(device.pin);
|
||||
});
|
||||
|
||||
it("contains the device's driver name", function() {
|
||||
|
|
Loading…
Reference in New Issue