homebridge-denon-tv 4.4.1 → 4.4.2-beta.2

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/index.js CHANGED
@@ -22,14 +22,14 @@ class DenonPlatform {
22
22
  api.on('didFinishLaunching', () => {
23
23
  for (const device of config.devices) {
24
24
  if (!device.name || !device.host || !device.port || !(device.zoneControl >= 0 && device.zoneControl <= 3)) {
25
- log.warn('Device name, host, port or zone control missing!');
25
+ log.warn(`Name: ${device.name ? 'OK' : device.name}, host: ${device.host ? 'OK' : device.host}, port: ${device.port ? 'OK' : device.port}, zone: ${(device.zoneControl >= 0 && device.zoneControl <= 3) ? 'OK' : device.zoneControl} ,n config wrong or missing.`);
26
26
  return;
27
27
  }
28
28
  const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, did finish launching.`) : false;
29
29
 
30
30
  //denon device
31
31
  const zone = device.zoneControl;
32
- const denonDevice = new DenonDevice(api, prefDir, device, zone);
32
+ const denonDevice = new DenonDevice(api, prefDir, zone, device);
33
33
  denonDevice.on('publishAccessory', (accessory) => {
34
34
  api.publishExternalAccessories(CONSTANS.PluginName, [accessory]);
35
35
  const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, published as external accessory.`) : false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "4.4.1",
4
+ "version": "4.4.2-beta.2",
5
5
  "description": "Homebridge plugin to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/constans.json CHANGED
@@ -173,6 +173,12 @@
173
173
  "Z3",
174
174
  "SM"
175
175
  ],
176
+ "ZoneInputSurroundName": [
177
+ "Input",
178
+ "Input",
179
+ "Input",
180
+ "Surround"
181
+ ],
176
182
  "InputSourceType": [
177
183
  "OTHER",
178
184
  "HOME_SCREEN",
package/src/denon.js CHANGED
@@ -37,6 +37,7 @@ class DENON extends EventEmitter {
37
37
  };
38
38
  const parseString = new XMLParser(options);
39
39
 
40
+ this.connected = false;
40
41
  this.startPrepareAccessory = true;
41
42
  this.emitDeviceInfo = true;
42
43
  this.power = false;
@@ -232,6 +233,8 @@ class DENON extends EventEmitter {
232
233
  this.soundMode = soundMode;
233
234
 
234
235
  //emit state
236
+ const emitConnected = !this.connected ? this.emit('message', `Connected.`) : false;
237
+ this.connected = true;
235
238
  this.emit('stateChanged', power, reference, volume, volumeDisplay, mute, pictureMode);
236
239
 
237
240
  //restFul
@@ -246,9 +249,15 @@ class DENON extends EventEmitter {
246
249
 
247
250
  this.checkState();
248
251
  } catch (error) {
249
- const debug = disableLogConnectError ? false : this.emit('error', `State error: ${error}, recheck in 15s.`);
250
- this.checkState();
252
+ const debug = disableLogConnectError ? false : this.emit('error', `State error: ${error}, reconnect in 15s.`);
253
+ this.emit('disconnect');
251
254
  };
255
+ })
256
+ .on('disconnect', () => {
257
+ this.emit('stateChanged', false, this.reference, this.volume, this.volumeDisplay, this.mute, this.pictureMode);
258
+ this.emit('disconnected', 'Disconnected.');
259
+ this.connected = false;
260
+ this.checkState();
252
261
  });
253
262
 
254
263
  this.emit('checkDeviceInfo');
@@ -9,7 +9,7 @@ const CONSTANS = require('./constans.json');
9
9
  let Accessory, Characteristic, Service, Categories, Encode, UUID;
10
10
 
11
11
  class DenonDevice extends EventEmitter {
12
- constructor(api, prefDir, config, zone) {
12
+ constructor(api, prefDir, zone, config) {
13
13
  super();
14
14
 
15
15
  Accessory = api.platformAccessory;
@@ -20,10 +20,10 @@ class DenonDevice extends EventEmitter {
20
20
  UUID = api.hap.uuid;
21
21
 
22
22
  //device configuration
23
+ this.zone = zone;
23
24
  this.name = config.name;
24
25
  this.host = config.host;
25
26
  this.port = config.port;
26
- this.zoneControl = zone;
27
27
  this.supportOldAvr = config.supportOldAvr || false;
28
28
  this.getInputsFromDevice = config.getInputsFromDevice || false;
29
29
  this.getFavoritesFromDevice = this.getInputsFromDevice ? config.getFavoritesFromDevice : false;
@@ -63,7 +63,7 @@ class DenonDevice extends EventEmitter {
63
63
  //zones
64
64
  this.zoneName = CONSTANS.ZoneName[zone];
65
65
  this.sZoneName = CONSTANS.ZoneNameShort[zone];
66
- this.inputOrSurround = zone <= 2 ? 'Input' : 'Sound Mode'
66
+ this.zoneInputSurroundName = CONSTANS.ZoneInputSurroundName[zone];
67
67
 
68
68
  //setup variables
69
69
  this.firstRun = true;
@@ -164,34 +164,32 @@ class DenonDevice extends EventEmitter {
164
164
  supportOldAvr: this.supportOldAvr,
165
165
  debugLog: this.enableDebugMode,
166
166
  disableLogConnectError: this.disableLogConnectError,
167
- zoneControl: this.zoneControl,
167
+ zoneControl: this.zone,
168
168
  refreshInterval: this.refreshInterval,
169
169
  restFulEnabled: this.restFulEnabled,
170
170
  mqttEnabled: this.mqttEnabled
171
171
  });
172
172
 
173
173
  this.denon.on('deviceInfo', async (devInfo, manufacturer, modelName, serialNumber, firmwareRevision, zones, apiVersion, supportPictureMode, supportFavorites, supportShortcut, supportInputSource, supportQuickSmartSelect) => {
174
- this.emit('message', `Connected.`);
175
-
176
174
  try {
177
175
  if (!this.disableLogDeviceInfo) {
178
176
  this.emit('devInfo', `-------- ${this.name} --------`);
179
177
  this.emit('devInfo', `Manufacturer: ${manufacturer}`);
180
178
  this.emit('devInfo', `Model: ${modelName}`);
181
- if (this.zoneControl === 0) {
179
+ if (this.zone === 0) {
182
180
  this.emit('devInfo', `Zones: ${zones}`);
183
181
  this.emit('devInfo', `Control: Main Zone`);
184
182
  this.emit('devInfo', `Firmware: ${firmwareRevision}`);
185
183
  this.emit('devInfo', `Api version: ${apiVersion}`);
186
184
  this.emit('devInfo', `Serialnr: ${serialNumber}`);
187
185
  }
188
- if (this.zoneControl === 1) {
186
+ if (this.zone === 1) {
189
187
  this.emit('devInfo', `Control: Zone 2`);
190
188
  }
191
- if (this.zoneControl === 2) {
189
+ if (this.zone === 2) {
192
190
  this.emit('devInfo', `Control: Zone 3`);
193
191
  }
194
- if (this.zoneControl === 3) {
192
+ if (this.zone === 3) {
195
193
  this.emit('devInfo', `Control: Sound Modes`);
196
194
  }
197
195
  this.emit('devInfo', `----------------------------------`);
@@ -204,7 +202,7 @@ class DenonDevice extends EventEmitter {
204
202
  this.supportPictureMode = supportPictureMode;
205
203
 
206
204
  //save device info to the file
207
- if (this.zoneControl === 0) {
205
+ if (this.zone === 0) {
208
206
  try {
209
207
  const info = JSON.stringify(devInfo, null, 2);
210
208
  await fsPromises.writeFile(this.devInfoFile, info);
@@ -239,7 +237,7 @@ class DenonDevice extends EventEmitter {
239
237
  }
240
238
 
241
239
  //new AVR-X
242
- const deviceInputs = this.getInputsFromDevice && supportInputSource ? devInfo.DeviceZoneCapabilities[this.zoneControl].InputSource.List.Source : [];
240
+ const deviceInputs = this.getInputsFromDevice && supportInputSource ? devInfo.DeviceZoneCapabilities[this.zone].InputSource.List.Source : [];
243
241
  for (const input of deviceInputs) {
244
242
  const inputName = input.DefaultName;
245
243
  const inputReference = input.FuncName;
@@ -253,7 +251,7 @@ class DenonDevice extends EventEmitter {
253
251
  referencesArray.push(reference);
254
252
  };
255
253
 
256
- const deviceSchortcuts = this.getInputsFromDevice && supportShortcut ? devInfo.DeviceZoneCapabilities[this.zoneControl].ShortcutControl.EntryList.Shortcut : [];
254
+ const deviceSchortcuts = this.getInputsFromDevice && supportShortcut ? devInfo.DeviceZoneCapabilities[this.zone].ShortcutControl.EntryList.Shortcut : [];
257
255
  for (const shortcut of deviceSchortcuts) {
258
256
  const category = shortcut.Category; //3 Quick/Smart Select, 4 Inputs
259
257
  const shortcutName = shortcut.DispName;
@@ -282,7 +280,7 @@ class DenonDevice extends EventEmitter {
282
280
  const push = !existedInArray ? inputsArr.push(obj) : false;
283
281
  };
284
282
 
285
- const deviceQuickSmartSelect = this.getQuickSmartSelectFromDevice && supportQuickSmartSelect ? devInfo.DeviceZoneCapabilities[this.zoneControl].Operation.QuickSelect : [];
283
+ const deviceQuickSmartSelect = this.getQuickSmartSelectFromDevice && supportQuickSmartSelect ? devInfo.DeviceZoneCapabilities[this.zone].Operation.QuickSelect : [];
286
284
  const quickSelectCount = this.getQuickSmartSelectFromDevice && supportQuickSmartSelect ? deviceQuickSmartSelect.MaxQuickSelect : 0;
287
285
  for (let i = 0; i < quickSelectCount; i++) {
288
286
  const quickSelect = deviceQuickSmartSelect[`QuickSelect${i + 1}`];
@@ -298,12 +296,12 @@ class DenonDevice extends EventEmitter {
298
296
  const push = !existedInArray ? inputsArr.push(obj) : false;
299
297
  };
300
298
 
301
- const allInputsArr = this.zoneControl <= 2 ? this.getInputsFromDevice ? inputsArr : this.inputs : this.surrounds;
299
+ const allInputsArr = this.zone <= 2 ? this.getInputsFromDevice ? inputsArr : this.inputs : this.surrounds;
302
300
  const inputs = JSON.stringify(allInputsArr, null, 2);
303
301
  await fsPromises.writeFile(this.inputsFile, inputs);
304
- const debug = this.enableDebugMode ? this.emit('message', `saved ${this.inputOrSurround}: ${inputs}`) : false;
302
+ const debug = this.enableDebugMode ? this.emit('message', `saved ${this.zoneInputSurroundName}: ${inputs}`) : false;
305
303
  } catch (error) {
306
- this.emit('error', `save ${this.inputOrSurround} error: ${error}`);
304
+ this.emit('error', `save ${this.zoneInputSurroundName} error: ${error}`);
307
305
  }
308
306
  } catch (error) {
309
307
  this.emit('error', `create files error: ${error}`);
@@ -395,28 +393,28 @@ class DenonDevice extends EventEmitter {
395
393
  //read inputs file
396
394
  try {
397
395
  const data = await fsPromises.readFile(this.inputsFile);
398
- this.savedInputs = data.length > 0 ? JSON.parse(data) : (this.zoneControl <= 2 ? this.inputs : this.surrounds);
399
- const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputOrSurround}: ${JSON.stringify(this.savedInputs, null, 2)}`) : false;
396
+ this.savedInputs = data.length > 0 ? JSON.parse(data) : (this.zone <= 2 ? this.inputs : this.surrounds);
397
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.zoneInputSurroundName}: ${JSON.stringify(this.savedInputs, null, 2)}`) : false;
400
398
  } catch (error) {
401
- this.emit('error', `Read saved ${this.inputOrSurround} error: ${error}`);
399
+ this.emit('error', `Read saved ${this.zoneInputSurroundName} error: ${error}`);
402
400
  };
403
401
 
404
402
  //read inputs names from file
405
403
  try {
406
404
  const data = await fsPromises.readFile(this.inputsNamesFile);
407
405
  this.savedInputsNames = data.length > 0 ? JSON.parse(data) : {};
408
- const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputOrSurround} Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`) : false;
406
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.zoneInputSurroundName} Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`) : false;
409
407
  } catch (error) {
410
- this.emit('error', `Read saved ${this.inputOrSurround} Names error: ${error}`);
408
+ this.emit('error', `Read saved ${this.zoneInputSurroundName} Names error: ${error}`);
411
409
  };
412
410
 
413
411
  //read inputs visibility from file
414
412
  try {
415
413
  const data = await fsPromises.readFile(this.inputsTargetVisibilityFile);
416
414
  this.savedInputsTargetVisibility = data.length > 0 ? JSON.parse(data) : {};
417
- const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputOrSurround} Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`) : false;
415
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.zoneInputSurroundName} Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`) : false;
418
416
  } catch (error) {
419
- this.emit('error', `Read saved ${this.inputOrSurround} Target Visibility error: ${error}`);
417
+ this.emit('error', `Read saved ${this.zoneInputSurroundName} Target Visibility error: ${error}`);
420
418
  };
421
419
 
422
420
  await new Promise(resolve => setTimeout(resolve, 2000));
@@ -452,7 +450,7 @@ class DenonDevice extends EventEmitter {
452
450
  try {
453
451
  //accessory
454
452
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare accessory`);
455
- const zoneControl = this.zoneControl;
453
+ const zoneControl = this.zone;
456
454
  const accessoryName = this.name;
457
455
  const accessoryUUID = UUID.generate(this.serialNumber + zoneControl);
458
456
  const accessoryCategory = Categories.AUDIO_RECEIVER;
@@ -501,7 +499,7 @@ class DenonDevice extends EventEmitter {
501
499
  const inputIdentifier = this.inputIdentifier;
502
500
  const inputName = this.inputsConfigured[inputIdentifier].name;
503
501
  const inputReference = this.inputsConfigured[inputIdentifier].reference;
504
- const info = this.disableLogInfo || this.firstRun ? false : this.emit('message', `${this.inputOrSurround} Name: ${inputName}, Reference: ${inputReference}`);
502
+ const info = this.disableLogInfo || this.firstRun ? false : this.emit('message', `${this.zoneInputSurroundName} Name: ${inputName}, Reference: ${inputReference}`);
505
503
  return inputIdentifier + 1;
506
504
  })
507
505
  .onSet(async (inputIdentifier) => {
@@ -520,11 +518,11 @@ class DenonDevice extends EventEmitter {
520
518
  break;
521
519
  case true:
522
520
  await this.denon.send(reference);
523
- const info = this.disableLogInfo || this.firstRun ? false : this.emit('message', `set ${this.inputOrSurround} Name: ${inputName}, Reference: ${inputReference}`);
521
+ const info = this.disableLogInfo || this.firstRun ? false : this.emit('message', `set ${this.zoneInputSurroundName} Name: ${inputName}, Reference: ${inputReference}`);
524
522
  break;
525
523
  }
526
524
  } catch (error) {
527
- this.emit('error', `set ${this.inputOrSurround} error: ${error}`);
525
+ this.emit('error', `set ${this.zoneInputSurroundName} error: ${error}`);
528
526
  };
529
527
  });
530
528
 
@@ -789,19 +787,7 @@ class DenonDevice extends EventEmitter {
789
787
  //prepare input service
790
788
  const debug8 = !this.enableDebugMode ? false : this.emit('debug', `Prepare input services`);
791
789
  //check possible inputs and possible count (max 80)
792
- let inputs = this.savedInputs;
793
- switch (this.inputsDisplayOrder) {
794
- case 0:
795
- inputs = inputs
796
- break;
797
- case 1:
798
- inputs.sort((a, b) => a.name.localeCompare(b.name));
799
- break;
800
- case 2:
801
- inputs.sort((a, b) => a.reference.localeCompare(b.reference));
802
- break;
803
- }
804
-
790
+ const inputs = this.savedInputs;
805
791
  const inputsCount = inputs.length;
806
792
  const possibleInputsCount = 90 - this.allServices.length;
807
793
  const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
@@ -834,7 +820,7 @@ class DenonDevice extends EventEmitter {
834
820
  const targetVisibility = currentVisibility;
835
821
 
836
822
  if (inputReference && inputName && inputMode) {
837
- const inputService = new Service.InputSource(`${inputName} ${index}`, `${this.inputOrSurround} ${index}`);
823
+ const inputService = new Service.InputSource(`${inputName} ${index}`, `${this.zoneInputSurroundName} ${index}`);
838
824
  inputService
839
825
  .setCharacteristic(Characteristic.Identifier, index)
840
826
  .setCharacteristic(Characteristic.Name, inputName)
@@ -854,7 +840,7 @@ class DenonDevice extends EventEmitter {
854
840
  try {
855
841
  this.savedInputsNames[inputReference] = value;
856
842
  await fsPromises.writeFile(this.inputsNamesFile, JSON.stringify(this.savedInputsNames, null, 2));
857
- const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputOrSurround} Name: ${value}, Reference: ${inputReference}`) : false;
843
+ const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.zoneInputSurroundName} Name: ${value}, Reference: ${inputReference}`) : false;
858
844
  } catch (error) {
859
845
  this.emit('error', `save Input Name error: ${error}`);
860
846
  }
@@ -872,7 +858,7 @@ class DenonDevice extends EventEmitter {
872
858
  try {
873
859
  this.savedInputsTargetVisibility[inputReference] = state;
874
860
  await fsPromises.writeFile(this.inputsTargetVisibilityFile, JSON.stringify(this.savedInputsTargetVisibility, null, 2));
875
- const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputOrSurround}: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
861
+ const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.zoneInputSurroundName}: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
876
862
  } catch (error) {
877
863
  this.emit('error', `save Target Visibility error: ${error}`);
878
864
  }
@@ -889,6 +875,19 @@ class DenonDevice extends EventEmitter {
889
875
 
890
876
  };
891
877
  };
878
+
879
+ //sort inputs list
880
+ switch (this.inputsDisplayOrder) {
881
+ case 0:
882
+ this.inputsConfigured = this.inputsConfigured
883
+ break;
884
+ case 1:
885
+ this.inputsConfigured.sort((a, b) => a.name.localeCompare(b.name));
886
+ break;
887
+ case 2:
888
+ this.inputsConfigured.sort((a, b) => a.reference.localeCompare(b.reference));
889
+ break;
890
+ }
892
891
  const displayOrder = this.inputsConfigured.map(input => input.identifier);
893
892
  this.televisionService.setCharacteristic(Characteristic.DisplayOrder, Encode(1, displayOrder).toString('base64'));
894
893