node-red-contrib-mobius-flow-base 2.5.86-beta.74 → 2.5.86-beta.78

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.
@@ -29,7 +29,7 @@
29
29
  const _ = require('lodash');
30
30
 
31
31
  module.exports = {
32
- async discover(connection, uri) {
32
+ async discover (connection, uri) {
33
33
  return new Promise((resolve, reject) => {
34
34
  connection.discover(uri, (err, response) => {
35
35
  if (err) {
@@ -41,7 +41,7 @@ module.exports = {
41
41
  });
42
42
  },
43
43
 
44
- async discoverDevicesByPID(RED, connection, hid, spids, pid) {
44
+ async discoverDevicesByPID (RED, connection, hid, spids, pid) {
45
45
  let devices = [];
46
46
  if (!hid || hid === '') {
47
47
  hid = connection.service.srvcAPI.status.hubId;
@@ -54,17 +54,12 @@ module.exports = {
54
54
  throw new Error(`Discover devices failed (${hid}) - ${err.message}`);
55
55
  }
56
56
  for (let srvcLoop = 0; srvcLoop < services.value.length; srvcLoop++) {
57
- if (
58
- services.value[srvcLoop].status === 'online' &&
59
- (spids.length === 0 || spids.includes(services.value[srvcLoop].spid))
60
- ) {
57
+ if (services.value[srvcLoop].status === 'online' && (spids.length === 0 || spids.includes(services.value[srvcLoop].spid))) {
61
58
  let insURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}`;
62
59
  try {
63
60
  let instances = await this.discover(connection, insURI);
64
61
  for (let insLoop = 0; insLoop < instances.value.length; insLoop++) {
65
- let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${
66
- instances.value[insLoop]
67
- }`;
62
+ let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${instances.value[insLoop]}`;
68
63
  let device = await this.discover(connection, deviceURI);
69
64
  let resourcesByName = _.keyBy(device.value[0].resources, 'name');
70
65
  let deviceName = resourcesByName['name'].pv;
@@ -84,7 +79,7 @@ module.exports = {
84
79
  });
85
80
  },
86
81
 
87
- async discoverServicesBySPID(RED, connection, hid, spid) {
82
+ async discoverServicesBySPID (RED, connection, hid, spid) {
88
83
  if (!hid || hid === '') {
89
84
  hid = connection.service.srvcAPI.status.hubId;
90
85
  }
@@ -104,130 +99,5 @@ module.exports = {
104
99
  return new Promise((resolve) => {
105
100
  resolve(srvcs);
106
101
  });
107
- },
108
-
109
- getServiceList(connection, hid) {
110
- // getNodeConfig -> id, spid, uri, name, enabled, runAtStart
111
- // For every: getServiceConfig -> mobiusSettings, customSettings
112
- // discover -> registered, last connected, status + any remaining if new service
113
- // For every: discover object -/0001/0001 -> status, statusText
114
- return new Promise(async (resolve, reject) => {
115
- try {
116
- // Fetch information from node config
117
- const nodeConfig = await connection.getNodeConfig(hid);
118
- const servicesFromConfig = nodeConfig.value.services;
119
- let services = [];
120
- for (let i = 0; i < servicesFromConfig.length; i++) {
121
- services.push({
122
- id: servicesFromConfig[i].id,
123
- spid: servicesFromConfig[i].id.split('/')[0],
124
- sid: servicesFromConfig[i].id.split('/')[1],
125
- uri: `${nodeConfig.uri}/${servicesFromConfig[i].id.split('/')[1]}`,
126
- name: servicesFromConfig[i].name,
127
- enabled: servicesFromConfig[i].enabled,
128
- runAtStart: servicesFromConfig[i].runAtStart,
129
- registered: null,
130
- lastConnected: null,
131
- status: null,
132
- statusText: null,
133
- mobiusSettings: null,
134
- customSettings: null,
135
- pids: [],
136
- });
137
- }
138
-
139
- // Fetch information from each service config
140
- for (let i = 0; i < services.length; i++) {
141
- const fullServiceConfig = await connection.getServiceConfigProm(hid, services[i].sid);
142
- if (fullServiceConfig.value.serviceConfig !== undefined) {
143
- services[i].mobiusSettings = fullServiceConfig.value.serviceConfig.settings;
144
- services[i].customSettings = fullServiceConfig.value.serviceConfig.custom;
145
- } else {
146
- services[i].mobiusSettings = fullServiceConfig.value.settings;
147
- services[i].customSettings = fullServiceConfig.value.custom;
148
- }
149
- }
150
-
151
- // Fetch information from discovered services
152
- const discoveryResponse = await this.discover(connection, hid);
153
- const servicesFromDiscovery = discoveryResponse.value;
154
- for (let i = 0; i < servicesFromDiscovery.length; i++) {
155
- let serviceFound = false;
156
- for (let j = 0; j < services.length; j++) {
157
- if (servicesFromDiscovery[i].id === services[j].id) {
158
- serviceFound = true;
159
- services[j].registered = servicesFromDiscovery[i].registered;
160
- services[j].lastConnected = servicesFromDiscovery[i].lastconnected;
161
- j = services.length;
162
- }
163
- }
164
- if (!serviceFound) {
165
- services.push({
166
- id: servicesFromDiscovery[i].id,
167
- spid: servicesFromDiscovery[i].id.split('/')[0],
168
- sid: servicesFromDiscovery[i].id.split('/')[1],
169
- uri: `${nodeConfig.uri}/${servicesFromDiscovery[i].id.split('/')[1]}`,
170
- name: null,
171
- enabled: null,
172
- runAtStart: null,
173
- registered: servicesFromDiscovery[i].registered,
174
- lastConnected: servicesFromDiscovery[i].lastconnected,
175
- status: null,
176
- statusText: null,
177
- mobiusSettings: null,
178
- customSettings: null,
179
- pids: [],
180
- });
181
- }
182
- }
183
-
184
- // Fetch pids and status object from all services
185
- for (let i = 0; i < services.length; i++) {
186
- if (services[i].sid !== '009') {
187
- const serviceResponse = await this.discover(connection, `${hid}/${services[i].sid}`);
188
- services[i].pids = [...new Set(serviceResponse.value)];
189
- const statusObjectResponse = await this.discover(
190
- connection,
191
- `${hid}/${services[i].sid}/0001/0001`
192
- );
193
- const statusObject = statusObjectResponse.value[0];
194
- services[i].status = statusObject.resources[1].pv;
195
- services[i].statusText = `${statusObject.resources[2].pv}`;
196
- } else {
197
- services[i].pids = [];
198
- services[i].status = 'Unknown';
199
- services[i].statusText = 'Unknown';
200
- }
201
- }
202
-
203
- resolve(services);
204
- } catch (err) {
205
- reject(JSON.stringify(err));
206
- }
207
- });
208
- },
209
-
210
- getObjectList(connection, hid, sid) {
211
- return new Promise(async (resolve, reject) => {
212
- try {
213
- let objectList = [];
214
- const serviceResponse = await this.discover(connection, `${hid}/${sid}`);
215
- const pids = [...new Set(serviceResponse.value)];
216
- for (let i = 0; i < pids.length; i++) {
217
- const inssResponse = await this.discover(connection, `${hid}/${sid}/${pids[i]}`);
218
- const inss = inssResponse.value;
219
- for (let j = 0; j < inss.length; j++) {
220
- const objResponse = await this.discover(
221
- connection,
222
- `${hid}/${sid}/${pids[i]}/${inss[j]}`
223
- );
224
- objectList.push(objResponse.value[0]);
225
- }
226
- }
227
- resolve(objectList);
228
- } catch (err) {
229
- reject(JSON.stringify(err));
230
- }
231
- });
232
- },
102
+ }
233
103
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "node-red-contrib-mobius-flow-base",
3
- "version": "2.5.86-beta.74",
3
+ "version": "2.5.86-beta.78",
4
4
  "description": "Node-RED base nodes for Mobius Flow",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "mkdir -p dist/nodes && cp src/nodes/*.js dist/nodes/ && cp src/nodes/*.html dist/nodes/ && cp -r src/nodes/icons dist/nodes/ && mkdir -p dist/nodes/common && cp src/nodes/common/*.js dist/nodes/common/"
9
+ "build": "mkdir -p dist/nodes && cp src/nodes/*.js dist/nodes/ && cp src/nodes/*.html dist/nodes/ && cp -r src/nodes/icons dist/nodes/"
10
10
  },
11
11
  "repository": "bitbucket:interiorautomation/node-red-contrib-mobius-flow-base",
12
12
  "node-red": {