-
Notifications
You must be signed in to change notification settings - Fork 0
/
bosesoundtouch.js
671 lines (598 loc) · 25.9 KB
/
bosesoundtouch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/* jshint -W097 */
// jshint strict:false
/* jslint node: true */
/* jslint esversion: 6 */
'use strict';
const BOSE_ID_ON = 'on';
const BOSE_ID_KEY = 'key';
const BOSE_ID_VOLUME = 'volume';
const BOSE_ID_MUTED = 'muted';
const BOSE_ID_NOW_PLAYING = 'nowPlaying.';
const BOSE_ID_NOW_PLAYING_SOURCE = BOSE_ID_NOW_PLAYING + 'source';
const BOSE_ID_NOW_PLAYING_TRACK = BOSE_ID_NOW_PLAYING + 'track';
const BOSE_ID_NOW_PLAYING_ARTIST = BOSE_ID_NOW_PLAYING + 'artist';
const BOSE_ID_NOW_PLAYING_ALBUM = BOSE_ID_NOW_PLAYING + 'album';
const BOSE_ID_NOW_PLAYING_STATION = BOSE_ID_NOW_PLAYING + 'station';
const BOSE_ID_NOW_PLAYING_ART = BOSE_ID_NOW_PLAYING + 'art';
const BOSE_ID_NOW_PLAYING_GENRE = BOSE_ID_NOW_PLAYING + 'genre';
const BOSE_ID_PRESETS = 'presets.';
const BOSE_ID_PRESET_SOURCE = BOSE_ID_PRESETS + '{}.source';
const BOSE_ID_PRESET_NAME = BOSE_ID_PRESETS + '{}.name';
const BOSE_ID_PRESET_ICON = BOSE_ID_PRESETS + '{}.iconUrl';
const BOSE_ID_ZONES = 'zones.';
const BOSE_ID_ZONES_MEMBER_OF = BOSE_ID_ZONES + 'memberOf';
const BOSE_ID_ZONES_MASTER_OF = BOSE_ID_ZONES + 'masterOf';
const BOSE_ID_ZONES_ADD_MASTER_OF = BOSE_ID_ZONES + 'addMasterOf';
const BOSE_ID_ZONES_REMOVE_MASTER_OF = BOSE_ID_ZONES + 'removeMasterOf';
const BOSE_ID_ZONES_PLAY_EVERYWHERE = BOSE_ID_ZONES + 'playEverywhere';
const BOSE_ID_DEVICE_INFO = 'deviceInfo.';
const BOSE_ID_INFO_NAME = BOSE_ID_DEVICE_INFO + 'name';
const BOSE_ID_INFO_TYPE = BOSE_ID_DEVICE_INFO + 'type';
const BOSE_ID_INFO_MAC_ADDRESS = BOSE_ID_DEVICE_INFO + 'macAddress';
const BOSE_ID_INFO_IP_ADDRESS = BOSE_ID_DEVICE_INFO + 'ipAddress';
// you have to require the utils module and call adapter function
var format = require('string-format');
var utils = require(__dirname + '/lib/utils'); // Get common adapter utils
var soundtouchsocket = require(__dirname + '/soundtouchsocket');
//var bosestates = require(__dirname + '/bosestates');
// you have to call the adapter function and pass a options object
// name has to be set and has to be equal to adapters folder name and main file name excluding extension
// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0
class boseSoundTouch {
constructor() {
var instance = this;
this.adapter = utils.Adapter('bosesoundtouch');
// is called when adapter shuts down - callback has to be called under any circumstances!
this.adapter.on('unload', function(callback) { instance.onUnload(callback); });
// is called if a subscribed object changes
this.adapter.on('objectChange', function(id, obj) { instance.onObjectChange(id, obj); });
// is called if a subscribed state changes
this.adapter.on('stateChange', function (id, state) { instance.onStateChange(id, state); });
// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ...
this.adapter.on('message', function(obj) { instance.onMessage(obj); });
// is called when databases are connected and adapter received configuration.
// start here!
this.adapter.on('ready', function() { instance.onReady(); });
}
onUnload(callback) {
try {
this.adapter.log.info('cleaned everything up...');
callback();
}
catch (e) {
callback();
}
}
onObjectChange(id, obj) {
// Warning, obj can be null if it was deleted
this.adapter.log.debug('objectChange ' + id + ' ' + JSON.stringify(obj));
}
onStateChange(id, state) {
// Warning, state can be null if it was deleted
this.adapter.log.debug('stateChange ' + id + ' ' + JSON.stringify(state));
var namespace = this.adapter.namespace + '.';
// you can use the ack flag to detect if it is status (true) or command (false)
if (state && !state.ack) {
switch (id) {
case namespace + BOSE_ID_ON:
this.adapter.setState(BOSE_ID_KEY, 'POWER');
break;
case namespace + BOSE_ID_VOLUME:
this.socket.setValue('volume', '', state.val);
break;
case namespace + BOSE_ID_KEY:
this.socket.setValue('key', 'state="press" sender="Gabbo"', state.val);
this.socket.setValue('key', 'state="release" sender="Gabbo"', state.val);
break;
case namespace + BOSE_ID_MUTED:
this.adapter.setState(BOSE_ID_KEY, 'MUTE');
break;
case namespace + BOSE_ID_ZONES_ADD_MASTER_OF:
this.handleMasterOf(state.val, this.socket.addZoneSlave, true);
this.adapter.setState(BOSE_ID_ZONES_ADD_MASTER_OF, {val: '', ack: true});
break;
case namespace + BOSE_ID_ZONES_REMOVE_MASTER_OF:
this.handleMasterOf(state.val, this.socket.removeZoneSlave);
this.adapter.setState(BOSE_ID_ZONES_REMOVE_MASTER_OF, {val: '', ack: true});
break;
case namespace + BOSE_ID_ZONES_PLAY_EVERYWHERE:
if (state.val) {
this.setMasterOf();
this.adapter.setState(BOSE_ID_ZONES_PLAY_EVERYWHERE, false);
}
break;
}
this.adapter.log.debug('ack is not set!');
}
}
onMessage(obj) {
if (typeof obj == 'object' && obj.message) {
if (obj.command == 'send') {
// e.g. send email or pushover or whatever
adapter.log.debug('send command');
// Send response in callback if required
if (obj.callback) {
this.adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback);
}
}
}
}
onError() {
//this.adapter.log.error('error' + obj);
var instance = this;
var interval = this.adapter.config.reconnectTime * 1000;
if (interval > 0) {
this.reconnectInterval = setInterval(function() { instance._connect(); }, interval);
}
}
onReady() {
this.initObjects();
this.adapter.subscribeStates('*');
// in this template all states changes inside the adapters namespace are subscribed
this.socket = new soundtouchsocket(this.adapter);
this._connect();
}
_connect() {
this.adapter.log.debug('connect...');
clearInterval(this.reconnectInterval);
var instance = this;
this.socket.removeAllListeners();
this.socket.addListener('error', function() { instance.onError(); });
this.socket.connect().then( function(server) {
instance.socket.addListener('deviceInfo', function(obj) { instance.setDeviceInfo(obj); });
instance.socket.addListener('volume', function(obj) { instance.setVolume(obj); });
instance.socket.addListener('nowPlaying', function(obj) { instance.setNowPlaying(obj); });
instance.socket.addListener('presets', function(obj) { instance.setPresets(obj); });
instance.socket.addListener('zones', function(obj) { instance.setZone(obj); });
instance.socket.updateAll(server);
}).catch(function(err) {
// error here
instance.adapter.error(err);
});
}
initObjects() {
this.adapter.setObjectNotExists(BOSE_ID_KEY, {
type: 'state',
common: {
name: 'key',
type: 'string',
role: 'text',
read: false,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_VOLUME, {
type: 'state',
common: {
name: 'volume',
type: 'number',
role: 'level',
read: true,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_MUTED, {
type: 'state',
common: {
name: 'muted',
type: 'boolean',
role: 'indicator',
read: true,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ON, {
type: 'state',
common: {
name: 'on',
type: 'boolean',
role: 'indicator',
read: true,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ZONES_MEMBER_OF, {
type: 'state',
common: {
name: 'member of',
type: 'string',
role: 'text',
read: true,
write: false
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ZONES_MASTER_OF, {
type: 'state',
common: {
name: 'master of',
type: 'string',
role: 'text',
read: true,
write: false
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ZONES_ADD_MASTER_OF, {
type: 'state',
common: {
name: 'add master of',
type: 'string',
role: 'text',
read: true,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ZONES_REMOVE_MASTER_OF, {
type: 'state',
common: {
name: 'remove master of',
type: 'string',
role: 'text',
read: true,
write: true
},
native: {}
});
this.adapter.setObjectNotExists(BOSE_ID_ZONES_PLAY_EVERYWHERE, {
type: 'state',
common: {
name: 'play everywhere',
type: 'boolean',
read: true,
write: true
},
native: {}
});
const presetsConfig = {
type: 'state',
common: {
name: '',
type: 'string',
read: true,
write: false
},
native: {}
};
for (var i = 1; i <= 6; i++) {
presetsConfig.common.role = 'text';
this.adapter.setObjectNotExists(format(BOSE_ID_PRESET_SOURCE, i), presetsConfig);
this.adapter.setObjectNotExists(format(BOSE_ID_PRESET_NAME, i), presetsConfig);
presetsConfig.common.role = 'text.url';
this.adapter.setObjectNotExists(format(BOSE_ID_PRESET_ICON, i), presetsConfig);
}
const nowPlayingConfig = {
type: 'state',
common: {
name: '',
type: 'string',
role: 'text',
read: true,
write: false
},
native: {}
};
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_SOURCE, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_TRACK, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_ARTIST, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_ALBUM, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_STATION, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_ART, nowPlayingConfig);
this.adapter.setObjectNotExists(BOSE_ID_NOW_PLAYING_GENRE, nowPlayingConfig);
const deviceInfoConfig = {
type: 'state',
common: {
name: '',
type: 'string',
role: 'text',
read: true,
write: false
},
native: {}
};
this.adapter.setObjectNotExists(BOSE_ID_INFO_NAME, deviceInfoConfig);
this.adapter.setObjectNotExists(BOSE_ID_INFO_TYPE, deviceInfoConfig);
this.adapter.setObjectNotExists(BOSE_ID_INFO_MAC_ADDRESS, deviceInfoConfig);
this.adapter.setObjectNotExists(BOSE_ID_INFO_IP_ADDRESS, deviceInfoConfig);
}
setDeviceInfo(obj) {
this.adapter.setState(BOSE_ID_INFO_NAME, {val: obj.name, ack: true});
this.adapter.setState(BOSE_ID_INFO_TYPE, {val: obj.type, ack: true});
this.adapter.setState(BOSE_ID_INFO_MAC_ADDRESS, {val: obj.macAddress, ack: true});
this.adapter.setState(BOSE_ID_INFO_IP_ADDRESS, {val: this.adapter.config.address, ack:true});
this.adapter.ipAddress = this.adapter.config.address;
this.adapter.macAddress = obj.macAddress;
}
setVolume(obj) {
var actualVolume = obj.actualvolume;
var muted = (obj.muteenabled == 'true');
this.adapter.setState(BOSE_ID_VOLUME, {val: actualVolume, ack: true});
this.adapter.setState(BOSE_ID_MUTED, {val: muted, ack: true});
}
setNowPlaying(obj) {
this.adapter.setState(BOSE_ID_NOW_PLAYING_SOURCE, {val: obj.source, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_TRACK, {val: obj.track, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_ARTIST, {val: obj.artist, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_ALBUM, {val: obj.album, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_STATION, {val: obj.station, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_ART, {val: obj.art, ack: true});
this.adapter.setState(BOSE_ID_NOW_PLAYING_GENRE, {val: obj.genre, ack: true});
this.adapter.setState(BOSE_ID_ON, {val: (obj.source != 'STANDBY'), ack: true});
if (this.adapter.config.autoSync) {
this._checkSyncZones(obj);
}
}
_collectCheckSyncData(syncData, namespaceList, originNowPlaying) {
var instance = this;
if (syncData) {
if (syncData.length == 0) {
instance._collectCheckSyncFinished(namespaceList, originNowPlaying);
} else {
var namespace = syncData.shift();
this.adapter.getForeignStates(namespace + "*", function (err, deviceInfoData) {
if (err) {
instance.adapter.log.error(err);
} else {
namespaceList[namespace] = deviceInfoData
instance._collectCheckSyncData(syncData, namespaceList, originNowPlaying);
}
});
}
}
}
_sameStation(obj1, obj2) {
return (obj1.source === obj2.source && obj1.station === obj2.station);
}
_sameTrack(obj1, obj2) {
return (obj1.source === obj2.source && obj1.artist === obj2.artist && obj1.track === obj2.track);
}
_collectCheckSyncFinished(namespaceList, originNowPlaying) {
var instance = this;
let setMasterOf = [];
let existMaster = false;
Object.keys(namespaceList).forEach(key => {
const dataFromKey = namespaceList[key];
const syncNowPlaying = {
source: dataFromKey[key + BOSE_ID_NOW_PLAYING_SOURCE].val,
track: dataFromKey[key + BOSE_ID_NOW_PLAYING_TRACK].val,
artist: dataFromKey[key + BOSE_ID_NOW_PLAYING_ARTIST].val,
album: dataFromKey[key + BOSE_ID_NOW_PLAYING_ALBUM].val,
station: dataFromKey[key + BOSE_ID_NOW_PLAYING_STATION].val,
art: dataFromKey[key + BOSE_ID_NOW_PLAYING_ART].val,
genre: dataFromKey[key + BOSE_ID_NOW_PLAYING_GENRE].val
}
if (instance._sameStation(syncNowPlaying, originNowPlaying) | instance._sameTrack(syncNowPlaying, originNowPlaying)) {
const syncMasterOf = dataFromKey[key + BOSE_ID_ZONES_MASTER_OF].val;
if (!(syncMasterOf.split(';').some(masterData => masterData === instance.adapter.macAddress))) {
setMasterOf.push(dataFromKey[key + BOSE_ID_INFO_MAC_ADDRESS].val)
} else {
existMaster = true;
}
}
})
if (setMasterOf.length > 0 && !existMaster) {
instance.setMasterOf(setMasterOf.join(';'))
}
}
_checkSyncZones(originNowPlaying) {
if (originNowPlaying.source !== 'STANDBY') {
var instance = this;
this.adapter.objects.getObjectView(
'system', 'instance', {
startkey: 'system.adapter.bosesoundtouch.',
endkey: 'system.adapter.bosesoundtouch.\u9999'
},
function (err, doc) {
if (doc && doc.rows && doc.rows.length) {
var toDoList = [];
for (var i = 0; i < doc.rows.length; i++) {
var obj = doc.rows[i].value;
if (obj.native.address != instance.adapter.ipAddress) {
const systemId = doc.rows[i].id.split('.');
const index = systemId[systemId.length - 1];
const namespace = systemId[systemId.length - 2] + '.' + index + '.';
toDoList.push(namespace);
}
}
instance._collectCheckSyncData(toDoList, {}, originNowPlaying);
} else {
instance.adapter.log.debug('No objects found: ' + err);
}
});
}
}
setPresets(obj) {
//var presets = JSON.parse(data);
for (var i = 0; i < 6; i++) {
var preset = {
source: '',
name: '',
iconUrl: ''
};
if (obj[i]) {
preset = obj[i];
}
this.adapter.setState(format(BOSE_ID_PRESET_SOURCE, i+1), {val: preset.source, ack: true});
this.adapter.setState(format(BOSE_ID_PRESET_NAME, i+1), {val: preset.name, ack: true});
this.adapter.setState(format(BOSE_ID_PRESET_ICON, i+1), {val: preset.iconUrl, ack: true});
}
}
setZone(obj) {
if (!obj || obj === '') {
this.adapter.setState(BOSE_ID_ZONES_MEMBER_OF, {val: '', ack: true});
this.adapter.setState(BOSE_ID_ZONES_MASTER_OF, {val: '', ack: true});
}
else {
if (obj.master === this.adapter.macAddress) {
let members = [];
if (obj.member && obj.member.length > 0) {
obj.member.forEach(member => {
members.push(member._);
});
}
else {
members.push(obj.member._);
}
this.adapter.setState(BOSE_ID_ZONES_MASTER_OF, {val: members.join(';'), ack: true});
this.adapter.setState(BOSE_ID_ZONES_MEMBER_OF, {val: '', ack: true});
}
else {
this.adapter.setState(BOSE_ID_ZONES_MASTER_OF, {val: '', ack: true});
this.adapter.setState(BOSE_ID_ZONES_MEMBER_OF, {val: obj.master, ack: true});
}
}
}
_collectPlayEverywhereData(data, callback, filterList) {
var instance = this;
if (data) {
if (data.length == 0) {
callback(instance, filterList);
}
else {
var id = data.shift();
var slave = {};
slave.id = id;
this.adapter.getForeignState(id, function(err, state) {
if (err) {
instance.adapter.log.error(err);
}
else {
slave.value = state.val;
instance.masterSlaveData.slave.push(slave);
instance._collectPlayEverywhereData(data, callback, filterList);
}
});
}
}
}
_collectPlayEverywhereFinished(instance, filterList) {
var slaveList = [];
var items = instance.masterSlaveData.slave;
for (let index = 0; index < items.length; index += 2) {
var type = items[index].id.split('.');
type = type[type.length - 1];
if (type === 'ipAddress') {
var slave = {
ip: items[index].value,
mac: items[index +1].value
};
if (!filterList || filterList.find(filterMac => filterMac === slave.mac)) {
slaveList.push(slave);
}
}
}
instance.socket.createZone(instance.masterSlaveData.master, slaveList);
}
handleMasterOf(setMacAddresses, setZoneFunction, add) {
var instance = this;
instance.adapter.getState(BOSE_ID_ZONES_MASTER_OF, function(err, stateMasterOf) {
if (err) {
instance.adapter.log.error(err);
}
else {
if (stateMasterOf.val === '') {
if (add) {
instance.setMasterOf(setMacAddresses);
}
return;
}
else {
const masterOf = stateMasterOf.val.split(';');
if (add) {
const setSlaves = setMacAddresses.split(';').filter(setSlave => !masterOf.some(masterOfSlave => setSlave === masterOfSlave));
setSlaves.forEach(setSlave => instance._setZoneSlave(setSlave, setZoneFunction));
}
else {
const setSlaves = setMacAddresses.split(';').filter(setSlave => masterOf.some(masterOfSlave => setSlave === masterOfSlave));
setSlaves.forEach(setSlave => instance._setZoneSlave(setSlave, setZoneFunction));
}
}
}
});
}
_setZoneSlave(slaveMacAddress, setZoneFunction) {
var instance = this;
instance.masterSlaveData = {
master: {
ip: this.adapter.ipAddress,
mac: this.adapter.macAddress
},
slave: []
};
this.adapter.objects.getObjectView(
'system', 'instance', {
startkey: 'system.adapter.bosesoundtouch.',
endkey: 'system.adapter.bosesoundtouch.\u9999' },
function (err, doc) {
if (doc && doc.rows && doc.rows.length) {
doc.rows.forEach(row => {
if (row.value.native.address != instance.adapter.ipAddress) {
const systemId = row.id.split('.');
const index = systemId[systemId.length - 1];
const namespace = systemId[systemId.length - 2] + '.' + index + '.';
instance.adapter.getForeignState(namespace + BOSE_ID_INFO_MAC_ADDRESS, function(err, stateMacAddress) {
if (err) {
instance.adapter.log.error(err);
}
else {
if (stateMacAddress.val === slaveMacAddress) {
instance.adapter.getForeignState(namespace + BOSE_ID_INFO_IP_ADDRESS, function(err, stateIpAddress) {
if (err) {
instance.adapter.log.error(err);
}
else {
setZoneFunction({mac: instance.adapter.macAddress}, {ip: stateIpAddress.val, mac: stateMacAddress.val}, instance.socket);
}
});
}
}
});
}
});
}
else {
instance.adapter.log.debug('No objects found: ' + err);
}
});
}
setMasterOf(setMasterOf) {
var instance = this;
instance.masterSlaveData = {
master: {
ip: this.adapter.ipAddress,
mac: this.adapter.macAddress
},
slave: []
};
this.adapter.objects.getObjectView(
'system', 'instance', {
startkey: 'system.adapter.bosesoundtouch.',
endkey: 'system.adapter.bosesoundtouch.\u9999' },
function (err, doc) {
if (doc && doc.rows && doc.rows.length) {
var toDoList = [];
for (var i = 0; i < doc.rows.length; i++) {
var obj = doc.rows[i].value;
if (obj.native.address != instance.adapter.ipAddress) {
var systemId = doc.rows[i].id.split('.');
var index = systemId[systemId.length - 1];
var namespace = systemId[systemId.length - 2] + '.' + index + '.';
toDoList.push(namespace + BOSE_ID_INFO_IP_ADDRESS);
toDoList.push(namespace + BOSE_ID_INFO_MAC_ADDRESS);
}
}
instance._collectPlayEverywhereData(toDoList, instance._collectPlayEverywhereFinished, setMasterOf !== undefined ? setMasterOf.split(';') : undefined);
}
else {
instance.adapter.log.debug('No objects found: ' + err);
}
}
);
}
}
var adapter = new(boseSoundTouch);