nodejs-poolcontroller 7.3.1 → 7.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +52 -52
  3. package/CONTRIBUTING.md +74 -74
  4. package/Changelog +215 -195
  5. package/Dockerfile +17 -17
  6. package/Gruntfile.js +40 -40
  7. package/LICENSE +661 -661
  8. package/README.md +191 -186
  9. package/app.ts +2 -0
  10. package/config/Config.ts +27 -2
  11. package/config/VersionCheck.ts +33 -14
  12. package/config copy.json +299 -299
  13. package/controller/Constants.ts +88 -0
  14. package/controller/Equipment.ts +2459 -2225
  15. package/controller/Errors.ts +180 -157
  16. package/controller/Lockouts.ts +437 -0
  17. package/controller/State.ts +364 -79
  18. package/controller/boards/BoardFactory.ts +45 -45
  19. package/controller/boards/EasyTouchBoard.ts +2653 -2489
  20. package/controller/boards/IntelliCenterBoard.ts +4230 -3973
  21. package/controller/boards/IntelliComBoard.ts +63 -63
  22. package/controller/boards/IntelliTouchBoard.ts +241 -167
  23. package/controller/boards/NixieBoard.ts +1675 -1105
  24. package/controller/boards/SystemBoard.ts +4697 -3201
  25. package/controller/comms/Comms.ts +222 -10
  26. package/controller/comms/messages/Messages.ts +13 -9
  27. package/controller/comms/messages/config/ChlorinatorMessage.ts +13 -4
  28. package/controller/comms/messages/config/CircuitGroupMessage.ts +6 -0
  29. package/controller/comms/messages/config/CircuitMessage.ts +0 -0
  30. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  31. package/controller/comms/messages/config/CoverMessage.ts +1 -0
  32. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  33. package/controller/comms/messages/config/EquipmentMessage.ts +4 -0
  34. package/controller/comms/messages/config/ExternalMessage.ts +53 -33
  35. package/controller/comms/messages/config/FeatureMessage.ts +8 -1
  36. package/controller/comms/messages/config/GeneralMessage.ts +8 -0
  37. package/controller/comms/messages/config/HeaterMessage.ts +14 -28
  38. package/controller/comms/messages/config/IntellichemMessage.ts +4 -1
  39. package/controller/comms/messages/config/OptionsMessage.ts +38 -2
  40. package/controller/comms/messages/config/PumpMessage.ts +4 -20
  41. package/controller/comms/messages/config/RemoteMessage.ts +4 -0
  42. package/controller/comms/messages/config/ScheduleMessage.ts +347 -331
  43. package/controller/comms/messages/config/SecurityMessage.ts +1 -0
  44. package/controller/comms/messages/config/ValveMessage.ts +13 -3
  45. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +2 -3
  46. package/controller/comms/messages/status/EquipmentStateMessage.ts +79 -25
  47. package/controller/comms/messages/status/HeaterStateMessage.ts +86 -53
  48. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -386
  49. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  50. package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
  51. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  52. package/controller/nixie/Nixie.ts +162 -160
  53. package/controller/nixie/NixieEquipment.ts +103 -103
  54. package/controller/nixie/bodies/Body.ts +120 -117
  55. package/controller/nixie/bodies/Filter.ts +135 -135
  56. package/controller/nixie/chemistry/ChemController.ts +2498 -2395
  57. package/controller/nixie/chemistry/Chlorinator.ts +314 -313
  58. package/controller/nixie/circuits/Circuit.ts +248 -210
  59. package/controller/nixie/heaters/Heater.ts +649 -441
  60. package/controller/nixie/pumps/Pump.ts +661 -599
  61. package/controller/nixie/schedules/Schedule.ts +257 -256
  62. package/controller/nixie/valves/Valve.ts +170 -170
  63. package/defaultConfig.json +286 -271
  64. package/issue_template.md +51 -51
  65. package/logger/DataLogger.ts +448 -433
  66. package/logger/Logger.ts +0 -0
  67. package/package.json +56 -54
  68. package/tsconfig.json +25 -25
  69. package/web/Server.ts +522 -31
  70. package/web/bindings/influxDB.json +1022 -894
  71. package/web/bindings/mqtt.json +654 -543
  72. package/web/bindings/mqttAlt.json +684 -574
  73. package/web/bindings/rulesManager.json +54 -54
  74. package/web/bindings/smartThings-Hubitat.json +31 -31
  75. package/web/bindings/valveRelays.json +20 -20
  76. package/web/bindings/vera.json +25 -25
  77. package/web/interfaces/baseInterface.ts +136 -136
  78. package/web/interfaces/httpInterface.ts +124 -122
  79. package/web/interfaces/influxInterface.ts +245 -240
  80. package/web/interfaces/mqttInterface.ts +475 -464
  81. package/web/services/config/Config.ts +181 -152
  82. package/web/services/config/ConfigSocket.ts +0 -0
  83. package/web/services/state/State.ts +118 -7
  84. package/web/services/state/StateSocket.ts +18 -1
  85. package/web/services/utilities/Utilities.ts +42 -42
