@awarevue/api-types 1.0.73 → 1.0.75
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.
- package/dist/alarm-automation.js +14 -8
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/alarm-automation.js
CHANGED
|
@@ -88,28 +88,34 @@ exports.parseAlarmAutomationCode = parseAlarmAutomationCode;
|
|
|
88
88
|
// ]
|
|
89
89
|
// }
|
|
90
90
|
// }
|
|
91
|
-
const
|
|
91
|
+
const encodeValue = (value) => {
|
|
92
92
|
if (typeof value === 'string') {
|
|
93
|
-
return
|
|
93
|
+
return `${JSON.stringify(value)}`;
|
|
94
94
|
}
|
|
95
95
|
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
96
|
-
return
|
|
96
|
+
return `${String(value)}`;
|
|
97
97
|
}
|
|
98
98
|
if (Array.isArray(value)) {
|
|
99
|
-
return `
|
|
99
|
+
return `(${value.map(encodeValue).join(', ')})`;
|
|
100
100
|
}
|
|
101
101
|
if (value === null) {
|
|
102
|
-
return '
|
|
102
|
+
return 'null';
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`Unsupported value type for: ${typeof value}`);
|
|
105
|
+
};
|
|
106
|
+
const encodeComparison = (value) => {
|
|
107
|
+
if (Array.isArray(value)) {
|
|
108
|
+
return `in ${encodeValue(value)}`;
|
|
103
109
|
}
|
|
104
|
-
|
|
110
|
+
return `== ${encodeValue(value)}`;
|
|
105
111
|
};
|
|
106
112
|
const createAlarmRuleBody = (eventKind, behavior, deviceType, eventCriteria, deviceId) => {
|
|
107
113
|
let runIf = 'source.type == "' + deviceType + '"';
|
|
108
114
|
if (deviceId) {
|
|
109
|
-
runIf += `
|
|
115
|
+
runIf += ` and source.id == "${deviceId}"`;
|
|
110
116
|
}
|
|
111
117
|
for (const criterion of eventCriteria) {
|
|
112
|
-
runIf += `
|
|
118
|
+
runIf += ` and event.${criterion.field} ${encodeComparison(criterion.value)}`;
|
|
113
119
|
}
|
|
114
120
|
return {
|
|
115
121
|
onEvent: eventKind,
|
package/dist/package.json
CHANGED