Skip to content

Commit

Permalink
fix: listener monitored item select from list
Browse files Browse the repository at this point in the history
  • Loading branch information
biancode committed Oct 10, 2018
1 parent ab8b4ca commit 8213bef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/opcua-iiot-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ module.exports = function (RED) {
itemsToTerminate.forEach(addressSpaceItem => {
const nodeIdToMonitor = (typeof addressSpaceItem.nodeId === 'string') ? addressSpaceItem.nodeId : addressSpaceItem.nodeId.toString()
const item = node.monitoredASO.get(nodeIdToMonitor)
if (item.monitoredItem) {
if (item && item.monitoredItem) {
coreListener.subscribeDebugLog('Monitored Item Unsubscribe ' + nodeIdToMonitor)
item.monitoredItem.terminate(function (err) {
coreListener.subscribeDebugLog('Terminated Monitored Item ' + item.monitoredItem.itemToMonitor.nodeId)
Expand Down Expand Up @@ -278,7 +278,7 @@ module.exports = function (RED) {

const item = node.monitoredASO.get(nodeIdToMonitor)

if (!item.monitoredItem) {
if (!item) {
coreListener.eventDebugLog('Regsiter Event Item ' + nodeIdToMonitor)
coreListener.buildNewEventItem(nodeIdToMonitor, msg, uaSubscription)
.then(function (result) {
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/opcua-iiot-method-caller-e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict'

jest.setTimeout(10000)
jest.setTimeout(12000)

var injectNodeRed = require('node-red/nodes/core/core/20-inject')
var functionNode = require('node-red/nodes/core/core/80-function')
Expand Down Expand Up @@ -214,6 +214,8 @@ var testMethodInjectFlowPayload = [
'compressStructure': false,
'showStatusActivities': false,
'showErrors': false,
'activateFilters': false,
'filters': [],
'wires': [
['n8mcf2']
]
Expand Down Expand Up @@ -349,9 +351,11 @@ describe('OPC UA Method Caller node e2e Testing', function () {
helper.load(eventNodesToLoad, testMethodInjectFlowPayload, function () {
let n8 = helper.getNode('n8mcf2')
n8.on('input', function (msg) {
console.log(msg)
expect(msg.nodetype).toBe('method')
expect(msg.entryStatus).toMatchObject([1, 0, 0])
expect(msg.payload).toMatchObject({'results': [{'statusCode': {'value': 0, 'description': 'No Error', 'name': 'Good'}, 'inputArgumentResults': [[{'value': 0, 'description': 'No Error', 'name': 'Good'}, {'value': 0, 'description': 'No Error', 'name': 'Good'}], [{'value': 0, 'description': 'No Error', 'name': 'Good'}, {'value': 0, 'description': 'No Error', 'name': 'Good'}]], 'inputArgumentDiagnosticInfos': [], 'outputArguments': [{'dataType': 'String', 'arrayType': 'Array', 'value': ['Whaff!!!!!!!!!!!', 'Whaff!!!!!!!!!!!', 'Whaff!!!!!!!!!!!', 'Whaff!!!!!!!!!!!', 'Whaff!!!!!!!!!!!', 'Whaff!!!!!!!!!!!']}]}], 'definition': {'methodId': 'ns=1;i=12345', 'methodDefinition': {'inputArguments': {'inputArguments': [{'name': 'barks', 'dataType': 'ns=0;i=7', 'valueRank': -1, 'arrayDimensions': [[0]], 'description': {'text': 'specifies the number of time I should bark'}}, {'name': 'volume', 'dataType': 'ns=0;i=7', 'valueRank': -1, 'arrayDimensions': [[0]], 'description': {'text': 'specifies the sound volume [0 = quiet ,100 = loud]'}}], 'outputArguments': [{'name': 'Barks', 'dataType': 'ns=0;i=12', 'valueRank': 1, 'arrayDimensions': [[0]], 'description': {'text': 'the generated barks'}}]}}}})
expect(msg.payload.results).toBeDefined()
expect(msg.payload.definition).toBeDefined()
done()
})
})
Expand Down

0 comments on commit 8213bef

Please sign in to comment.