Correctly execute device commands
This commit is contained in:
parent
e6c567a090
commit
7a481f6767
|
@ -1,12 +1,16 @@
|
|||
var Cylon = require('../..');
|
||||
|
||||
Cylon.api();
|
||||
|
||||
Cylon.robot({
|
||||
name: 'test',
|
||||
connection: { name: 'loopback', adaptor: 'loopback' },
|
||||
device: { name: 'ping', driver: 'ping' },
|
||||
|
||||
work: function() {
|
||||
work: function(my) {
|
||||
every((1).seconds(), function(){
|
||||
console.log("Hello, human!")
|
||||
console.log(my.ping.ping());
|
||||
});
|
||||
|
||||
after((5).seconds(), function(){
|
||||
|
|
|
@ -102,13 +102,12 @@ router.get("/robots/:robot/devices/:device/events/:event", load, function(req, r
|
|||
});
|
||||
|
||||
router.get("/robots/:robot/devices/:device/commands", load, function(req, res) {
|
||||
res.json({ commands: req.device.toJSON().commands });
|
||||
res.json({ commands: Object.keys(req.device.commands) });
|
||||
});
|
||||
|
||||
router.all("/robots/:robot/devices/:device/commands/:command", load, function(req, res) {
|
||||
var command = req.params.command;
|
||||
|
||||
var result = req.device[command].apply(req.device, req.commandParams);
|
||||
var command = req.device.driver.commands[req.params.command];
|
||||
var result = command.apply(req.device, req.commandParams);
|
||||
res.json({ result: result });
|
||||
});
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ var Device = module.exports = function Device(opts) {
|
|||
}
|
||||
}
|
||||
|
||||
Utils.proxyFunctionsToObject(this.driver.commands, this.driver, this);
|
||||
Utils.proxyFunctionsToObject(Object.keys(this.driver.commands), this.driver, this);
|
||||
};
|
||||
|
||||
Utils.subclass(Device, EventEmitter);
|
||||
|
@ -86,7 +86,7 @@ Device.prototype.toJSON = function() {
|
|||
name: this.name,
|
||||
driver: this.driver.constructor.name || this.driver.name,
|
||||
connection: this.connection.name,
|
||||
commands: this.driver.commands,
|
||||
commands: Object.keys(this.driver.commands),
|
||||
details: this.details
|
||||
};
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ var Ping = module.exports = function Ping() {
|
|||
Ping.__super__.constructor.apply(this, arguments);
|
||||
|
||||
this.commands = {
|
||||
ping: this.ping
|
||||
ping: this.ping.bind(this)
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ describe("Device", function() {
|
|||
});
|
||||
|
||||
it("contains the device's driver commands", function() {
|
||||
expect(json.commands).to.be.eql(driver.commands);
|
||||
expect(json.commands).to.be.eql(Object.keys(driver.commands));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue