@machinemetrics/io-adapter-lib 2.32.0 → 2.32.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.
package/CHANGELOG.md
CHANGED
|
@@ -379,7 +379,7 @@ class AdapterConfig {
|
|
|
379
379
|
defn.message = override['override-message'];
|
|
380
380
|
defn.messagePath = `conditions.${key}.overrides.${index}.override-message`;
|
|
381
381
|
defn.messageIsStatic = this.expressionService.isStaticExpression(defn.messagePath);
|
|
382
|
-
defn.messageResolver = this.expressionResolver(defn.
|
|
382
|
+
defn.messageResolver = this.expressionResolver(defn.message, defn.messagePath);
|
|
383
383
|
defn.messageResolverTriggers = this.expressionService.expressionTriggers(defn.messagePath);
|
|
384
384
|
this.conditionsByExpression[defn.messagePath] = key;
|
|
385
385
|
}
|
|
@@ -19,13 +19,11 @@ class OpcuaConfig {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
getIdentifiers(config = {}) {
|
|
22
|
-
|
|
23
|
-
// No tags, this should be a softer warning
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
22
|
+
const keyset = Object.keys(config.tags || {});
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (config['opcua-conditions']?.key) {
|
|
25
|
+
keyset.push(config['opcua-conditions'].key);
|
|
26
|
+
} else if (config['opcua-condition-key']) {
|
|
29
27
|
keyset.push(config['opcua-condition-key']);
|
|
30
28
|
}
|
|
31
29
|
|
|
@@ -55,7 +53,17 @@ class OpcuaConfig {
|
|
|
55
53
|
this.userPrivateKeyPath = config['user-private-key-path'];
|
|
56
54
|
|
|
57
55
|
this.tags = this.loadTags(config.tags);
|
|
56
|
+
|
|
57
|
+
// opcua-condition-key deprecated in favor of opcua-conditions
|
|
58
58
|
this.conditionKey = config['opcua-condition-key'];
|
|
59
|
+
this.opcuaConditions = this.loadConditions(config['opcua-conditions']);
|
|
60
|
+
|
|
61
|
+
// For backwards compatibility
|
|
62
|
+
if (this.conditionKey && !this.opcuaConditions?.key) {
|
|
63
|
+
this.opcuaConditions = { key: this.conditionKey };
|
|
64
|
+
} else if (this.opcuaConditions?.key) {
|
|
65
|
+
this.conditionKey = this.opcuaConditions.key;
|
|
66
|
+
}
|
|
59
67
|
|
|
60
68
|
this.securityMode = this.checkSecurityMode(config['security-mode']);
|
|
61
69
|
this.securityPolicy = this.checkSecurityPolicy(config['security-policy']);
|
|
@@ -106,6 +114,45 @@ class OpcuaConfig {
|
|
|
106
114
|
}).keyBy('name').value();
|
|
107
115
|
}
|
|
108
116
|
|
|
117
|
+
loadConditions(conditions) {
|
|
118
|
+
if (!conditions) {
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
if (!conditions.key) {
|
|
124
|
+
throw new ConfigError('key is required').atAttribute('key');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const result = {
|
|
128
|
+
key: conditions.key,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (_.has(conditions, 'fault-threshold')) {
|
|
132
|
+
const faultThreshold = conditions['fault-threshold'];
|
|
133
|
+
if (!_.isNumber(faultThreshold)) {
|
|
134
|
+
throw new ConfigError('fault-threshold must be a number').atAttribute('fault-threshold');
|
|
135
|
+
}
|
|
136
|
+
result.faultThreshold = faultThreshold;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (_.has(conditions, 'warning-threshold')) {
|
|
140
|
+
const warningThreshold = conditions['warning-threshold'];
|
|
141
|
+
if (!_.isNumber(warningThreshold)) {
|
|
142
|
+
throw new ConfigError('warning-threshold must be a number').atAttribute('warning-threshold');
|
|
143
|
+
}
|
|
144
|
+
result.warningThreshold = warningThreshold;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return result;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (error instanceof ConfigError) {
|
|
150
|
+
error.atSection('opcua-conditions');
|
|
151
|
+
}
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
109
156
|
checkTagPath(defn) {
|
|
110
157
|
const path = defn.path;
|
|
111
158
|
if (!path) {
|
package/package.json
CHANGED
|
@@ -7,9 +7,12 @@ const testUtils = require('../util/testUtils');
|
|
|
7
7
|
describe('OPC-UA config tests', function () {
|
|
8
8
|
let config;
|
|
9
9
|
let defaultConfig;
|
|
10
|
+
let conditionsConfig;
|
|
11
|
+
|
|
10
12
|
before(async () => {
|
|
11
13
|
defaultConfig = await testUtils.loadConfig('device/opcua-default.yml');
|
|
12
14
|
config = await testUtils.loadConfig('device/opcua-std.yml');
|
|
15
|
+
conditionsConfig = await testUtils.loadConfig('device/opcua-conditions.yml');
|
|
13
16
|
});
|
|
14
17
|
|
|
15
18
|
it('loads minimal config with defaults', async function () {
|
|
@@ -24,6 +27,7 @@ describe('OPC-UA config tests', function () {
|
|
|
24
27
|
expect(defaultConfig.device.userCertificatePath).to.eq(undefined);
|
|
25
28
|
expect(defaultConfig.device.userPrivateKeyPath).to.eq(undefined);
|
|
26
29
|
expect(defaultConfig.device.conditionKey).to.eq(undefined);
|
|
30
|
+
expect(defaultConfig.device.opcuaConditions).to.deep.eq({});
|
|
27
31
|
});
|
|
28
32
|
|
|
29
33
|
it('reads tags', async function () {
|
|
@@ -31,7 +35,7 @@ describe('OPC-UA config tests', function () {
|
|
|
31
35
|
});
|
|
32
36
|
|
|
33
37
|
it('loaded expression service', async function () {
|
|
34
|
-
const deviceNames = ['fan-speed', 'pump-speed', 'some-date', 'pressure'];
|
|
38
|
+
const deviceNames = ['fan-speed', 'pump-speed', 'some-date', 'pressure', 'system'];
|
|
35
39
|
const allNames = [...deviceNames, 'device-connected'];
|
|
36
40
|
expect(config.expressionService.definedNames()).to.deep.eq(allNames);
|
|
37
41
|
expect(config.expressionService.definedNames('device')).to.deep.eq(deviceNames);
|
|
@@ -40,6 +44,11 @@ describe('OPC-UA config tests', function () {
|
|
|
40
44
|
expect(config.expressionService.referencedNames('device')).to.deep.eq(['fan-speed', 'pump-speed']);
|
|
41
45
|
});
|
|
42
46
|
|
|
47
|
+
it('migrates deprecated opcua-condition-key to opcua-conditions', async function () {
|
|
48
|
+
expect(config.device.conditionKey).to.eq('system');
|
|
49
|
+
expect(config.device.opcuaConditions).to.deep.eq({ key: 'system' });
|
|
50
|
+
});
|
|
51
|
+
|
|
43
52
|
it('catches bad tag definition (bad path syntax)', async function () {
|
|
44
53
|
try {
|
|
45
54
|
await testUtils.loadConfig('device/opcua-bad-tag.yml');
|
|
@@ -94,4 +103,13 @@ describe('OPC-UA config tests', function () {
|
|
|
94
103
|
testPath('10853');
|
|
95
104
|
testPath('nsu=http://test.org/UA/Data/;i=10853');
|
|
96
105
|
});
|
|
106
|
+
|
|
107
|
+
it('loads opcua-conditions with all properties', async function () {
|
|
108
|
+
expect(conditionsConfig.device.opcuaConditions).to.deep.eq({
|
|
109
|
+
key: 'system',
|
|
110
|
+
faultThreshold: 100,
|
|
111
|
+
warningThreshold: 50,
|
|
112
|
+
});
|
|
113
|
+
expect(conditionsConfig.device.conditionKey).to.eq('system');
|
|
114
|
+
});
|
|
97
115
|
});
|