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
|
# TODO show a warning
|
||||||
schedule.schedule = false
|
schedule.schedule = false
|
||||||
|
|
||||||
|
events = preset.events ? {}
|
||||||
|
|
||||||
precondition = JSON.parse(preset.precondition)
|
precondition = JSON.parse(preset.precondition)
|
||||||
|
|
||||||
_provisions = preset.provisions or []
|
_provisions = preset.provisions or []
|
||||||
@@ -139,7 +141,7 @@ refresh = (callback) ->
|
|||||||
else
|
else
|
||||||
throw new Error("Unknown configuration type #{c.type}")
|
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
|
if -- counter == 0
|
||||||
computeHash()
|
computeHash()
|
||||||
|
|||||||
+14
-2
@@ -133,11 +133,23 @@ applyPresets = (currentRequest) ->
|
|||||||
|
|
||||||
currentRequest.sessionData.presetsHash = presetsHash
|
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 = {}
|
parameters = {}
|
||||||
filteredPresets = []
|
filteredPresets = []
|
||||||
for p in presets
|
for p in presets
|
||||||
continue if p.schedule and not
|
eventsMatch = true
|
||||||
(p.schedule.schedule and testSchedule(p.schedule, currentRequest.sessionData.timestamp)[0])
|
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)
|
filteredPresets.push(p)
|
||||||
for a in Object.keys(query.queryProjection(p.precondition))
|
for a in Object.keys(query.queryProjection(p.precondition))
|
||||||
|
|||||||
Reference in new issue
Block a user