iobroker.zigbee 1.8.1 → 1.8.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.
Files changed (89) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +37 -0
  3. package/.github/FUNDING.yml +3 -0
  4. package/.github/auto-merge.yml +17 -0
  5. package/.github/dependabot.yml +24 -0
  6. package/.github/stale.yml +13 -0
  7. package/.github/workflows/codeql.yml +41 -0
  8. package/.github/workflows/dependabot-automerge.yml +22 -0
  9. package/.github/workflows/test-and-release.yml +149 -0
  10. package/.releaseconfig.json +3 -0
  11. package/.travis/wiki.sh +28 -0
  12. package/.travis.yml +41 -0
  13. package/README.md +31 -8
  14. package/admin/admin.js +466 -482
  15. package/admin/i18n/de/translations.json +2 -2
  16. package/admin/index_m.html +1 -1
  17. package/admin/tab_m.html +3 -44
  18. package/admin/words.js +2 -2
  19. package/gulpfile.js +464 -0
  20. package/io-package.json +18 -25
  21. package/lib/backup.js +2 -2
  22. package/lib/binding.js +37 -32
  23. package/lib/colors.js +158 -163
  24. package/lib/commands.js +90 -99
  25. package/lib/developer.js +12 -9
  26. package/lib/devices.js +179 -169
  27. package/lib/exclude.js +36 -30
  28. package/lib/exposes.js +139 -163
  29. package/lib/groups.js +83 -81
  30. package/lib/json.js +6 -5
  31. package/lib/networkmap.js +3 -2
  32. package/lib/ota.js +18 -34
  33. package/lib/rgb.js +72 -114
  34. package/lib/seriallist.js +20 -25
  35. package/lib/states.js +526 -511
  36. package/lib/statescontroller.js +183 -206
  37. package/lib/utils.js +23 -24
  38. package/lib/zbBaseExtension.js +4 -4
  39. package/lib/zbDelayedAction.js +13 -5
  40. package/lib/zbDeviceAvailability.js +65 -69
  41. package/lib/zbDeviceConfigure.js +21 -9
  42. package/lib/zbDeviceEvent.js +4 -3
  43. package/lib/zigbeecontroller.js +103 -109
  44. package/main.js +147 -163
  45. package/package.json +15 -29
  46. package/test/integration.js +5 -0
  47. package/test/mocha.custom.opts +2 -0
  48. package/test/mocha.setup.js +14 -0
  49. package/test/package.js +5 -0
  50. package/test/unit.js +5 -0
  51. package/docs/de/img/CC2531.png +0 -0
  52. package/docs/de/img/CC2538_CC2592_PA.PNG +0 -0
  53. package/docs/de/img/CC2591.png +0 -0
  54. package/docs/de/img/boards.jpg +0 -0
  55. package/docs/de/img/cc26x2r.PNG +0 -0
  56. package/docs/de/img/results.jpg +0 -0
  57. package/docs/de/img/sku_429478_2.png +0 -0
  58. package/docs/de/img/sku_429601_2.png +0 -0
  59. package/docs/de/readme.md +0 -27
  60. package/docs/en/img/CC2531.png +0 -0
  61. package/docs/en/img/CC2591.png +0 -0
  62. package/docs/en/img/deconz.png +0 -0
  63. package/docs/en/img/sku_429478_2.png +0 -0
  64. package/docs/en/img/sku_429601_2.png +0 -0
  65. package/docs/en/readme.md +0 -30
  66. package/docs/flashing_via_arduino_(en).md +0 -110
  67. package/docs/ru/img/CC2531.png +0 -0
  68. package/docs/ru/img/CC2591.png +0 -0
  69. package/docs/ru/img/sku_429478_2.png +0 -0
  70. package/docs/ru/img/sku_429601_2.png +0 -0
  71. package/docs/ru/readme.md +0 -28
  72. package/docs/tutorial/CC2530_20190425.zip +0 -0
  73. package/docs/tutorial/CC2530_CC2591_20190515.zip +0 -0
  74. package/docs/tutorial/CC2530_CC2592_20190515.zip +0 -0
  75. package/docs/tutorial/CC2531_20190425.zip +0 -0
  76. package/docs/tutorial/adm5_1.PNG +0 -0
  77. package/docs/tutorial/adm5_2.PNG +0 -0
  78. package/docs/tutorial/cat.PNG +0 -0
  79. package/docs/tutorial/groups-1.png +0 -0
  80. package/docs/tutorial/groups-2.png +0 -0
  81. package/docs/tutorial/inst.PNG +0 -0
  82. package/docs/tutorial/reflash-finish.PNG +0 -0
  83. package/docs/tutorial/reflash-step0.png +0 -0
  84. package/docs/tutorial/reflash-step1.PNG +0 -0
  85. package/docs/tutorial/reflash-step2.PNG +0 -0
  86. package/docs/tutorial/settings.png +0 -0
  87. package/docs/tutorial/tab-dev-1.png +0 -0
  88. package/docs/tutorial/zigbee.png +0 -0
  89. package/docs/tutorial/zigbee15.png +0 -0
