Implement preset triggers on device events
This commit is contained in:
1 parent
d9f8b1c695
commit
a1ce53bf03
2 files changed
+17
-3
No files matched your search
+3
-1
@@ -119,6 +119,8 @@ refresh = (callback) ->
|
||||
# TODO show a warning
|
||||
schedule.schedule = false
|
||||
|
||||
events = preset.events ? {}
|
||||
|
||||
precondition = JSON.parse(preset.precondition)
|
||||
|
||||
_provisions = preset.provisions or []
|
||||
@@ -139,7 +141,7 @@ refresh = (callback) ->
|
||||
else
|
||||
throw new Error("Unknown configuration type #{c.type}")
|
||||
|
||||
presets.push({name: preset._id, schedule: schedule, precondition: precondition, provisions: _provisions})
|
||||
presets.push({name: preset._id, schedule: schedule, events: events, precondition: precondition, provisions: _provisions})
|
||||
|
||||
if -- counter == 0
|
||||
computeHash()
|
||||
|
||||
+14
-2
@@ -133,11 +133,23 @@ applyPresets = (currentRequest) ->
|
||||
|
||||
currentRequest.sessionData.presetsHash = presetsHash
|
||||
|
||||
deviceEvents = {}
|
||||
iter = currentRequest.sessionData.deviceData.paths.subset(['Events', '*'])
|
||||
while (p = iter.next().value)
|
||||
if currentRequest.sessionData.timestamp == currentRequest.sessionData.deviceData.values.value.get(p)?[0]
|
||||
deviceEvents[p[1]] = true
|
||||
|
||||
parameters = {}
|
||||
filteredPresets = []
|
||||
for p in presets
|
||||
continue if p.schedule and not
|
||||
(p.schedule.schedule and testSchedule(p.schedule, currentRequest.sessionData.timestamp)[0])
|
||||
eventsMatch = true
|
||||
for k, v of p.events
|
||||
if !v != !deviceEvents[k.replace(' ', '_')]
|
||||
eventsMatch = false
|
||||
break
|
||||
|
||||
continue if not eventsMatch or (p.schedule and not
|
||||
(p.schedule.schedule and testSchedule(p.schedule, currentRequest.sessionData.timestamp)[0]))
|
||||
|
||||
filteredPresets.push(p)
|
||||
for a in Object.keys(query.queryProjection(p.precondition))
|
||||
|
||||
Reference in new issue
Block a user