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.
- package/.eslintignore +2 -0
- package/.eslintrc.json +37 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/auto-merge.yml +17 -0
- package/.github/dependabot.yml +24 -0
- package/.github/stale.yml +13 -0
- package/.github/workflows/codeql.yml +41 -0
- package/.github/workflows/dependabot-automerge.yml +22 -0
- package/.github/workflows/test-and-release.yml +149 -0
- package/.releaseconfig.json +3 -0
- package/.travis/wiki.sh +28 -0
- package/.travis.yml +41 -0
- package/README.md +31 -8
- package/admin/admin.js +466 -482
- package/admin/i18n/de/translations.json +2 -2
- package/admin/index_m.html +1 -1
- package/admin/tab_m.html +3 -44
- package/admin/words.js +2 -2
- package/gulpfile.js +464 -0
- package/io-package.json +18 -25
- package/lib/backup.js +2 -2
- package/lib/binding.js +37 -32
- package/lib/colors.js +158 -163
- package/lib/commands.js +90 -99
- package/lib/developer.js +12 -9
- package/lib/devices.js +179 -169
- package/lib/exclude.js +36 -30
- package/lib/exposes.js +139 -163
- package/lib/groups.js +83 -81
- package/lib/json.js +6 -5
- package/lib/networkmap.js +3 -2
- package/lib/ota.js +18 -34
- package/lib/rgb.js +72 -114
- package/lib/seriallist.js +20 -25
- package/lib/states.js +526 -511
- package/lib/statescontroller.js +183 -206
- package/lib/utils.js +23 -24
- package/lib/zbBaseExtension.js +4 -4
- package/lib/zbDelayedAction.js +13 -5
- package/lib/zbDeviceAvailability.js +65 -69
- package/lib/zbDeviceConfigure.js +21 -9
- package/lib/zbDeviceEvent.js +4 -3
- package/lib/zigbeecontroller.js +103 -109
- package/main.js +147 -163
- package/package.json +15 -29
- package/test/integration.js +5 -0
- package/test/mocha.custom.opts +2 -0
- package/test/mocha.setup.js +14 -0
- package/test/package.js +5 -0
- package/test/unit.js +5 -0
- package/docs/de/img/CC2531.png +0 -0
- package/docs/de/img/CC2538_CC2592_PA.PNG +0 -0
- package/docs/de/img/CC2591.png +0 -0
- package/docs/de/img/boards.jpg +0 -0
- package/docs/de/img/cc26x2r.PNG +0 -0
- package/docs/de/img/results.jpg +0 -0
- package/docs/de/img/sku_429478_2.png +0 -0
- package/docs/de/img/sku_429601_2.png +0 -0
- package/docs/de/readme.md +0 -27
- package/docs/en/img/CC2531.png +0 -0
- package/docs/en/img/CC2591.png +0 -0
- package/docs/en/img/deconz.png +0 -0
- package/docs/en/img/sku_429478_2.png +0 -0
- package/docs/en/img/sku_429601_2.png +0 -0
- package/docs/en/readme.md +0 -30
- package/docs/flashing_via_arduino_(en).md +0 -110
- package/docs/ru/img/CC2531.png +0 -0
- package/docs/ru/img/CC2591.png +0 -0
- package/docs/ru/img/sku_429478_2.png +0 -0
- package/docs/ru/img/sku_429601_2.png +0 -0
- package/docs/ru/readme.md +0 -28
- package/docs/tutorial/CC2530_20190425.zip +0 -0
- package/docs/tutorial/CC2530_CC2591_20190515.zip +0 -0
- package/docs/tutorial/CC2530_CC2592_20190515.zip +0 -0
- package/docs/tutorial/CC2531_20190425.zip +0 -0
- package/docs/tutorial/adm5_1.PNG +0 -0
- package/docs/tutorial/adm5_2.PNG +0 -0
- package/docs/tutorial/cat.PNG +0 -0
- package/docs/tutorial/groups-1.png +0 -0
- package/docs/tutorial/groups-2.png +0 -0
- package/docs/tutorial/inst.PNG +0 -0
- package/docs/tutorial/reflash-finish.PNG +0 -0
- package/docs/tutorial/reflash-step0.png +0 -0
- package/docs/tutorial/reflash-step1.PNG +0 -0
- package/docs/tutorial/reflash-step2.PNG +0 -0
- package/docs/tutorial/settings.png +0 -0
- package/docs/tutorial/tab-dev-1.png +0 -0
- package/docs/tutorial/zigbee.png +0 -0
- 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
|
-
|
|
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
|
-
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
84
|
return undefined;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
} catch (error) {
|
|
88
|
-
if (error) this.error(
|
|
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
|
-
|
|
97
|
+
// const groupsState = await this.adapter.getStateAsync('info.groups');
|
|
98
98
|
const herdsmanGroups = await this.zbController.getGroups();
|
|
99
99
|
|
|
100
|
-
|
|
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]
|
|
107
|
+
groups[gid]=this.stController.verifyDeviceName(`group_${gid}`,`Group ${gid}`);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
this.debug(
|
|
111
|
+
this.debug('getGroups result: ' + JSON.stringify(groups));
|
|
112
112
|
response.groups = groups;
|
|
113
|
-
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
114
115
|
response.error = `getGroups: caught error: ${error}`;
|
|
115
116
|
this.error(`getGroups: caught error: ${error}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
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
|
-
|
|
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(
|
|
147
|
+
this.error("remove dev from group Error: "+ JSON.stringify(response.error));
|
|
144
148
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
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(
|
|
154
|
+
this.error("add dev to group Error: "+ JSON.stringify(response.error));
|
|
150
155
|
}
|
|
151
|
-
|
|
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(
|
|
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
|
|
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
|
|
199
|
-
this.warn(
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
234
|
-
|
|
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
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
246
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
}
|
|
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.
|
|
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
|
|
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(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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(
|
|
81
|
-
const lqi = await this.adapter.getStateAsync(
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
133
|
-
|
|
116
|
+
this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
|
|
117
|
+
return;
|
|
134
118
|
}
|
|
135
|
-
const availablestate = await this.adapter.getStateAsync(
|
|
136
|
-
const lqi = await this.adapter.getStateAsync(
|
|
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
|
-
|
|
139
|
-
|
|
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 '
|
|
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}'
|
|
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) {
|