package/lib/groups.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const statesMapping = require('./devices');
4
4
 
5
+
5
6
  class Groups {
6
7
  constructor(adapter) {
7
8
  this.adapter = adapter;
@@ -12,12 +13,12 @@ class Groups {
12
13
  this.zbController = zbController;
13
14
  this.stController = stController;
14
15
  this.adapter.getStateAsync('info.groups')
15
- .then(groupsState => {
16
+ .then((groupsState) => {
16
17
  const groups = (groupsState && groupsState.val) ? JSON.parse(groupsState.val) : {};
17
18
  for (const gid in groups) {
18
19
  stController.storeDeviceName(`group_${gid}`, groups[gid]);
19
20
  }
20
- // this.Adapter.deleteState('info.groups');
21
+ // this.Adapter.deleteState('info.groups');
21
22
  this.syncGroups();
22
23
  });
23
24
  }
@@ -76,53 +77,56 @@ class Groups {
76
77
  for (const member of groupmembers) {
77
78
  const nwk = member.deviceNetworkAddress;
78
79
  const device = this.zbController.getDeviceByNetworkAddress(nwk);
79
- if (device && device.ieeeAddr) {
80
- members.push({device: device.ieeeAddr});
81
- }
80
+ if (device && device.ieeeAddr) members.push( { device:device.ieeeAddr } );
82
81
  }
83
- } else {
82
+ }
83
+ else {
84
84
  return undefined;
85
85
  }
86
86
 
87
87
  } catch (error) {
88
- if (error) this.error(`getGroupMembersFromController: error is ${JSON.stringify(error)} ${JSON.stringify(new Error().stack)}`);
88
+ if (error) this.error('getGroupMembersFromController: error is ' + JSON.stringify(error) + ' ' + JSON.stringify(new Error().stack));
89
89
  else this.error('unidentifed error in getGroupMembersFromController');
90
90
  }
91
91
  return members;
92
92
  }
93
93
 
94
94
  async getGroups(obj) {
95
- const response = {groups: {}};
95
+ const response = { groups: {} };
96
96
  try {
97
- // const groupsState = await this.adapter.getStateAsync('info.groups');
97
+ // const groupsState = await this.adapter.getStateAsync('info.groups');
98
98
  const herdsmanGroups = await this.zbController.getGroups();
99
99
 
100
- // const groups = (groupsState && groupsState.val) ? JSON.parse(groupsState.val) : {};
100
+ // const groups = (groupsState && groupsState.val) ? JSON.parse(groupsState.val) : {};
101
101
 
102
102
  const groups = {};
103
103
  if (typeof herdsmanGroups === 'object') {
104
104
  for (const group of herdsmanGroups) {
105
105
  const gid = group.groupID;
106
106
  if (gid) {
107
- groups[gid] = this.stController.verifyDeviceName(`group_${gid}`, `Group ${gid}`);
107
+ groups[gid]=this.stController.verifyDeviceName(`group_${gid}`,`Group ${gid}`);
108
108
  }
109
109
  }
110
110
  }
111
- this.debug(`getGroups result: ${JSON.stringify(groups)}`);
111
+ this.debug('getGroups result: ' + JSON.stringify(groups));
112
112
  response.groups = groups;
113
- } catch (error) {
113
+ }
114
+ catch (error) {
114
115
  response.error = `getGroups: caught error: ${error}`;
115
116
  this.error(`getGroups: caught error: ${error}`);
116
- } finally {
117
- obj && this.adapter.sendTo(obj.from, obj.command, response, obj.callback);
117
+ }
118
+ finally {
119
+ if (obj)
120
+ this.adapter.sendTo(obj.from, obj.command, response, obj.callback);
121
+
118
122
  }
119
123
  return response.groups;
120
124
  }
121
125
 
122
126
  async updateGroupMembership(from, command, message, callback) {
123
127
  try {
124
- const groups = message && message.groups ? message.groups : {};
125
- const devId = message && message.id ? message.id : undefined;
128
+ const groups = (message && message.groups ? message.groups : {});
129
+ const devId = (message && message.id ? message.id : undefined);
126
130
  if (devId === undefined) {
127
131
  this.adapter.sendTo(from, command, {error: 'No device specified'}, callback);
128
132
  }
@@ -132,32 +136,33 @@ class Groups {
132
136
  // this.adapter.setState(id, JSON.stringify(groups), true);
133
137
 
134
138
  //const current = await this.zbController.getGroupMembersFromController(sysid);
135
- const errors = [];
139
+ const errors = []
136
140
  for (const epid in groups) {
137
141
  for (const gpid of groups[epid]) {
138
142
  const gpidn = parseInt(gpid);
139
143
  if (gpidn < 0) {
140
- const response = await this.zbController.removeDevFromGroup(sysid, (-gpidn), epid);
144
+ let response = await this.zbController.removeDevFromGroup(sysid,(-gpidn), epid);
141
145
  if (response && response.error) {
142
146
  errors.push(response.error);
143
- this.error(`remove dev from group Error: ${JSON.stringify(response.error)}`);
147
+ this.error("remove dev from group Error: "+ JSON.stringify(response.error));
144
148
  }
145
- } else if (gpidn > 0) {
146
- const response = await this.zbController.addDevToGroup(sysid, (gpidn), epid);
149
+ }
150
+ else if (gpidn > 0){
151
+ let response = await this.zbController.addDevToGroup(sysid,(gpidn), epid);
147
152
  if (response && response.error) {
148
153
  errors.push(response.error);
149
- this.error(`add dev to group Error: ${JSON.stringify(response.error)}`);
154
+ this.error("add dev to group Error: "+ JSON.stringify(response.error));
150
155
  }
151
- } else {
152
- this.warn('illegal group id 0');
156
+
153
157
  }
158
+ else this.warn('illegal group id 0');
154
159
  }
155
160
  }
156
161
  } catch (e) {
157
162
  this.adapter.sendTo(from, command, {error: e}, callback);
158
163
  return;
159
164
  }
160
- this.adapter.sendTo(from, command, {}, callback);
165
+ this.adapter.sendTo(from, command, { }, callback);
161
166
  }
162
167
 
163
168
 
@@ -169,13 +174,11 @@ class Groups {
169
174
  };
170
175
  for (const member of members) {
171
176
  const entity = await this.zbController.resolveEntity(member.device);
172
- if (!entity) {
173
- return false;
174
- }
177
+ if (!entity) return false;
175
178
  this.debug(`entity: ${JSON.stringify(entity)}`);
176
179
  const mappedModel = entity.mapped;
177
- this.debug(`Mapped Model: ${JSON.stringify(mappedModel)}`);
178
- const converter = mappedModel.toZigbee.find(c => c && (c.key.includes(stateDesc.prop) || c.key.includes(stateDesc.setattr) || c.key.includes(stateDesc.id)));
180
+ this.debug('Mapped Model: ' + JSON.stringify(mappedModel));
181
+ const converter = mappedModel.toZigbee.find((c) => c && (c.key.includes(stateDesc.prop) || c.key.includes(stateDesc.setattr) || c.key.includes(stateDesc.id)));
179
182
  if (!converter) {
180
183
  result.unsupported.push(member.device);
181
184
  continue;
@@ -188,62 +191,63 @@ class Groups {
188
191
  }
189
192
  }
190
193
  }
191
- if (result.unsupported.length > 0) {
194
+ if (result.unsupported.length>0) {
192
195
  const error = {
193
196
  code: 134,
194
197
  message: `unsupported ${stateDesc.id} change for group members ${result.unsupported.join()}`
195
198
  };
196
199
  throw error;
197
200
  }
198
- if (result.unread.length > 0) {
199
- this.warn(`unread ${stateDesc.id} change for group members ${JSON.stringify(result.unread)}`);
201
+ if (result.unread.length>0) {
202
+ this.warn('unread ' + stateDesc.id + ' change for group members ' + JSON.stringify(result.unread));
200
203
  }
201
204
  }
202
205
 
203
206
  async deleteGroup(from, command, message) {
204
- /*
205
- const members = await this.getGroupMembersFromController(parseInt(message));
206
- if (members && members.length) {
207
- for (const member of members) {
208
- const devName = member.device.substring(2);
209
- const groupEntry = this.adapter.getStateAsync(`${devName}.groups`);
210
- const memberarray = (groupEntry && groupEntry.val) ? JSON.parse(groupEntry.val) : [];
211
- const index = memberarray.indexOf(message.toString());
212
- if (index > -1) {
213
- memberarray.splice(index, 1);
214
- }
215
- if (memberarray.length > 0) {
216
- await this.adapter.setStateAsync(`${devName}.groups`, JSON.stringify(memberarray), true);
217
- }
218
- else {
219
- await this.adapter.setStateAsync(`${devName}.groups`, '', true);
220
- }
207
+ /*
208
+ const members = await this.getGroupMembersFromController(parseInt(message));
209
+ if (members && members.length) {
210
+ for (const member of members) {
211
+ const devName = member.device.substring(2);
212
+ const groupEntry = this.adapter.getStateAsync(`${devName}.groups`);
213
+ const memberarray = (groupEntry && groupEntry.val) ? JSON.parse(groupEntry.val) : [];
214
+ const index = memberarray.indexOf(message.toString());
215
+ if (index > -1) {
216
+ memberarray.splice(index, 1);
217
+ }
218
+ if (memberarray.length > 0) {
219
+ await this.adapter.setStateAsync(`${devName}.groups`, JSON.stringify(memberarray), true);
220
+ }
221
+ else {
222
+ await this.adapter.setStateAsync(`${devName}.groups`, '', true);
221
223
  }
222
224
  }
223
- const groupsEntry = await this.adapter.getStateAsync('info.groups');
224
- const objGroups = (groupsEntry && groupsEntry.val ? JSON.parse(groupsEntry.val) : {});
225
- delete objGroups[message.toString()];
226
- await this.adapter.setStateAsync('info.groups', JSON.stringify(objGroups), true);
227
- */
225
+ }
226
+ const groupsEntry = await this.adapter.getStateAsync('info.groups');
227
+ const objGroups = (groupsEntry && groupsEntry.val ? JSON.parse(groupsEntry.val) : {});
228
+ delete objGroups[message.toString()];
229
+ await this.adapter.setStateAsync('info.groups', JSON.stringify(objGroups), true);
230
+ */
228
231
  await this.zbController.removeGroupById(message);
229
232
  await this.stController.deleteDeviceStatesAsync(`group_${parseInt(message)}`);
230
233
  }
231
234
 
232
235
  async renameGroup(from, command, message) {
233
- // const groupsEntry = await this.adapter.getStateAsync('info.groups');
234
- // const objGroups = (groupsEntry && groupsEntry.val ? JSON.parse(groupsEntry.val) : {});
236
+
237
+ // const groupsEntry = await this.adapter.getStateAsync('info.groups');
238
+ // const objGroups = (groupsEntry && groupsEntry.val ? JSON.parse(groupsEntry.val) : {});
235
239
  const name = message.name;
236
240
  const id = `group_${message.id}`;
237
241
  this.stController.storeDeviceName(id, name);
238
242
  try {
239
- await this.zbController.verifyGroupExists(message.id);
240
- } catch (e) {
241
- if (e && e.hasOwnProperty('code')) {
242
- this.warn(`renameGroup caught error ${JSON.stringify(e.code)}`);
243
- }
243
+ await this.zbController.verifyGroupExists(message.id);
244
+ }
245
+ catch (e)
246
+ {
247
+ if (e && e.hasOwnProperty('code')) this.warn('renameGroup caught error ' + JSON.stringify(e.code));
244
248
  }
245
- // objGroups[message.id.toString()] = message.name;
246
- // await this.adapter.setStateAsync('info.groups', JSON.stringify(objGroups), true);
249
+ // objGroups[message.id.toString()] = message.name;
250
+ // await this.adapter.setStateAsync('info.groups', JSON.stringify(objGroups), true);
247
251
 
248
252
  const group = await this.adapter.getStateAsync(id);
249
253
  if (!group) {
@@ -251,14 +255,12 @@ class Groups {
251
255
  this.adapter.setObjectNotExists(id, {
252
256
  type: 'device',
253
257
  common: {name: name, type: 'group'},
254
- native: {id}
258
+ native: {id: id}
255
259
  }, () => {
256
- this.adapter.extendObject(id, {common: {name, type: 'group'}});
260
+ this.adapter.extendObject(id , {common: {name: name, type: 'group'}});
257
261
  // create writable states for groups from their devices
258
262
  for (const stateInd in statesMapping.groupStates) {
259
- if (!statesMapping.groupStates.hasOwnProperty(stateInd)) {
260
- continue;
261
- }
263
+ if (!statesMapping.groupStates.hasOwnProperty(stateInd)) continue;
262
264
  const statedesc = statesMapping.groupStates[stateInd];
263
265
  const common = {
264
266
  name: statedesc.name,
@@ -277,15 +279,16 @@ class Groups {
277
279
  }
278
280
  }
279
281
 
282
+
280
283
  async syncGroups() {
281
284
  const groups = await this.getGroups();
282
285
  const chain = [];
283
286
  const usedGroupsIds = [];
284
287
  for (const j in groups) {
285
288
  if (groups.hasOwnProperty(j)) {
286
- const id = `group_${j}`;
287
- const name = groups[j];
288
- chain.push(new Promise(resolve => {
289
+ const id = `group_${j}`,
290
+ name = groups[j];
291
+ chain.push(new Promise((resolve) => {
289
292
  this.adapter.setObjectNotExists(id, {
290
293
  type: 'device',
291
294
  common: {name: name, type: 'group'},
@@ -294,9 +297,7 @@ class Groups {
294
297
  this.adapter.extendObject(id, {common: {type: 'group'}});
295
298
  // create writable states for groups from their devices
296
299
  for (const stateInd in statesMapping.groupStates) {
297
- if (!statesMapping.groupStates.hasOwnProperty(stateInd)) {
298
- continue;
299
- }
300
+ if (!statesMapping.groupStates.hasOwnProperty(stateInd)) continue;
300
301
  const statedesc = statesMapping.groupStates[stateInd];
301
302
  const common = {
302
303
  name: statedesc.name,
@@ -317,8 +318,8 @@ class Groups {
317
318
  usedGroupsIds.push(parseInt(j));
318
319
  }
319
320
  }
320
- chain.push(new Promise(resolve =>
321
- // remove unused adapter groups
321
+ chain.push(new Promise((resolve) => {
322
+ // remove unused adpter groups
322
323
  this.adapter.getDevices((err, devices) => {
323
324
  if (!err) {
324
325
  devices.forEach((dev) => {
@@ -331,10 +332,11 @@ class Groups {
331
332
  });
332
333
  }
333
334
  resolve();
334
- })));
335
-
336
- await Promise.all(chain);
335
+ });
336
+ }));
337
+ Promise.all(chain);
337
338
  }
339
+
338
340
  }
339
341
 
340
342
  module.exports = Groups;
package/lib/json.js CHANGED
@@ -3,14 +3,15 @@
3
3
  const hasProp = Object.prototype.hasOwnProperty;
4
4
 
5
5
  function throwsMessage(err) {
6
- return `[Throws: ${err ? err.message : '?'}]`;
6
+ return '[Throws: ' + (err ? err.message : '?') + ']';
7
7
  }
8
8
 
9
9
  function safeGetValueFromPropertyOnObject(obj, property) {
10
10
  if (hasProp.call(obj, property)) {
11
11
  try {
12
12
  return obj[property];
13
- } catch (err) {
13
+ }
14
+ catch (err) {
14
15
  return throwsMessage(err);
15
16
  }
16
17
  }
@@ -19,14 +20,14 @@ function safeGetValueFromPropertyOnObject(obj, property) {
19
20
  }
20
21
 
21
22
  function ensureProperties(obj) {
22
- const seen = []; // store references to objects we have seen before
23
+ const seen = [ ]; // store references to objects we have seen before
23
24
 
24
25
  function visit(obj) {
25
26
  if (obj === null || typeof obj !== 'object') {
26
27
  return obj;
27
28
  }
28
29
 
29
- if (seen.includes(obj)) {
30
+ if (seen.indexOf(obj) !== -1) {
30
31
  return '[Circular]';
31
32
  }
32
33
  seen.push(obj);
@@ -34,7 +35,7 @@ function ensureProperties(obj) {
34
35
  if (typeof obj.toJSON === 'function') {
35
36
  try {
36
37
  return visit(obj.toJSON());
37
- } catch (err) {
38
+ } catch(err) {
38
39
  return throwsMessage(err);
39
40
  }
40
41
  }
package/lib/networkmap.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+
3
4
  class NetworkMap {
4
5
  constructor(adapter) {
5
6
  this.adapter = adapter;
@@ -45,8 +46,8 @@ class NetworkMap {
45
46
 
46
47
  getMap(from, command, callback) {
47
48
  if (this.zbController) {
48
- this.zbController.getMap(networkmap => {
49
- this.adapter.log.debug(`getMap result: ${JSON.stringify(networkmap)}`);
49
+ this.zbController.getMap((networkmap) => {
50
+ this.adapter.log.debug('getMap result: ' + JSON.stringify(networkmap));
50
51
  this.adapter.sendTo(from, command, networkmap, callback);
51
52
  });
52
53
  }
package/lib/ota.js CHANGED
@@ -55,11 +55,7 @@ class Ota {
55
55
  const device = await this.getDeviceForMessage(obj);
56
56
  if (!device) {
57
57
  this.debug(`Device ${obj.message.devId} is unavailable`);
58
- this.adapter.sendTo(obj.from, obj.command, {
59
- status: 'fail',
60
- device: getZbId(obj.message.devId),
61
- msg: 'Device is unavailable'
62
- }, obj.callback);
58
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
63
59
  return;
64
60
  }
65
61
  if (this.inProgress.has(device.device.ieeeAddr)) {
@@ -69,24 +65,16 @@ class Ota {
69
65
  // do not attempt update for a device which has been deactivated or is unavailable
70
66
  const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
71
67
  if (stateObj && stateObj.common && stateObj.common.deactivated) {
72
- this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
73
- this.adapter.sendTo(obj.from, obj.command, {
74
- status: 'fail',
75
- device: getZbId(obj.message.devId),
76
- msg: 'Device is deactivated'
77
- }, obj.callback);
78
- return;
68
+ this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
69
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is deactivated'}, obj.callback);
70
+ return;
79
71
  }
80
- const availablestate = await this.adapter.getStateAsync(`${obj.message.devId.replace(this.namespace + '.', '')}.available`);
81
- const lqi = await this.adapter.getStateAsync(`${obj.message.devId.replace(this.namespace + '.', '')}.link_quality`);
72
+ const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
73
+ const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
82
74
  if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
83
- this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
84
- this.adapter.sendTo(obj.from, obj.command, {
85
- status: 'fail',
86
- device: getZbId(obj.message.devId),
87
- msg: 'Device is marked unavailable'
88
- }, obj.callback);
89
- return;
75
+ this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
76
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is marked unavailable'}, obj.callback);
77
+ return;
90
78
  }
91
79
  this.inProgress.add(device.device.ieeeAddr);
92
80
  const result = {status: 'unknown', device: device ? device.name : null};
@@ -115,11 +103,7 @@ class Ota {
115
103
  const device = await this.getDeviceForMessage(obj);
116
104
  if (!device) {
117
105
  this.debug(`Device ${obj.message.devId} is unavailable`);
118
- this.adapter.sendTo(obj.from, obj.command, {
119
- status: 'fail',
120
- device: getZbId(obj.message.devId),
121
- msg: 'Device is unavailable'
122
- }, obj.callback);
106
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
123
107
  return;
124
108
  }
125
109
  if (this.inProgress.has(device.device.ieeeAddr)) {
@@ -129,19 +113,19 @@ class Ota {
129
113
  // do not attempt update for a device which has been deactivated or is unavailable
130
114
  const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
131
115
  if (stateObj && stateObj.common && stateObj.common.deactivated) {
132
- this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
133
- return;
116
+ this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
117
+ return;
134
118
  }
135
- const availablestate = await this.adapter.getStateAsync(`${obj.message.devId.replace(this.namespace + '.', '')}.available`);
136
- const lqi = await this.adapter.getStateAsync(`${obj.message.devId.replace(this.namespace + '.', '')}.link_quality`);
119
+ const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
120
+ const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
137
121
  if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
138
- this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
139
- return;
122
+ this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
123
+ return;
140
124
  }
141
125
  this.inProgress.add(device.device.ieeeAddr);
142
126
  const result = {status: 'unknown', device: device ? device.name : null};
143
127
  try {
144
- this.info('Start firmware update for ' + device.name);
128
+ this.info('Start firmware update for '+device.name);
145
129
 
146
130
  const onProgress = (progress, remaining) => {
147
131
  let message = `Update of '${device.name}' at ${progress}%`;
@@ -156,7 +140,7 @@ class Ota {
156
140
  const to = await this.readSoftwareBuildIDAndDateCode(device.device, true);
157
141
  const [fromS, toS] = [JSON.stringify(from_), JSON.stringify(to)];
158
142
  result.status = 'success';
159
- result.msg = `Finished update of '${device.name}'${to ? `, from '${fromS}' to '${toS}'` : ``}`;
143
+ result.msg = `Finished update of '${device.name}'` + (to ? `, from '${fromS}' to '${toS}'` : ``);
160
144
  this.info(result.msg);
161
145
  this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
162
146
  } catch (error) {