@machinemetrics/io-adapter-lib 2.32.1 → 2.32.3

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
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.32.3]
4
+ - Added opcua-conditions options for code format and allow/deny nodes
5
+
6
+ ## [2.32.2]
7
+ - Add support to reclassify conditions to NORMAL
8
+
3
9
  ## [2.32.1]
4
10
  - Added opcua-conditions block to opcua config
5
11
  - Fixed message overrides in conditions
@@ -350,6 +350,9 @@ class AdapterConfig {
350
350
  if (item['reclassify-fault']) {
351
351
  source.reclassifyFault = allowDenyList.parseWildcardKeyList(item['reclassify-fault'], `conditions.${key}.reclassify-fault-codes`);
352
352
  }
353
+ if (item['reclassify-normal']) {
354
+ source.reclassifyNormal = allowDenyList.parseWildcardKeyList(item['reclassify-normal'], `conditions.${key}.reclassify-normal-codes`);
355
+ }
353
356
 
354
357
  if (item.overrides) {
355
358
  if (!_.isArray(item.overrides)) {
@@ -2,6 +2,9 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const ConfigError = require('../configError');
5
+ const AllowDenyList = require('../common/allowDenyList');
6
+
7
+ const allowDenyList = new AllowDenyList();
5
8
 
6
9
  // Pattern to match valid OPC-UA node ID paths, as supported by node-opcua
7
10
  // Our validation may be slightly stricter on some value validation.
@@ -144,6 +147,28 @@ class OpcuaConfig {
144
147
  result.warningThreshold = warningThreshold;
145
148
  }
146
149
 
150
+ result.codeFormat = '{conditionName}_{conditionIdHash}';
151
+ if (_.has(conditions, 'code-format')) {
152
+ const codeFormat = conditions['code-format'];
153
+ if (_.isEmpty(codeFormat) || !_.isString(codeFormat)) {
154
+ throw new ConfigError('code-format cannot be empty').atAttribute('code-format');
155
+ }
156
+ result.codeFormat = codeFormat;
157
+ }
158
+
159
+ if (_.has(conditions, 'allow-condition-nodes')) {
160
+ result.allowConditionNodes = allowDenyList.parseWildcardKeyList(conditions['allow-condition-nodes'], 'allow-condition-nodes');
161
+ }
162
+ if (_.has(conditions, 'deny-condition-nodes')) {
163
+ result.denyConditionNodes = allowDenyList.parseWildcardKeyList(conditions['deny-condition-nodes'], 'deny-condition-nodes');
164
+ }
165
+ if (_.has(conditions, 'allow-source-nodes')) {
166
+ result.allowSourceNodes = allowDenyList.parseWildcardKeyList(conditions['allow-source-nodes'], 'allow-source-nodes');
167
+ }
168
+ if (_.has(conditions, 'deny-source-nodes')) {
169
+ result.denySourceNodes = allowDenyList.parseWildcardKeyList(conditions['deny-source-nodes'], 'deny-source-nodes');
170
+ }
171
+
147
172
  return result;
148
173
  } catch (error) {
149
174
  if (error instanceof ConfigError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/io-adapter-lib",
3
- "version": "2.32.1",
3
+ "version": "2.32.3",
4
4
  "description": "Configuration and engine implementation for MachineMetrics AdapterScripts and adapters",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",
@@ -4,7 +4,8 @@
4
4
  },
5
5
  "rules": {
6
6
  "import/no-extraneous-dependencies": [ "off" ],
7
- "prefer-arrow-callback": "off"
7
+ "prefer-arrow-callback": "off",
8
+ "no-unused-expressions": "off"
8
9
  },
9
10
  "env": {
10
11
  "mocha": true
@@ -72,6 +72,37 @@ describe('data items', async function () {
72
72
  validateCondition(captured[10], 'cond1', 'FAULT', 5000, 'A2', 'Code A2');
73
73
  validateCondition(captured[11], 'cond2', 'FAULT', 6000, 'B33', 'Code B33');
74
74
  });
75
+
76
+ it('loads reclassification config', async function () {
77
+ expect(config.adapter.passthroughConditions).to.exist;
78
+ expect(config.adapter.passthroughConditions.system).to.exist;
79
+ expect(config.adapter.passthroughConditions.system.length).to.eq(1);
80
+
81
+ const source = config.adapter.passthroughConditions.system[0];
82
+ expect(source.name).to.eq('cond4');
83
+ expect(source.reclassifyFault).to.exist;
84
+ expect(source.reclassifyWarning).to.exist;
85
+ expect(source.reclassifyNormal).to.exist;
86
+ });
87
+
88
+ it('reclassifies codes based on patterns', async function () {
89
+ const source = config.adapter.passthroughConditions.system[0];
90
+
91
+ // Test FAULT reclassification
92
+ expect(source.reclassifyFault[0].test('HIGH_TEMP')).to.eq(true);
93
+ expect(source.reclassifyFault[0].test('HIGH_PRESSURE')).to.eq(true);
94
+ expect(source.reclassifyFault[0].test('MEDIUM_TEMP')).to.eq(false);
95
+
96
+ // Test WARNING reclassification
97
+ expect(source.reclassifyWarning[0].test('MEDIUM_TEMP')).to.eq(true);
98
+ expect(source.reclassifyWarning[0].test('MEDIUM_PRESSURE')).to.eq(true);
99
+ expect(source.reclassifyWarning[0].test('LOW_TEMP')).to.eq(false);
100
+
101
+ // Test NORMAL reclassification
102
+ expect(source.reclassifyNormal[0].test('LOW_TEMP')).to.eq(true);
103
+ expect(source.reclassifyNormal[0].test('LOW_PRESSURE')).to.eq(true);
104
+ expect(source.reclassifyNormal[0].test('HIGH_TEMP')).to.eq(false);
105
+ });
75
106
  });
76
107
 
77
108
  function validateCondition(entry, key, value, time, code, message) {
@@ -8,11 +8,13 @@ describe('OPC-UA config tests', function () {
8
8
  let config;
9
9
  let defaultConfig;
10
10
  let conditionsConfig;
11
+ let conditionsDefaultConfig;
11
12
 
12
13
  before(async () => {
13
14
  defaultConfig = await testUtils.loadConfig('device/opcua-default.yml');
14
15
  config = await testUtils.loadConfig('device/opcua-std.yml');
15
16
  conditionsConfig = await testUtils.loadConfig('device/opcua-conditions.yml');
17
+ conditionsDefaultConfig = await testUtils.loadConfig('device/opcua-conditions-default.yml');
16
18
  });
17
19
 
18
20
  it('loads minimal config with defaults', async function () {
@@ -104,12 +106,27 @@ describe('OPC-UA config tests', function () {
104
106
  testPath('nsu=http://test.org/UA/Data/;i=10853');
105
107
  });
106
108
 
109
+ it('loads opcua-conditions with default properties', async function () {
110
+ expect(conditionsDefaultConfig.device.opcuaConditions.key).to.eq('system');
111
+ expect(conditionsDefaultConfig.device.opcuaConditions.faultThreshold).to.eq(undefined);
112
+ expect(conditionsDefaultConfig.device.opcuaConditions.warningThreshold).to.eq(undefined);
113
+ expect(conditionsDefaultConfig.device.opcuaConditions.codeFormat).to.eq('{conditionName}_{conditionIdHash}');
114
+ expect(conditionsDefaultConfig.device.opcuaConditions.allowConditionNodes).to.eq(undefined);
115
+ expect(conditionsDefaultConfig.device.opcuaConditions.denyConditionNodes).to.eq(undefined);
116
+ expect(conditionsDefaultConfig.device.opcuaConditions.allowSourceNodes).to.eq(undefined);
117
+ expect(conditionsDefaultConfig.device.opcuaConditions.denySourceNodes).to.eq(undefined);
118
+ expect(conditionsDefaultConfig.device.conditionKey).to.eq('system');
119
+ });
120
+
107
121
  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
- });
122
+ expect(conditionsConfig.device.opcuaConditions.key).to.eq('system');
123
+ expect(conditionsConfig.device.opcuaConditions.faultThreshold).to.eq(100);
124
+ expect(conditionsConfig.device.opcuaConditions.warningThreshold).to.eq(50);
125
+ expect(conditionsConfig.device.opcuaConditions.codeFormat).to.eq('{conditionName}');
126
+ expect(conditionsConfig.device.opcuaConditions.allowConditionNodes).to.have.lengthOf(1);
127
+ expect(conditionsConfig.device.opcuaConditions.denyConditionNodes).to.have.lengthOf(1);
128
+ expect(conditionsConfig.device.opcuaConditions.allowSourceNodes).to.have.lengthOf(1);
129
+ expect(conditionsConfig.device.opcuaConditions.denySourceNodes).to.have.lengthOf(1);
113
130
  expect(conditionsConfig.device.conditionKey).to.eq('system');
114
131
  });
115
132
  });
@@ -5,6 +5,8 @@ declare-keys:
5
5
  - key2
6
6
  - key3
7
7
  - key4
8
+ - system:
9
+ type: condition
8
10
  variables:
9
11
  keymod:
10
12
  - source: key2
@@ -35,3 +37,11 @@ conditions:
35
37
  override-message: ${this} coolant=${key1}
36
38
  - override-code: Y
37
39
  override-message: Z
40
+ cond4:
41
+ source: system
42
+ reclassify-fault:
43
+ - HIGH*
44
+ reclassify-warning:
45
+ - MEDIUM*
46
+ reclassify-normal:
47
+ - LOW*
@@ -0,0 +1,5 @@
1
+ version: 2
2
+ device: opc-ua
3
+ endpoint: opc.tcp://localhost:4840
4
+ opcua-conditions:
5
+ key: system
@@ -5,3 +5,12 @@ opcua-conditions:
5
5
  key: system
6
6
  fault-threshold: 100
7
7
  warning-threshold: 50
8
+ code-format: "{conditionName}"
9
+ allow-condition-nodes:
10
+ - ns=2;s=Flames/*
11
+ deny-condition-nodes:
12
+ - ns=2;s=Flames/ControlledFacilityComponents/*
13
+ allow-source-nodes:
14
+ - ns=2;s=Flames/*
15
+ deny-source-nodes:
16
+ - ns=2;s=Flames/ControlledFacilityComponents/*