Do not store available custom commands in device doc, find them from config. No longer having to reinitialize the device after adding a custom command.
This commit is contained in:
1 parent
86ff19a6e2
commit
9537bfad0f
4 files changed
+26
-14
No files matched your search
@@ -0,0 +1,27 @@
|
||||
config = require './config'
|
||||
common = require './common'
|
||||
|
||||
|
||||
exports.execute = (deviceId, command, callback) ->
|
||||
args = command.split(/\s+/)
|
||||
f = args.shift()
|
||||
c = args.shift()
|
||||
|
||||
file = require "./config/custom_commands/#{f}"
|
||||
file[c](deviceId, args.join(' '), callback)
|
||||
|
||||
|
||||
exports.getFileCommands = (filename) ->
|
||||
commands = []
|
||||
f = require("./config/custom_commands/#{filename}")
|
||||
for k,v of f
|
||||
commands.push(k)
|
||||
return commands
|
||||
|
||||
|
||||
exports.getDeviceCustomCommands = (deviceId) ->
|
||||
commands = {}
|
||||
for k,v of config.CUSTOM_COMMANDS
|
||||
if eval(v).test(deviceId)
|
||||
commands[k] = exports.getFileCommands(k)
|
||||
return commands
|
||||
Reference in new issue
Block a user