On Mon, 2016-04-04 at 12:39 +0200, Ivo Abreu wrote:
> Now the question is, how can I set that Value to the CPE? Should I do
> it on the Preset Set command? What would be the syntax?
There's actually no way to do that from presets in this version, not
without some patching anyway. Attached is a patch file that allows you
to do just that. To use it, add a set configuration for some parameter,
and use this format in the value field "=mycustomcommandname" (without
the quotes). I rely on this for some of my use cases, but it does have
its limitations so I generally recommend pushing the configuration
through the API to individual devices. Also, patching GenieACS core
terrifies me :)
Zaid
diff --git a/lib/presets.coffee b/lib/presets.coffee
index 8e3293e..365e5ed 100644
--- a/lib/presets.coffee
+++ b/lib/presets.coffee
@@ -72,10 +72,21 @@ matchObject = (object, param) ->
return true
+evaluateDynamicValues = (device, value) ->
+ if value[0] != '='
+ return value
+
+ return device['_customCommands']?[value[1..].toLowerCase()]?['_value']
+
+
exports.getDevicePreset = (deviceId, presets, objects, aliases, callback) ->
deviceCustomCommands = customCommands.getDeviceCustomCommands(deviceId)
# only fetch relevant params
projection = {_id : 1}
+
+ # For dyanmic values
+ projection['_customCommands'] = 1
+
for p in presets
if common.typeOf(p.precondition) is common.STRING_TYPE
p.precondition = query.expand(JSON.parse(p.precondition), aliases)
@@ -125,11 +136,13 @@ exports.getDevicePreset = (deviceId, presets, objects, aliases, callback) ->
for c in configurations
switch c.type
when 'value'
- devicePreset.parameters ?= {}
- devicePreset.parameters[c.name] ?= {}
- devicePreset.parameters[c.name].preset ?= {}
- devicePreset.parameters[c.name].preset.value = c.value
- devicePreset.parameters[c.name].current = getParamDetails(device, c.name)
+ v = evaluateDynamicValues(device, c.value)
+ if v?
+ devicePreset.parameters ?= {}
+ devicePreset.parameters[c.name] ?= {}
+ devicePreset.parameters[c.name].preset ?= {}
+ devicePreset.parameters[c.name].preset.value = v
+ devicePreset.parameters[c.name].current = getParamDetails(device, c.name)
when 'age'
devicePreset.parameters ?= {}
_______________________________________________
Users mailing list
[email protected]
http://lists.genieacs.com/mailman/listinfo/users