Support nested parameters in object configurations in presets.
This commit is contained in:
1 parent
c88e5d6fe8
commit
c70354997a
2 files changed
+34
-12
No files matched your search
@@ -86,6 +86,18 @@ exports.extend = (obj, mixin) ->
|
|||||||
obj
|
obj
|
||||||
|
|
||||||
|
|
||||||
|
exports.flattenObject = (object) ->
|
||||||
|
newObj = {}
|
||||||
|
f = (obj, prefix) ->
|
||||||
|
for k, v of obj
|
||||||
|
if typeof(v) is 'object'
|
||||||
|
f(v, "#{prefix}#{k}.")
|
||||||
|
else
|
||||||
|
newObj["#{prefix}#{k}"] = v
|
||||||
|
f(object, '')
|
||||||
|
return newObj
|
||||||
|
|
||||||
|
|
||||||
exports.getParamValueFromPath = (obj, path) ->
|
exports.getParamValueFromPath = (obj, path) ->
|
||||||
pp = path.split('.')
|
pp = path.split('.')
|
||||||
ref = obj
|
ref = obj
|
||||||
|
|||||||
+22
-12
@@ -54,12 +54,21 @@ exports.calculatePresetsHash = (presets, objects) ->
|
|||||||
|
|
||||||
|
|
||||||
matchObject = (object, param) ->
|
matchObject = (object, param) ->
|
||||||
return false if not object._keys? or object._keys.length == 0
|
flatObject = common.flattenObject(object)
|
||||||
for k in object._keys
|
if object._keys?.length
|
||||||
return false if not param[k]?
|
keys = object._keys
|
||||||
v = common.matchType(param[k]._value, object[k])
|
else
|
||||||
if param[k]._value != v
|
# Consider all parameters as keys if none are defined
|
||||||
|
keys = (k for k in Object.keys(flatObject) when k[0] != '_')
|
||||||
|
|
||||||
|
for k in keys
|
||||||
|
p = common.getParamValueFromPath(param, k)
|
||||||
|
return false if not p?
|
||||||
|
v = common.matchType(p._value, flatObject[k])
|
||||||
|
|
||||||
|
if p._value != common.matchType(p._value, flatObject[k])
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
@@ -250,18 +259,19 @@ exports.processDevicePreset = (deviceId, devicePreset, callback) ->
|
|||||||
for objectName, objectDetails of object
|
for objectName, objectDetails of object
|
||||||
continue if not objectDetails.current?
|
continue if not objectDetails.current?
|
||||||
if objectDetails.preset?
|
if objectDetails.preset?
|
||||||
|
flatObject = common.flattenObject(objectDetails.preset)
|
||||||
if Object.keys(objectDetails.current).length > 0
|
if Object.keys(objectDetails.current).length > 0
|
||||||
for i, obj of objectDetails.current
|
for i, obj of objectDetails.current
|
||||||
for paramName, paramValue of objectDetails.preset
|
for paramName, paramValue of flatObject
|
||||||
continue if paramName[0] == '_'
|
continue if paramName[0] == '_'
|
||||||
if obj[paramName]
|
currentValue = common.getParamValueFromPath(obj, paramName)
|
||||||
currentValue = obj[paramName]._value
|
if currentValue?
|
||||||
presetValue = common.matchType(currentValue, objectDetails.preset[paramName])
|
presetValue = common.matchType(currentValue._value, flatObject[paramName])
|
||||||
if currentValue != presetValue
|
if currentValue._value != presetValue
|
||||||
setParameterValues.push(["#{parameterPath}.#{i}.#{paramName}", presetValue, obj[paramName]._type])
|
setParameterValues.push(["#{parameterPath}.#{i}.#{paramName}", presetValue, currentValue._type])
|
||||||
else
|
else
|
||||||
vals = []
|
vals = []
|
||||||
for k,v of objectDetails.preset
|
for k,v of flatObject
|
||||||
vals.push([k, v]) if k[0] != '_'
|
vals.push([k, v]) if k[0] != '_'
|
||||||
taskList.push({device : deviceId, name : 'addObject', objectName : parameterPath, parameterValues : vals, instanceName : objectName})
|
taskList.push({device : deviceId, name : 'addObject', objectName : parameterPath, parameterValues : vals, instanceName : objectName})
|
||||||
else if Object.keys(objectDetails.current).length > 0
|
else if Object.keys(objectDetails.current).length > 0
|
||||||
|
|||||||
Reference in new issue
Block a user