homebridge-denon-tv 4.3.21 → 4.3.22-beta.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/denondevice.js +45 -20
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "4.3.21",
4
+ "version": "4.3.22-beta.0",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -400,6 +400,35 @@ class DenonDevice extends EventEmitter {
400
400
  //start prepare accessory
401
401
  if (this.startPrepareAccessory) {
402
402
  try {
403
+
404
+ //read inputs file
405
+ try {
406
+ const data = await fsPromises.readFile(this.inputsFile);
407
+ this.savedInputs = data.length > 5 ? JSON.parse(data) : this.zoneControl <= 2 ? this.inputs : this.surrounds;
408
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround}: ${JSON.stringify(this.savedInputs, null, 2)}`) : false;
409
+ } catch (error) {
410
+ this.emit('error', `Read saved ${this.inputSurround} error: ${error}`);
411
+ };
412
+
413
+ //read inputs names from file
414
+ try {
415
+ const data = await fsPromises.readFile(this.inputsNamesFile);
416
+ this.savedInputsNames = data.length > 5 ? JSON.parse(data) : undefined;
417
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`) : false;
418
+ } catch (error) {
419
+ this.emit('error', `Read saved ${this.inputSurround} Names error: ${error}`);
420
+ };
421
+
422
+ //read inputs visibility from file
423
+ try {
424
+ const data = await fsPromises.readFile(this.inputsTargetVisibilityFile);
425
+ this.savedInputsTargetVisibility = data.length > 5 ? JSON.parse(data) : undefined;
426
+ const debug = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`) : false;
427
+ } catch (error) {
428
+ this.emit('error', `Read saved ${this.inputSurround} Target Visibility error: ${error}`);
429
+ };
430
+
431
+ await new Promise(resolve => setTimeout(resolve, 2000));
403
432
  const accessory = await this.prepareAccessory();
404
433
  this.emit('publishAccessory', accessory);
405
434
  this.startPrepareAccessory = false;
@@ -789,18 +818,8 @@ class DenonDevice extends EventEmitter {
789
818
  accessory.addService(this.tvSpeakerService);
790
819
 
791
820
  //prepare input service
792
- const debug4 = !this.enableDebugMode ? false : this.emit('debug', `Prepare inputs service`);
793
- const savedInputs = fs.readFileSync(this.inputsFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsFile)) : (this.zoneControl <= 2 ? this.inputs : this.surrounds);
794
- const debug5 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround}: ${JSON.stringify(savedInputs, null, 2)}`) : false;
795
-
796
- const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
797
- const debug6 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
798
-
799
- const savedInputsTargetVisibility = fs.readFileSync(this.inputsTargetVisibilityFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsTargetVisibilityFile)) : {};
800
- const debug7 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Target Visibility: ${JSON.stringify(savedInputsTargetVisibility, null, 2)}`) : false;
801
-
802
821
  //check possible inputs and possible count (max 80)
803
- const inputs = savedInputs;
822
+ const inputs = this.savedInputs;
804
823
  const inputsCount = inputs.length;
805
824
  const possibleInputsCount = 90 - this.services.length;
806
825
  const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
@@ -812,7 +831,7 @@ class DenonDevice extends EventEmitter {
812
831
  const inputReference = input.reference;
813
832
 
814
833
  //get name
815
- const inputName = savedInputsNames[inputReference] ?? input.name;
834
+ const inputName = this.savedInputsNames[inputReference] ?? input.name;
816
835
 
817
836
  //get mode
818
837
  const inputMode = zoneControl <= 2 ? input.mode : 'MS';
@@ -824,7 +843,8 @@ class DenonDevice extends EventEmitter {
824
843
  const isConfigured = 1;
825
844
 
826
845
  //get visibility state
827
- const currentVisibility = savedInputsTargetVisibility[inputReference] ?? 0;
846
+ const currentVisibility = this.savedInputsTargetVisibility[inputReference] ?? 0;
847
+ const targetVisibility = currentVisibility;
828
848
 
829
849
  if (inputReference && inputName && inputMode) {
830
850
  const inputService = new Service.InputSource(inputName, `${this.inputSurround} ${i}`);
@@ -836,14 +856,18 @@ class DenonDevice extends EventEmitter {
836
856
  .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
837
857
 
838
858
  inputService.getCharacteristic(Characteristic.ConfiguredName)
859
+ .onGet(async () => {
860
+ return inputName;
861
+ })
839
862
  .onSet(async (value) => {
840
863
  try {
841
- savedInputsNames[inputReference] = value;
842
- const newCustomName = JSON.stringify(savedInputsNames, null, 2);
864
+ this.savedInputsNames[inputReference] = value;
865
+ const newCustomName = JSON.stringify(this.savedInputsNames, null, 2);
843
866
 
844
867
  await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
845
868
  const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround} Name: ${value}, Reference: ${inputReference}`) : false;
846
- inputService.setCharacteristic(Characteristic.Name, value);
869
+ inputService.updateCharacteristic(Characteristic.Name, value);
870
+ inputService.updateCharacteristic(Characteristic.ConfiguredName, value);
847
871
  } catch (error) {
848
872
  this.emit('error', `save Input Name error: ${error}`);
849
873
  }
@@ -851,16 +875,17 @@ class DenonDevice extends EventEmitter {
851
875
 
852
876
  inputService.getCharacteristic(Characteristic.TargetVisibilityState)
853
877
  .onGet(async () => {
854
- return currentVisibility;
878
+ return targetVisibility;
855
879
  })
856
880
  .onSet(async (state) => {
857
881
  try {
858
- savedInputsTargetVisibility[inputReference] = state;
859
- const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
882
+ this.savedInputsTargetVisibility[inputReference] = state;
883
+ const newTargetVisibility = JSON.stringify(this.savedInputsTargetVisibility, null, 2);
860
884
 
861
885
  await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
862
886
  const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround}: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
863
- inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
887
+ inputService.updateCharacteristic(Characteristic.CurrentVisibilityState, state);
888
+ inputService.updateCharacteristic(Characteristic.TargetVisibilityState, state);
864
889
  } catch (error) {
865
890
  this.emit('error', `save Target Visibility error: ${error}`);
866
891
  }