@@ -1,55 +1,55 @@
1
- {
2
- "context": {
3
- "name": "Rules Manager",
4
- "vars": {},
5
- "options": {
6
- "method": "PUT",
7
- "headers": {
8
- "CONTENT-TYPE": "application/json"
9
- }
10
- }
11
- },
12
- "events": [
13
- {
14
- "name": "controller",
15
- "description": "Turn on needsCleaning flag for filter. Evaluate on a controller socket emit. True when the pool is on, pump is not priming, and filter psi > 15",
16
- "enabled": true,
17
- "filter": "@bind=data.id;===1 && @bind=state.filters.getItemById(1).psi;>15 && @bind=data.status.name;!=='priming'",
18
- "options": {
19
- "path": "/config/filter"
20
- },
21
- "body": {"needsCleaning":true}
22
- },
23
- {
24
- "name": "controller",
25
- "description": "Turn on needsCleaning flag for filter. Evaluate on a controller/time socket emit. Eval on the first day of every 3rd month when psi is >15 at any point",
26
- "enabled": true,
27
- "filter": "@bind=(new Date(data.time)).getMonth()%3;===0 && @bind=(new Date(data.time)).getDate();===1 && @bind=state.filters.getItemById(1).psi;>15",
28
- "options": {
29
- "path": "/config/filter"
30
- },
31
- "body": {"needsCleaning":true}
32
- },
33
- {
34
- "name": "chemController",
35
- "description": "Sets chlorinator to 50% if ORP is low",
36
- "enabled": true,
37
- "filter": "@bind=data.orpLevel; < @bind=sys.chemControllers.getItemById(1).orpSetpoint;",
38
- "options": {
39
- "path": "/config/chlorinator"
40
- },
41
- "body": {"id":1, "poolSetpoint":50}
42
- },
43
- {
44
- "name": "chemController",
45
- "description": "Sets chlorinator to 5% if ORP is in range",
46
- "enabled": true,
47
- "filter": "@bind=data.orpLevel; > @bind=sys.chemControllers.getItemById(1).orpSetpoint;",
48
- "options": {
49
- "path": "/config/chlorinator"
50
- },
51
- "body": {"id":1, "poolSetpoint":5}
52
- }
53
-
54
- ]
1
+ {
2
+ "context": {
3
+ "name": "Rules Manager",
4
+ "vars": {},
5
+ "options": {
6
+ "method": "PUT",
7
+ "headers": {
8
+ "CONTENT-TYPE": "application/json"
9
+ }
10
+ }
11
+ },
12
+ "events": [
13
+ {
14
+ "name": "controller",
15
+ "description": "Turn on needsCleaning flag for filter. Evaluate on a controller socket emit. True when the pool is on, pump is not priming, and filter psi > 15",
16
+ "enabled": true,
17
+ "filter": "@bind=data.id;===1 && @bind=state.filters.getItemById(1).psi;>15 && @bind=data.status.name;!=='priming'",
18
+ "options": {
19
+ "path": "/config/filter"
20
+ },
21
+ "body": {"needsCleaning":true}
22
+ },
23
+ {
24
+ "name": "controller",
25
+ "description": "Turn on needsCleaning flag for filter. Evaluate on a controller/time socket emit. Eval on the first day of every 3rd month when psi is >15 at any point",
26
+ "enabled": true,
27
+ "filter": "@bind=(new Date(data.time)).getMonth()%3;===0 && @bind=(new Date(data.time)).getDate();===1 && @bind=state.filters.getItemById(1).psi;>15",
28
+ "options": {
29
+ "path": "/config/filter"
30
+ },
31
+ "body": {"needsCleaning":true}
32
+ },
33
+ {
34
+ "name": "chemController",
35
+ "description": "Sets chlorinator to 50% if ORP is low",
36
+ "enabled": true,
37
+ "filter": "@bind=data.orpLevel; < @bind=sys.chemControllers.getItemById(1).orpSetpoint;",
38
+ "options": {
39
+ "path": "/config/chlorinator"
40
+ },
41
+ "body": {"id":1, "poolSetpoint":50}
42
+ },
43
+ {
44
+ "name": "chemController",
45
+ "description": "Sets chlorinator to 5% if ORP is in range",
46
+ "enabled": true,
47
+ "filter": "@bind=data.orpLevel; > @bind=sys.chemControllers.getItemById(1).orpSetpoint;",
48
+ "options": {
49
+ "path": "/config/chlorinator"
50
+ },
51
+ "body": {"id":1, "poolSetpoint":5}
52
+ }
53
+
54
+ ]
55
55
  }
@@ -1,32 +1,32 @@
1
- {
2
- "context": {
3
- "name": "SmartThings",
4
- "vars": {},
5
- "options": {
6
- "method": "NOTIFY",
7
- "path": "/notify",
8
- "headers": {
9
- "CONTENT-TYPE": "application/json",
10
- "X-EVENT-TYPE": "@bind=eventName;"
11
- }
12
- }
13
- },
14
- "events": [
15
- {
16
- "name": "justAnExample",
17
- "description": "Shows how the binding can be used to send variable data to SmartThings. This can be any combination of data.",
18
- "body": "{\"air\":\"@bind=data.air;@bind=data.units.name.substring(0, 1);\", \"total\":@bind=data.solar + data.waterSensor1;, \"status\":\"@bind=state.equipment.model;\"}",
19
- "options": {
20
- "headers": {
21
- "X-EVENT2": ""
22
- }
23
- }
24
- },
25
- {
26
- "name": "config",
27
- "description": "Not used for updates",
28
- "enabled": false
29
- },
30
- { "name": "*", "description": "All events that are not trapped by other event names. Sends the entire emitted response.", "body": "@bind=data;" }
31
- ]
1
+ {
2
+ "context": {
3
+ "name": "SmartThings",
4
+ "vars": {},
5
+ "options": {
6
+ "method": "NOTIFY",
7
+ "path": "/notify",
8
+ "headers": {
9
+ "CONTENT-TYPE": "application/json",
10
+ "X-EVENT-TYPE": "@bind=eventName;"
11
+ }
12
+ }
13
+ },
14
+ "events": [
15
+ {
16
+ "name": "justAnExample",
17
+ "description": "Shows how the binding can be used to send variable data to SmartThings. This can be any combination of data.",
18
+ "body": "{\"air\":\"@bind=data.air;@bind=data.units.name.substring(0, 1);\", \"total\":@bind=data.solar + data.waterSensor1;, \"status\":\"@bind=state.equipment.model;\"}",
19
+ "options": {
20
+ "headers": {
21
+ "X-EVENT2": ""
22
+ }
23
+ }
24
+ },
25
+ {
26
+ "name": "config",
27
+ "description": "Not used for updates",
28
+ "enabled": false
29
+ },
30
+ { "name": "*", "description": "All events that are not trapped by other event names. Sends the entire emitted response.", "body": "@bind=data;" }
31
+ ]
32
32
  }
@@ -1,20 +1,20 @@
1
- {
2
- "context": {
3
- "name": "valveRelay",
4
- "options": {
5
- "method": "GET",
6
- "path": "/@bind=data.pinId;/@bind=data.isDiverted ? 'on' : 'off';",
7
- "headers": {
8
- "CONTENT-TYPE": "application/json"
9
- }
10
- },
11
- "vars": {}
12
- },
13
- "events": [
14
- {
15
- "name": "valve",
16
- "filter": "@bind=data.isVirtual;",
17
- "description": "Send commands to turn on or off the valve relay based upon the valve emit."
18
- }
19
- ]
20
- }
1
+ {
2
+ "context": {
3
+ "name": "valveRelay",
4
+ "options": {
5
+ "method": "GET",
6
+ "path": "/@bind=data.pinId;/@bind=data.isDiverted ? 'on' : 'off';",
7
+ "headers": {
8
+ "CONTENT-TYPE": "application/json"
9
+ }
10
+ },
11
+ "vars": {}
12
+ },
13
+ "events": [
14
+ {
15
+ "name": "valve",
16
+ "filter": "@bind=data.isVirtual;",
17
+ "description": "Send commands to turn on or off the valve relay based upon the valve emit."
18
+ }
19
+ ]
20
+ }
@@ -1,25 +1,25 @@
1
- {
2
- "context": {
3
- "name": "Vera",
4
- "options": {
5
- "method": "POST",
6
- "path": "/data_request?id=action&DeviceNum=@bind=vars.deviceId;&serviceId=urn:rstrouse-com:serviceId:PoolController1&action=SetEventData&targetData=@bind=eventName;",
7
- "headers": {
8
- "CONTENT-TYPE": "application/json"
9
- }
10
- },
11
- "vars": {}
12
- },
13
- "events": [
14
- {
15
- "name": "config",
16
- "description": "Vera doesn't use this payload.",
17
- "enabled": false
18
- },
19
- {
20
- "name": "*",
21
- "description": "This will be the UPnP version when I get the services built in Vera and the only binding required. Sends the entire emitted response.",
22
- "body": "@bind=data;"
23
- }
24
- ]
25
- }
1
+ {
2
+ "context": {
3
+ "name": "Vera",
4
+ "options": {
5
+ "method": "POST",
6
+ "path": "/data_request?id=action&DeviceNum=@bind=vars.deviceId;&serviceId=urn:rstrouse-com:serviceId:PoolController1&action=SetEventData&targetData=@bind=eventName;",
7
+ "headers": {
8
+ "CONTENT-TYPE": "application/json"
9
+ }
10
+ },
11
+ "vars": {}
12
+ },
13
+ "events": [
14
+ {
15
+ "name": "config",
16
+ "description": "Vera doesn't use this payload.",
17
+ "enabled": false
18
+ },
19
+ {
20
+ "name": "*",
21
+ "description": "This will be the UPnP version when I get the services built in Vera and the only binding required. Sends the entire emitted response.",
22
+ "body": "@bind=data;"
23
+ }
24
+ ]
25
+ }
@@ -1,136 +1,136 @@
1
- import extend = require("extend");
2
- import { logger } from "../../logger/Logger";
3
- import { sys as sysAlias } from "../../controller/Equipment";
4
- import { state as stateAlias} from "../../controller/State";
5
- import { webApp as webAppAlias } from '../Server';
6
- import { utils, Timestamp } from "../../controller/Constants";
7
-
8
- export class BaseInterfaceBindings {
9
- constructor(cfg) {
10
- this.cfg = cfg;
11
- }
12
- public context: InterfaceContext;
13
- public cfg;
14
- public events: InterfaceEvent[];
15
- public bindEvent(evt: string, ...data: any) { };
16
- protected bindVarTokens(e: InterfaceEvent, evt: string, ...data: any) {
17
- let v = {};
18
- let toks = {};
19
- let vars = extend(true, {}, this.cfg.vars, this.context.vars, typeof e !== 'undefined' && e.vars ? e.vars : {});
20
- for (var s in vars) {
21
- let ovalue = vars[s];
22
- if (typeof ovalue === 'string') {
23
- if (ovalue.includes('@bind')) {
24
- this.matchTokens(ovalue, evt, toks, e, data[0], vars);
25
- v[s] = toks;
26
- ovalue = this.evalTokens(ovalue, toks);
27
- }
28
- }
29
- v[s] = ovalue;
30
- }
31
- //console.log(...data);
32
- //console.log(v);
33
- return v;
34
- }
35
- protected matchTokens(input: string, eventName: string, toks: any, e: InterfaceEvent, data, vars): any {
36
- toks = toks || [];
37
- let s = input;
38
- let regx = /(?<=@bind\=\s*).*?(?=\;)/g;
39
- let match;
40
- let sys = sysAlias;
41
- let state = stateAlias;
42
- let webApp = webAppAlias;
43
- while (match = regx.exec(s)) {
44
- let bind = match[0];
45
- if (typeof toks[bind] !== 'undefined') continue;
46
- let tok: any = {};
47
- toks[bind] = tok;
48
- try {
49
- // we may error out if data can't be found (eg during init)
50
- tok.reg = new RegExp("@bind=" + this.escapeRegex(bind) + ";", "g");
51
- tok.value = eval(bind);
52
- }
53
- catch (err) {
54
- // leave value undefined so it isn't sent to bindings
55
- toks[bind] = null;
56
- }
57
- }
58
- return toks;
59
-
60
- }
61
- protected buildTokens(input: string, eventName: string, toks: any, e: InterfaceEvent, data): any {
62
- toks = toks || [];
63
- let s = input;
64
- let regx = /(?<=@bind\=\s*).*?(?=\;)/g;
65
- let match;
66
- let vars = this.bindVarTokens(e, eventName, data);
67
- let sys = sysAlias;
68
- let state = stateAlias;
69
- let webApp = webAppAlias;
70
- // Map all the returns to the token list. We are being very basic
71
- // here an the object graph is simply based upon the first object occurrence.
72
- // We simply want to eval against that object reference.
73
-
74
- while (match = regx.exec(s)) {
75
- let bind = match[0];
76
- if (typeof toks[bind] !== 'undefined') continue;
77
- let tok: any = {};
78
- toks[bind] = tok;
79
- try {
80
- // we may error out if data can't be found (eg during init)
81
- tok.reg = new RegExp("@bind=" + this.escapeRegex(bind) + ";", "g");
82
- tok.value = eval(bind);
83
- }
84
- catch (err) {
85
- // leave value undefined so it isn't sent to bindings
86
- toks[bind] = null;
87
- }
88
- }
89
- return toks;
90
- }
91
- protected escapeRegex(reg: string) { return reg.replace(/[-[\]{}()*+?.|,\\^$]/g, '\\$&'); }
92
- protected replaceTokens(input: string, toks: any) {
93
- let s = input;
94
- for (let exp in toks) {
95
- let tok = toks[exp];
96
- if (!tok || typeof tok.reg === 'undefined') continue;
97
- tok.reg.lastIndex = 0; // Start over if we used this before.
98
- if (typeof tok.value === 'string') s = s.replace(tok.reg, tok.value);
99
- else if (typeof tok.value === 'undefined') s = s.replace(tok.reg, 'null');
100
- else s = s.replace(tok.reg, JSON.stringify(tok.value));
101
- }
102
- return s;
103
- }
104
- protected evalTokens(input: string, toks: any) {
105
- let s = input;
106
- for (let exp in toks) {
107
- let tok = toks[exp];
108
- if (!tok || typeof tok.reg === 'undefined') continue;
109
- tok.reg.lastIndex = 0; // Start over if we used this before.
110
- if (typeof tok.value === 'string') s = s.replace(tok.reg, tok.value);
111
- else if (typeof tok.value === 'undefined') s = s.replace(tok.reg, 'null');
112
- else return tok.value;
113
- }
114
- }
115
- protected tokensReplacer(input: string, eventName: string, toks: any, e: InterfaceEvent, data): any{
116
- this.buildTokens(input, eventName, toks, e, data);
117
- return this.replaceTokens(input, toks);
118
- }
119
- public async stopAsync() { }
120
- }
121
-
122
- export class InterfaceEvent {
123
- public name: string;
124
- public enabled: boolean = true;
125
- public filter: string;
126
- public options: any = {};
127
- public body: any = {};
128
- public vars: any = {};
129
- }
130
- export class InterfaceContext {
131
- public name: string;
132
- public mdnsDiscovery: any;
133
- public upnpDevice: any;
134
- public options: any = {};
135
- public vars: any = {};
136
- }
1
+ import extend = require("extend");
2
+ import { logger } from "../../logger/Logger";
3
+ import { sys as sysAlias } from "../../controller/Equipment";
4
+ import { state as stateAlias} from "../../controller/State";
5
+ import { webApp as webAppAlias } from '../Server';
6
+ import { utils, Timestamp } from "../../controller/Constants";
7
+
8
+ export class BaseInterfaceBindings {
9
+ constructor(cfg) {
10
+ this.cfg = cfg;
11
+ }
12
+ public context: InterfaceContext;
13
+ public cfg;
14
+ public events: InterfaceEvent[];
15
+ public bindEvent(evt: string, ...data: any) { };
16
+ protected bindVarTokens(e: InterfaceEvent, evt: string, ...data: any) {
17
+ let v = {};
18
+ let toks = {};
19
+ let vars = extend(true, {}, this.cfg.vars, this.context.vars, typeof e !== 'undefined' && e.vars ? e.vars : {});
20
+ for (var s in vars) {
21
+ let ovalue = vars[s];
22
+ if (typeof ovalue === 'string') {
23
+ if (ovalue.includes('@bind')) {
24
+ this.matchTokens(ovalue, evt, toks, e, data[0], vars);
25
+ v[s] = toks;
26
+ ovalue = this.evalTokens(ovalue, toks);
27
+ }
28
+ }
29
+ v[s] = ovalue;
30
+ }
31
+ //console.log(...data);
32
+ //console.log(v);
33
+ return v;
34
+ }
35
+ protected matchTokens(input: string, eventName: string, toks: any, e: InterfaceEvent, data, vars): any {
36
+ toks = toks || [];
37
+ let s = input;
38
+ let regx = /(?<=@bind\=\s*).*?(?=\;)/g;
39
+ let match;
40
+ let sys = sysAlias;
41
+ let state = stateAlias;
42
+ let webApp = webAppAlias;
43
+ while (match = regx.exec(s)) {
44
+ let bind = match[0];
45
+ if (typeof toks[bind] !== 'undefined') continue;
46
+ let tok: any = {};
47
+ toks[bind] = tok;
48
+ try {
49
+ // we may error out if data can't be found (eg during init)
50
+ tok.reg = new RegExp("@bind=" + this.escapeRegex(bind) + ";", "g");
51
+ tok.value = eval(bind);
52
+ }
53
+ catch (err) {
54
+ // leave value undefined so it isn't sent to bindings
55
+ toks[bind] = null;
56
+ }
57
+ }
58
+ return toks;
59
+
60
+ }
61
+ protected buildTokens(input: string, eventName: string, toks: any, e: InterfaceEvent, data): any {
62
+ toks = toks || [];
63
+ let s = input;
64
+ let regx = /(?<=@bind\=\s*).*?(?=\;)/g;
65
+ let match;
66
+ let vars = this.bindVarTokens(e, eventName, data);
67
+ let sys = sysAlias;
68
+ let state = stateAlias;
69
+ let webApp = webAppAlias;
70
+ // Map all the returns to the token list. We are being very basic
71
+ // here an the object graph is simply based upon the first object occurrence.
72
+ // We simply want to eval against that object reference.
73
+
74
+ while (match = regx.exec(s)) {
75
+ let bind = match[0];
76
+ if (typeof toks[bind] !== 'undefined') continue;
77
+ let tok: any = {};
78
+ toks[bind] = tok;
79
+ try {
80
+ // we may error out if data can't be found (eg during init)
81
+ tok.reg = new RegExp("@bind=" + this.escapeRegex(bind) + ";", "g");
82
+ tok.value = eval(bind);
83
+ }
84
+ catch (err) {
85
+ // leave value undefined so it isn't sent to bindings
86
+ toks[bind] = null;
87
+ }
88
+ }
89
+ return toks;
90
+ }
91
+ protected escapeRegex(reg: string) { return reg.replace(/[-[\]{}()*+?.|,\\^$]/g, '\\$&'); }
92
+ protected replaceTokens(input: string, toks: any) {
93
+ let s = input;
94
+ for (let exp in toks) {
95
+ let tok = toks[exp];
96
+ if (!tok || typeof tok.reg === 'undefined') continue;
97
+ tok.reg.lastIndex = 0; // Start over if we used this before.
98
+ if (typeof tok.value === 'string') s = s.replace(tok.reg, tok.value);
99
+ else if (typeof tok.value === 'undefined') s = s.replace(tok.reg, 'null');
100
+ else s = s.replace(tok.reg, JSON.stringify(tok.value));
101
+ }
102
+ return s;
103
+ }
104
+ protected evalTokens(input: string, toks: any) {
105
+ let s = input;
106
+ for (let exp in toks) {
107
+ let tok = toks[exp];
108
+ if (!tok || typeof tok.reg === 'undefined') continue;
109
+ tok.reg.lastIndex = 0; // Start over if we used this before.
110
+ if (typeof tok.value === 'string') s = s.replace(tok.reg, tok.value);
111
+ else if (typeof tok.value === 'undefined') s = s.replace(tok.reg, 'null');
112
+ else return tok.value;
113
+ }
114
+ }
115
+ protected tokensReplacer(input: string, eventName: string, toks: any, e: InterfaceEvent, data): any{
116
+ this.buildTokens(input, eventName, toks, e, data);
117
+ return this.replaceTokens(input, toks);
118
+ }
119
+ public async stopAsync() { }
120
+ }
121
+
122
+ export class InterfaceEvent {
123
+ public name: string;
124
+ public enabled: boolean = true;
125
+ public filter: string;
126
+ public options: any = {};
127
+ public body: any = {};
128
+ public vars: any = {};
129
+ }
130
+ export class InterfaceContext {
131
+ public name: string;
132
+ public mdnsDiscovery: any;
133
+ public upnpDevice: any;
134
+ public options: any = {};
135
+ public vars: any = {};
136
+ }