forked from hassoncs/CAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actionRunner.js
43 lines (35 loc) · 1.1 KB
/
actionRunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
actionRunner
*/
var _ = require('underscore'),
util = require('util'),
logger = require('./logger'),
lights = require('./hueWrapper'),
ActionDirectory = require('./action/actionDirectory'),
Events = require('./events');
(function(context) {
var ACTIONS = {};
function runActionsForEvent(eventId) {
var actions = ACTIONS[eventId];
if (!actions) {
return;
}
_.each(actions, function(action) {
action.run();
});
}
function init() {
addAction(Events.TURN_ON_ENTRANCE_LIGHT, new ActionDirectory.TurnOnLightAction("Stairs Bottom"));
addAction(Events.TURN_ON_ENTRANCE_LIGHT, new ActionDirectory.DelayedAction(
new ActionDirectory.TurnOffLightAction("Stairs Bottom"), 60000));
}
function addAction(eventId, action) {
ACTIONS = ACTIONS || {};
var actions = ACTIONS[eventId];
actions = actions || [];
actions.push(action);
ACTIONS[eventId] = actions;
}
exports.init = init;
exports.runActionsForEvent = runActionsForEvent;
})(exports);