forked from zettajs/zetta-scientist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_device_config.js
75 lines (64 loc) · 1.52 KB
/
default_device_config.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var DeviceConfig = module.exports = function() {
this._name = null;
this._type = null;
this._state = null;
this._remoteFetch = null;
this._remoteUpdate = null;
this._remoteDestroy = null;
this.streams = {};
this.monitors = [];
this.monitorsOptions = {};
this.allowed = {};
this.transitions = {};
};
DeviceConfig.prototype.name = function(name) {
this._name = name;
return this;
};
DeviceConfig.prototype.type = function(type) {
this._type = type;
return this;
};
DeviceConfig.prototype.state = function(state) {
this._state = state;
return this;
};
DeviceConfig.prototype.when = function(state, options) {
var allow = options.allow;
if (!allow) {
return this;
}
this.allowed[state] = allow;
return this;
};
DeviceConfig.prototype.map = function(name, handler, fields) {
this.transitions[name] = {
handler: handler,
fields: fields
};
return this;
};
DeviceConfig.prototype.monitor = function(name, options) {
this.monitors.push(name);
this.monitorsOptions[name] = options || {};
return this;
};
DeviceConfig.prototype.stream = function(name, handler, options) {
this.streams[name] = {
handler: handler,
options: options
};
return this;
};
DeviceConfig.prototype.remoteFetch = function(handler) {
this._remoteFetch = handler;
return this;
};
DeviceConfig.prototype.remoteUpdate = function(handler) {
this._remoteUpdate = handler;
return this;
};
DeviceConfig.prototype.remoteDestroy = function(handler) {
this._remoteDestroy = handler;
return this;
};