nodejs-poolcontroller 7.6.1 → 7.7.0

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 (91) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -0
  3. package/.github/ISSUE_TEMPLATE/2-docs.md +12 -0
  4. package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -0
  5. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  6. package/CONTRIBUTING.md +74 -74
  7. package/Changelog +220 -215
  8. package/Dockerfile +17 -17
  9. package/Gruntfile.js +40 -40
  10. package/LICENSE +661 -661
  11. package/README.md +191 -191
  12. package/app.ts +1 -1
  13. package/config/Config.ts +14 -0
  14. package/config/VersionCheck.ts +2 -2
  15. package/controller/Constants.ts +2 -1
  16. package/controller/Equipment.ts +2484 -2459
  17. package/controller/Errors.ts +180 -180
  18. package/controller/Lockouts.ts +502 -436
  19. package/controller/State.ts +106 -30
  20. package/controller/boards/AquaLinkBoard.ts +1000 -0
  21. package/controller/boards/BoardFactory.ts +49 -45
  22. package/controller/boards/EasyTouchBoard.ts +2859 -2653
  23. package/controller/boards/IntelliCenterBoard.ts +4198 -4230
  24. package/controller/boards/IntelliComBoard.ts +63 -63
  25. package/controller/boards/IntelliTouchBoard.ts +273 -241
  26. package/controller/boards/NixieBoard.ts +1728 -1675
  27. package/controller/boards/SystemBoard.ts +4925 -4697
  28. package/controller/comms/Comms.ts +442 -479
  29. package/controller/comms/messages/Messages.ts +171 -25
  30. package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -2
  31. package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
  32. package/controller/comms/messages/config/CircuitMessage.ts +1 -0
  33. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  34. package/controller/comms/messages/config/CoverMessage.ts +0 -0
  35. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  36. package/controller/comms/messages/config/EquipmentMessage.ts +0 -0
  37. package/controller/comms/messages/config/ExternalMessage.ts +0 -0
  38. package/controller/comms/messages/config/FeatureMessage.ts +0 -0
  39. package/controller/comms/messages/config/GeneralMessage.ts +0 -0
  40. package/controller/comms/messages/config/HeaterMessage.ts +142 -10
  41. package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
  42. package/controller/comms/messages/config/OptionsMessage.ts +4 -21
  43. package/controller/comms/messages/config/PumpMessage.ts +53 -35
  44. package/controller/comms/messages/config/RemoteMessage.ts +0 -0
  45. package/controller/comms/messages/config/ScheduleMessage.ts +350 -347
  46. package/controller/comms/messages/config/SecurityMessage.ts +0 -0
  47. package/controller/comms/messages/config/ValveMessage.ts +1 -1
  48. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +38 -86
  49. package/controller/comms/messages/status/EquipmentStateMessage.ts +58 -22
  50. package/controller/comms/messages/status/HeaterStateMessage.ts +116 -86
  51. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -445
  52. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  53. package/controller/comms/messages/status/PumpStateMessage.ts +23 -1
  54. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  55. package/controller/nixie/Nixie.ts +162 -162
  56. package/controller/nixie/NixieEquipment.ts +103 -103
  57. package/controller/nixie/bodies/Body.ts +120 -120
  58. package/controller/nixie/bodies/Filter.ts +135 -135
  59. package/controller/nixie/chemistry/ChemController.ts +2511 -2498
  60. package/controller/nixie/chemistry/Chlorinator.ts +363 -314
  61. package/controller/nixie/circuits/Circuit.ts +261 -248
  62. package/controller/nixie/heaters/Heater.ts +650 -648
  63. package/controller/nixie/pumps/Pump.ts +906 -661
  64. package/controller/nixie/schedules/Schedule.ts +313 -257
  65. package/controller/nixie/valves/Valve.ts +170 -170
  66. package/defaultConfig.json +306 -286
  67. package/logger/DataLogger.ts +448 -448
  68. package/logger/Logger.ts +0 -0
  69. package/package.json +56 -56
  70. package/tsconfig.json +25 -25
  71. package/web/Server.ts +92 -47
  72. package/web/bindings/aqualinkD.json +505 -0
  73. package/web/bindings/influxDB.json +1051 -1021
  74. package/web/bindings/mqtt.json +702 -654
  75. package/web/bindings/mqttAlt.json +731 -684
  76. package/web/bindings/rulesManager.json +54 -54
  77. package/web/bindings/smartThings-Hubitat.json +31 -31
  78. package/web/bindings/valveRelays.json +20 -20
  79. package/web/bindings/vera.json +25 -25
  80. package/web/interfaces/baseInterface.ts +137 -136
  81. package/web/interfaces/httpInterface.ts +145 -124
  82. package/web/interfaces/influxInterface.ts +276 -245
  83. package/web/interfaces/mqttInterface.ts +535 -475
  84. package/web/services/config/Config.ts +39 -18
  85. package/web/services/config/ConfigSocket.ts +0 -0
  86. package/web/services/state/State.ts +10 -0
  87. package/web/services/state/StateSocket.ts +4 -4
  88. package/web/services/utilities/Utilities.ts +44 -42
  89. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -52
  90. package/config copy.json +0 -300
  91. package/issue_template.md +0 -52
@@ -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,137 @@
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
+ public processor?: string[]
130
+ }
131
+ export class InterfaceContext {
132
+ public name: string;
133
+ public mdnsDiscovery: any;
134
+ public upnpDevice: any;
135
+ public options: any = {};
136
+ public vars: any = {};
137
+ }