@bitpoolos/edge-bacnet 1.4.4 → 1.4.6

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/treeBuilder.js CHANGED
@@ -63,11 +63,45 @@ class treeBuilder {
63
63
  // Check if the device object exists and the device name is valid
64
64
  if (deviceObject) {
65
65
  await this.processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index);
66
+
67
+ //delete dummy object if all conditions satisfied
68
+ if (deviceName !== null) {
69
+ if (deviceId !== null) {
70
+ let lastIndex = deviceName.lastIndexOf(deviceId);
71
+ if (lastIndex) {
72
+ let formattedName = deviceName.substring(0, lastIndex);
73
+ formattedName = `${formattedName.trim()}_Device_${deviceId}`;
74
+ if (
75
+ this.networkTree[deviceKey][formattedName] &&
76
+ Object.keys(this.networkTree[deviceKey][formattedName]).length > 0 &&
77
+ this.networkTree[deviceKey]["device"]
78
+ ) {
79
+ delete this.networkTree[deviceKey]["device"];
80
+ }
81
+ }
82
+ }
83
+ }
84
+
66
85
  } else {
67
- //console.log("Unable to find device object");
86
+ //invalid ip object, likely dumb mstp router
87
+ if (device.getIsDumbMstpRouter()) {
88
+ //update dumb mstp router name
89
+ await this.updateDumbMstpRouterName(deviceName, ipAddress, deviceId);
90
+ }
68
91
  }
69
92
  }
70
93
 
94
+ async updateDumbMstpRouterName(deviceName, ipAddress, deviceId) {
95
+ return new Promise((resolve, reject) => {
96
+ let listDeviceIndex = this.renderList.findIndex(item => item.deviceId == deviceId && item.ipAddr == ipAddress && item.isDumbMstpRouter == true);
97
+ if (listDeviceIndex !== -1) {
98
+ this.renderList[listDeviceIndex].label = deviceName;
99
+ this.renderList[listDeviceIndex].data = deviceName;
100
+ }
101
+ resolve();
102
+ });
103
+ }
104
+
71
105
  /**
72
106
  * Add the root device folder to the render list.
73
107
  *
@@ -88,8 +122,9 @@ class treeBuilder {
88
122
 
89
123
  // Check if the device already exists in the renderList
90
124
  const existingDeviceIndex = this.renderList.findIndex(item => item.deviceId === deviceId && item.ipAddr === ipAddress);
91
-
92
125
  if (existingDeviceIndex === -1) { // Device not found, add new entry
126
+ let isDumbMstpRouter = false;
127
+ if (device.getIsDumbMstpRouter() && deviceId == null) isDumbMstpRouter = true;
93
128
  const rootFolder = {
94
129
  key: index,
95
130
  label: displayName,
@@ -103,6 +138,7 @@ class treeBuilder {
103
138
  deviceId,
104
139
  isMstpDevice: device.getIsMstpDevice(),
105
140
  initialName: device.getDeviceName(),
141
+ isDumbMstpRouter: isDumbMstpRouter,
106
142
  };
107
143
 
108
144
  // Add the root folder to the render list
@@ -112,10 +148,10 @@ class treeBuilder {
112
148
  }
113
149
 
114
150
  addEmptyIpRootDevice(childDevice) {
115
-
116
151
  const ipAddress = this.getDeviceIpAddress(childDevice);
117
152
 
118
- let deviceIndex = this.deviceList.findIndex(ele => ele.address === ipAddress && ele.deviceId === null && ele.deviceName === ipAddress && ele.displayName === ipAddress);
153
+ //let deviceIndex = this.deviceList.findIndex(ele => ele.address === ipAddress && ele.deviceId === null && ele.deviceName === ipAddress && ele.displayName === ipAddress);
154
+ let deviceIndex = this.deviceList.findIndex(ele => ele.address === ipAddress && ele.deviceId === null);
119
155
 
120
156
  if (deviceIndex === -1) {
121
157
  let newDevice = {
@@ -140,6 +176,7 @@ class treeBuilder {
140
176
  protocolServicesSupported: [],
141
177
  isProtocolServicesSet: false,
142
178
  isInitialQuery: true,
179
+ isDumbMstpRouter: true,
143
180
  };
144
181
 
145
182
  let newBacnetDevice = new BacnetDevice(true, newDevice);
@@ -287,7 +324,6 @@ class treeBuilder {
287
324
  updateRenderList(children, device, deviceName, index, ipAddress, deviceId) {
288
325
  // Create the folder structure for the device
289
326
  const folderJson = this.createFolderJson(children, device.hasChildDevices(), deviceId);
290
-
291
327
  if (!this.renderList) {
292
328
  this.renderList = [];
293
329
  }