iobroker.zigbee 1.7.6 → 1.8.0
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/LICENSE +21 -21
- package/README.md +368 -381
- package/admin/admin.js +2951 -2927
- package/admin/i18n/de/translations.json +108 -0
- package/admin/i18n/en/translations.json +108 -0
- package/admin/i18n/es/translations.json +102 -0
- package/admin/i18n/fr/translations.json +108 -0
- package/admin/i18n/it/translations.json +102 -0
- package/admin/i18n/nl/translations.json +108 -0
- package/admin/i18n/pl/translations.json +108 -0
- package/admin/i18n/pt/translations.json +102 -0
- package/admin/i18n/ru/translations.json +108 -0
- package/admin/i18n/uk/translations.json +108 -0
- package/admin/i18n/zh-cn/translations.json +102 -0
- package/admin/img/philips_hue_lom001.png +0 -0
- package/admin/index.html +159 -159
- package/admin/index_m.html +1161 -1161
- package/admin/moment.min.js +1 -1
- package/admin/shuffle.min.js +2 -2
- package/admin/tab_m.html +985 -944
- package/admin/vis-network.min.css +1 -1
- package/admin/vis-network.min.js +27 -27
- package/admin/words.js +110 -110
- 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 +27 -0
- 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 +30 -0
- package/docs/flashing_via_arduino_(en).md +110 -0
- 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 +28 -0
- 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/io-package.json +335 -370
- package/lib/backup.js +171 -171
- package/lib/binding.js +324 -325
- package/lib/colors.js +462 -460
- package/lib/commands.js +508 -501
- package/lib/developer.js +147 -148
- package/lib/devices.js +3136 -3145
- package/lib/exclude.js +162 -168
- package/lib/exposes.js +799 -804
- package/lib/groups.js +341 -342
- package/lib/json.js +59 -60
- package/lib/networkmap.js +56 -56
- package/lib/ota.js +187 -179
- package/lib/rgb.js +258 -255
- package/lib/seriallist.js +48 -37
- package/lib/states.js +6406 -6416
- package/lib/statescontroller.js +676 -670
- package/lib/tools.js +54 -54
- package/lib/utils.js +152 -151
- package/lib/zbBaseExtension.js +36 -36
- package/lib/zbDelayedAction.js +144 -152
- package/lib/zbDeviceAvailability.js +318 -315
- package/lib/zbDeviceConfigure.js +147 -159
- package/lib/zbDeviceEvent.js +48 -49
- package/lib/zigbeecontroller.js +943 -951
- package/main.js +149 -133
- package/package.json +33 -19
- package/support/docgen.js +93 -93
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -37
- package/.github/FUNDING.yml +0 -3
- package/.github/stale.yml +0 -13
- package/.github/workflows/test-and-release.yml +0 -151
- package/.travis/wiki.sh +0 -28
- package/admin/adapter-settings.js +0 -244
package/lib/binding.js
CHANGED
|
@@ -1,325 +1,324 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const safeJsonStringify = require('./json');
|
|
4
|
-
|
|
5
|
-
// 5 - genScenes, 6 - genOnOff, 8 - genLevelCtrl, 768 - lightingColorCtrl
|
|
6
|
-
const allowClusters = [5, 6, 8, 768];
|
|
7
|
-
const allowClustersName = {5: 'genScenes', 6: 'genOnOff', 8: 'genLevelCtrl', 768: 'lightingColorCtrl'};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Binding {
|
|
11
|
-
constructor(adapter) {
|
|
12
|
-
this.adapter = adapter;
|
|
13
|
-
this.adapter.on('message', this.onMessage.bind(this));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
start(zbController, stController) {
|
|
17
|
-
this.zbController = zbController;
|
|
18
|
-
this.stController = stController;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
stop() {
|
|
22
|
-
delete this.zbController;
|
|
23
|
-
delete this.stController;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
info(msg) {
|
|
27
|
-
this.adapter.log.info(msg);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
error(msg) {
|
|
31
|
-
this.adapter.log.error(msg);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
debug(msg) {
|
|
35
|
-
this.adapter.log.debug(msg);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
warn(msg) {
|
|
39
|
-
this.adapter.log.warn(msg);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {ioBroker.Message} obj
|
|
44
|
-
*/
|
|
45
|
-
onMessage(obj) {
|
|
46
|
-
if (typeof obj === 'object' && obj.command) {
|
|
47
|
-
switch (obj.command) {
|
|
48
|
-
case 'addBinding':
|
|
49
|
-
if (obj && obj.message && typeof obj.message === 'object') {
|
|
50
|
-
this.addBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
51
|
-
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
case 'editBinding':
|
|
56
|
-
if (obj && obj.message && typeof obj.message === 'object') {
|
|
57
|
-
this.editBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
58
|
-
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case 'getBinding':
|
|
63
|
-
if (obj && obj.message && typeof obj.message === 'object') {
|
|
64
|
-
this.getBinding((binding)=>{
|
|
65
|
-
this.adapter.sendTo(obj.from, obj.command, binding, obj.callback);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
case 'delBinding':
|
|
70
|
-
if (obj && obj.message) {
|
|
71
|
-
this.delBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
72
|
-
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
extractBindId(stateId) {
|
|
81
|
-
return stateId.replace(`${this.adapter.namespace}.info.`, '');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
getBindingId(bind_source, bind_source_ep, bind_target, bind_target_ep) {
|
|
85
|
-
return `bind_${this.extractDeviceId(bind_source)}_${bind_source_ep}_${this.extractDeviceId(bind_target)}_${bind_target_ep}`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
extractDeviceId(stateId) {
|
|
89
|
-
if (stateId)
|
|
90
|
-
return stateId.replace(`${this.adapter.namespace}.`, '');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.debug(`
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
} else {
|
|
150
|
-
let ok = true;
|
|
151
|
-
for (const clID of clusters) {
|
|
152
|
-
const cluster = allowClustersName[clID];
|
|
153
|
-
const targetValid = target.type === 'group' ||
|
|
154
|
-
target.device.type === 'Coordinator' || target.endpoint.supportsInputCluster(cluster);
|
|
155
|
-
|
|
156
|
-
if (source.endpoint.supportsOutputCluster(cluster) && targetValid) {
|
|
157
|
-
this.debug(`${type}ing cluster '${cluster}' from '${sourceName}' to '${targetName}'`);
|
|
158
|
-
try {
|
|
159
|
-
const bindTarget = target.type === 'group' ? target.group : target.endpoint;
|
|
160
|
-
if (type === 'bind') {
|
|
161
|
-
await source.endpoint.bind(cluster, bindTarget);
|
|
162
|
-
} else {
|
|
163
|
-
await source.endpoint.unbind(cluster, bindTarget);
|
|
164
|
-
}
|
|
165
|
-
this.info(
|
|
166
|
-
`Successfully ${type === 'bind' ? 'bound' : 'unbound'} cluster '${cluster}' from ` +
|
|
167
|
-
`'${sourceName}' to '${targetName}'`,
|
|
168
|
-
);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
this.error(
|
|
171
|
-
`Failed to ${type} cluster '${cluster}' from '${sourceName}' to ` +
|
|
172
|
-
`'${targetName}' (${error})`,
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
ok = false;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
this.error(`Failed to doBindUnbind ${error.stack}`);
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async addBinding(from, command, params, callback) {
|
|
189
|
-
try {
|
|
190
|
-
this.debug(
|
|
191
|
-
const bind_source = params.bind_source,
|
|
192
|
-
bind_source_ep = params.bind_source_ep,
|
|
193
|
-
bind_target = params.bind_target,
|
|
194
|
-
bind_target_ep = params.bind_target_ep;
|
|
195
|
-
|
|
196
|
-
if (params.unbind_from_coordinator) {
|
|
197
|
-
await this.doBindUnbind('unbind', bind_source, bind_source_ep, 'coordinator', '1');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
await this.doBindUnbind('bind', bind_source, bind_source_ep, bind_target, bind_target_ep, (err, id) => {
|
|
201
|
-
if (err) {
|
|
202
|
-
callback({error: err});
|
|
203
|
-
} else {
|
|
204
|
-
const stateId = `info.${id}`;
|
|
205
|
-
// now set state
|
|
206
|
-
this.adapter.setObjectNotExists(stateId, {
|
|
207
|
-
type: 'state',
|
|
208
|
-
common: {name: id},
|
|
209
|
-
}, () => {
|
|
210
|
-
this.adapter.setState(stateId, JSON.stringify(params), true, () =>
|
|
211
|
-
callback();
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
module.exports = Binding;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const safeJsonStringify = require('./json');
|
|
4
|
+
|
|
5
|
+
// 5 - genScenes, 6 - genOnOff, 8 - genLevelCtrl, 768 - lightingColorCtrl
|
|
6
|
+
const allowClusters = [5, 6, 8, 768];
|
|
7
|
+
const allowClustersName = {5: 'genScenes', 6: 'genOnOff', 8: 'genLevelCtrl', 768: 'lightingColorCtrl'};
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Binding {
|
|
11
|
+
constructor(adapter) {
|
|
12
|
+
this.adapter = adapter;
|
|
13
|
+
this.adapter.on('message', this.onMessage.bind(this));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
start(zbController, stController) {
|
|
17
|
+
this.zbController = zbController;
|
|
18
|
+
this.stController = stController;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
stop() {
|
|
22
|
+
delete this.zbController;
|
|
23
|
+
delete this.stController;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
info(msg) {
|
|
27
|
+
this.adapter.log.info(msg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
error(msg) {
|
|
31
|
+
this.adapter.log.error(msg);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
debug(msg) {
|
|
35
|
+
this.adapter.log.debug(msg);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
warn(msg) {
|
|
39
|
+
this.adapter.log.warn(msg);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {ioBroker.Message} obj
|
|
44
|
+
*/
|
|
45
|
+
onMessage(obj) {
|
|
46
|
+
if (typeof obj === 'object' && obj.command) {
|
|
47
|
+
switch (obj.command) {
|
|
48
|
+
case 'addBinding':
|
|
49
|
+
if (obj && obj.message && typeof obj.message === 'object') {
|
|
50
|
+
this.addBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
51
|
+
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'editBinding':
|
|
56
|
+
if (obj && obj.message && typeof obj.message === 'object') {
|
|
57
|
+
this.editBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
58
|
+
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case 'getBinding':
|
|
63
|
+
if (obj && obj.message && typeof obj.message === 'object') {
|
|
64
|
+
this.getBinding((binding)=>{
|
|
65
|
+
this.adapter.sendTo(obj.from, obj.command, binding, obj.callback);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'delBinding':
|
|
70
|
+
if (obj && obj.message) {
|
|
71
|
+
this.delBinding(obj.from, obj.command, obj.message, (err)=>{
|
|
72
|
+
this.adapter.sendTo(obj.from, obj.command, err, obj.callback);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
extractBindId(stateId) {
|
|
81
|
+
return stateId.replace(`${this.adapter.namespace}.info.`, '');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getBindingId(bind_source, bind_source_ep, bind_target, bind_target_ep) {
|
|
85
|
+
return `bind_${this.extractDeviceId(bind_source)}_${bind_source_ep}_${this.extractDeviceId(bind_target)}_${bind_target_ep}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
extractDeviceId(stateId) {
|
|
89
|
+
if (stateId) {
|
|
90
|
+
return stateId.replace(`${this.adapter.namespace}.`, '');
|
|
91
|
+
}
|
|
92
|
+
return '';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getBindEp(ep) {
|
|
96
|
+
if (ep) {
|
|
97
|
+
return parseInt(ep.split('_')[0]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.warn(`getBindEp called with illegal ep: ${safeJsonStringify(ep)}`);
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getBindCl(ep) {
|
|
105
|
+
return ep.indexOf('_') > 0 ? ep.split('_')[1] : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async doBindUnbind(type, bind_source, bind_source_ep, bind_target, bind_target_ep, callback) {
|
|
109
|
+
try {
|
|
110
|
+
const id = this.getBindingId(bind_source, bind_source_ep, bind_target, bind_target_ep);
|
|
111
|
+
|
|
112
|
+
const source = await this.zbController.resolveEntity(`0x${this.extractDeviceId(bind_source)}`, this.getBindEp(bind_source_ep));
|
|
113
|
+
this.debug(`source: ${safeJsonStringify(source)}`);
|
|
114
|
+
let target = await this.zbController.resolveEntity(`0x${this.extractDeviceId(bind_target)}`, this.getBindEp(bind_target_ep));
|
|
115
|
+
this.debug(`target: ${safeJsonStringify(target)}`);
|
|
116
|
+
if (!target) {
|
|
117
|
+
if (bind_target === 'coordinator') {
|
|
118
|
+
target = await this.zbController.resolveEntity(bind_target);
|
|
119
|
+
this.debug(`Coordinator target: ${safeJsonStringify(target)}`);
|
|
120
|
+
} else {
|
|
121
|
+
target = await this.zbController.resolveEntity(parseInt(bind_target));
|
|
122
|
+
this.debug(`Group target: ${safeJsonStringify(target)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!source || !target) {
|
|
127
|
+
this.error('Devices not found');
|
|
128
|
+
return callback && callback('Devices not found');
|
|
129
|
+
}
|
|
130
|
+
const sourceName = source.name;
|
|
131
|
+
const targetName = target.name;
|
|
132
|
+
let found = false;
|
|
133
|
+
const bindCluster = this.getBindCl(bind_source_ep);
|
|
134
|
+
const clusters = bindCluster ? [bindCluster] : allowClusters;
|
|
135
|
+
// Find which clusters are supported by both the source and target.
|
|
136
|
+
// Groups are assumed to support all clusters.
|
|
137
|
+
for (const clID of clusters) {
|
|
138
|
+
const cluster = allowClustersName[clID];
|
|
139
|
+
const targetValid = target.type === 'group' ||
|
|
140
|
+
target.device.type === 'Coordinator' || target.endpoint.supportsInputCluster(cluster);
|
|
141
|
+
|
|
142
|
+
if (source.endpoint.supportsOutputCluster(cluster) && targetValid) {
|
|
143
|
+
found = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!found) {
|
|
147
|
+
this.debug(`No bind clusters`);
|
|
148
|
+
return callback && callback(`No bind clusters`);
|
|
149
|
+
} else {
|
|
150
|
+
let ok = true;
|
|
151
|
+
for (const clID of clusters) {
|
|
152
|
+
const cluster = allowClustersName[clID];
|
|
153
|
+
const targetValid = target.type === 'group' ||
|
|
154
|
+
target.device.type === 'Coordinator' || target.endpoint.supportsInputCluster(cluster);
|
|
155
|
+
|
|
156
|
+
if (source.endpoint.supportsOutputCluster(cluster) && targetValid) {
|
|
157
|
+
this.debug(`${type}ing cluster '${cluster}' from '${sourceName}' to '${targetName}'`);
|
|
158
|
+
try {
|
|
159
|
+
const bindTarget = target.type === 'group' ? target.group : target.endpoint;
|
|
160
|
+
if (type === 'bind') {
|
|
161
|
+
await source.endpoint.bind(cluster, bindTarget);
|
|
162
|
+
} else {
|
|
163
|
+
await source.endpoint.unbind(cluster, bindTarget);
|
|
164
|
+
}
|
|
165
|
+
this.info(
|
|
166
|
+
`Successfully ${type === 'bind' ? 'bound' : 'unbound'} cluster '${cluster}' from ` +
|
|
167
|
+
`'${sourceName}' to '${targetName}'`,
|
|
168
|
+
);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
this.error(
|
|
171
|
+
`Failed to ${type} cluster '${cluster}' from '${sourceName}' to ` +
|
|
172
|
+
`'${targetName}' (${error})`,
|
|
173
|
+
);
|
|
174
|
+
callback && callback(`Failed to ${type} cluster '${cluster}' from '${sourceName}' to '${targetName}' (${error})`);
|
|
175
|
+
ok = false;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
ok && callback && callback(undefined, id);
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
this.error(`Failed to doBindUnbind ${error.stack}`);
|
|
184
|
+
callback && callback(`Failed to doBindUnbind ${error.stack}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async addBinding(from, command, params, callback) {
|
|
189
|
+
try {
|
|
190
|
+
this.debug(`addBinding message: ${JSON.stringify(params)}`);
|
|
191
|
+
const bind_source = params.bind_source,
|
|
192
|
+
bind_source_ep = params.bind_source_ep,
|
|
193
|
+
bind_target = params.bind_target,
|
|
194
|
+
bind_target_ep = params.bind_target_ep;
|
|
195
|
+
|
|
196
|
+
if (params.unbind_from_coordinator) {
|
|
197
|
+
await this.doBindUnbind('unbind', bind_source, bind_source_ep, 'coordinator', '1');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
await this.doBindUnbind('bind', bind_source, bind_source_ep, bind_target, bind_target_ep, (err, id) => {
|
|
201
|
+
if (err) {
|
|
202
|
+
callback({error: err});
|
|
203
|
+
} else {
|
|
204
|
+
const stateId = `info.${id}`;
|
|
205
|
+
// now set state
|
|
206
|
+
this.adapter.setObjectNotExists(stateId, {
|
|
207
|
+
type: 'state',
|
|
208
|
+
common: {name: id},
|
|
209
|
+
}, () => {
|
|
210
|
+
this.adapter.setState(stateId, JSON.stringify(params), true, () =>
|
|
211
|
+
callback());
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
this.error(`Failed to addBinding ${error.stack}`);
|
|
217
|
+
throw new Error(`Failed to addBinding ${error.stack}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async editBinding(from, command, params, callback) {
|
|
222
|
+
try {
|
|
223
|
+
this.debug(`editBinding message: ${JSON.stringify(params)}`);
|
|
224
|
+
const old_id = params.id,
|
|
225
|
+
bind_source = params.bind_source,
|
|
226
|
+
bind_source_ep = params.bind_source_ep,
|
|
227
|
+
bind_target = params.bind_target,
|
|
228
|
+
bind_target_ep = params.bind_target_ep,
|
|
229
|
+
id = this.getBindingId(bind_source, bind_source_ep, bind_target, bind_target_ep);
|
|
230
|
+
if (old_id !== id) {
|
|
231
|
+
await this.delBinding(from, command, old_id, async err => {
|
|
232
|
+
if (err) {
|
|
233
|
+
callback(err);
|
|
234
|
+
} else {
|
|
235
|
+
await this.addBinding(from, command, params, callback);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
const type = params.unbind_from_coordinator ? 'unbind' : 'bind';
|
|
240
|
+
try {
|
|
241
|
+
await this.doBindUnbind(type , bind_source, bind_source_ep, 'coordinator', '1');
|
|
242
|
+
this.debug('Successfully ' + (type === 'bind' ? 'bound' : 'unbound') + ' Coordinator from ' + bind_source);
|
|
243
|
+
} catch (e) {
|
|
244
|
+
this.error(`Could not ${type} Coordinator from ${bind_source}: ${JSON.stringify(e)}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} catch (error) {
|
|
248
|
+
this.error(`Failed to editBinding ${error.stack}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async delBinding(from, command, bind_id, callback) {
|
|
253
|
+
try {
|
|
254
|
+
this.debug(`delBinding message: ${JSON.stringify(bind_id)}`);
|
|
255
|
+
const stateId = `info.${bind_id}`;
|
|
256
|
+
this.adapter.getStateAsync(stateId)
|
|
257
|
+
.then(async stateV => {
|
|
258
|
+
this.debug(`found state: ${JSON.stringify(stateV)}`);
|
|
259
|
+
const params = JSON.parse(stateV.val);
|
|
260
|
+
const bind_source = params.bind_source,
|
|
261
|
+
bind_source_ep = params.bind_source_ep,
|
|
262
|
+
bind_target = params.bind_target,
|
|
263
|
+
bind_target_ep = params.bind_target_ep;
|
|
264
|
+
await this.doBindUnbind('unbind', bind_source, bind_source_ep, bind_target, bind_target_ep, async err => {
|
|
265
|
+
if (err) {
|
|
266
|
+
callback({error: err});
|
|
267
|
+
} else {
|
|
268
|
+
this.adapter.deleteState(null, 'info', bind_id, async () => {
|
|
269
|
+
// if (err) {
|
|
270
|
+
// callback({error: err});
|
|
271
|
+
// } else {
|
|
272
|
+
if (params.unbind_from_coordinator) {
|
|
273
|
+
await this.doBindUnbind('bind', bind_source, bind_source_ep, 'coordinator', '1', callback);
|
|
274
|
+
} else {
|
|
275
|
+
callback();
|
|
276
|
+
}
|
|
277
|
+
//}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
} catch (error) {
|
|
283
|
+
this.error(`Failed to delBinding ${error.stack}`);
|
|
284
|
+
throw new Error(`Failed to delBinding ${error.stack}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
getBinding(callback) {
|
|
289
|
+
try {
|
|
290
|
+
const binding = [];
|
|
291
|
+
this.adapter.getStatesOf('info', (err, states) => {
|
|
292
|
+
if (!err && states) {
|
|
293
|
+
const chain = [];
|
|
294
|
+
states.forEach(state => {
|
|
295
|
+
if (state._id.startsWith(`${this.adapter.namespace}.info.bind_`)) {
|
|
296
|
+
chain.push(new Promise(resolve => {
|
|
297
|
+
return this.adapter.getStateAsync(state._id)
|
|
298
|
+
.then(stateV => {
|
|
299
|
+
if (stateV !== null) {
|
|
300
|
+
const val = JSON.parse(stateV.val);
|
|
301
|
+
val.id = this.extractBindId(state._id);
|
|
302
|
+
binding.push(val);
|
|
303
|
+
}
|
|
304
|
+
resolve();
|
|
305
|
+
});
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
return Promise.all(chain).then(() => {
|
|
310
|
+
this.debug(`getBinding result: ${JSON.stringify(binding)}`);
|
|
311
|
+
callback(binding);
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
this.debug(`getBinding result: ${JSON.stringify(binding)}`);
|
|
315
|
+
callback(binding);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
} catch (error) {
|
|
319
|
+
this.error(`Failed to getBinding ${error.stack}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
module.exports = Binding;
|