homebridge-denon-tv 4.3.21 → 4.3.22-beta.1

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 +61 -36
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.1",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -67,7 +67,7 @@ class DenonDevice extends EventEmitter {
67
67
  this.startPrepareAccessory = true;
68
68
  this.restFulConnected = false;
69
69
  this.mqttConnected = false;
70
- this.services = [];
70
+ this.allServices = [];
71
71
  this.inputsReference = [];
72
72
  this.inputsName = [];
73
73
  this.inputsMode = [];
@@ -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, 3000));
403
432
  const accessory = await this.prepareAccessory();
404
433
  this.emit('publishAccessory', accessory);
405
434
  this.startPrepareAccessory = false;
@@ -447,7 +476,7 @@ class DenonDevice extends EventEmitter {
447
476
  .setCharacteristic(Characteristic.Model, this.modelName)
448
477
  .setCharacteristic(Characteristic.SerialNumber, this.serialNumber)
449
478
  .setCharacteristic(Characteristic.FirmwareRevision, this.firmwareRevision);
450
- this.services.push(this.informationService);
479
+ this.allServices.push(this.informationService);
451
480
 
452
481
 
453
482
  //prepare television service
@@ -710,7 +739,7 @@ class DenonDevice extends EventEmitter {
710
739
  });
711
740
  };
712
741
 
713
- this.services.push(this.televisionService);
742
+ this.allServices.push(this.televisionService);
714
743
  accessory.addService(this.televisionService);
715
744
 
716
745
  //prepare speaker service
@@ -785,24 +814,14 @@ class DenonDevice extends EventEmitter {
785
814
  };
786
815
  });
787
816
 
788
- this.services.push(this.tvSpeakerService);
817
+ this.allServices.push(this.tvSpeakerService);
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
- const possibleInputsCount = 90 - this.services.length;
824
+ const possibleInputsCount = 90 - this.allServices.length;
806
825
  const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
807
826
  for (let i = 0; i < maxInputsCount; i++) {
808
827
  //get input
@@ -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
  }
@@ -871,7 +896,7 @@ class DenonDevice extends EventEmitter {
871
896
  this.inputsMode.push(inputMode);
872
897
 
873
898
  this.televisionService.addLinkedService(inputService);
874
- this.services.push(inputService);
899
+ this.allServices.push(inputService);
875
900
  accessory.addService(inputService);
876
901
  } else {
877
902
  this.emit('message', `Name: ${inputName ? inputName : 'Missing'}, Reference: ${inputReference ? inputReference : 'Missing'}, Mode: ${inputMode ? inputMode : 'Missing'}.`);
@@ -903,7 +928,7 @@ class DenonDevice extends EventEmitter {
903
928
  this.tvSpeakerService.setCharacteristic(Characteristic.Mute, !state);
904
929
  });
905
930
 
906
- this.services.push(this.volumeService);
931
+ this.allServices.push(this.volumeService);
907
932
  accessory.addService(this.volumeService);
908
933
  }
909
934
 
@@ -928,7 +953,7 @@ class DenonDevice extends EventEmitter {
928
953
  this.tvSpeakerService.setCharacteristic(Characteristic.Mute, !state);
929
954
  });
930
955
 
931
- this.services.push(this.volumeServiceFan);
956
+ this.allServices.push(this.volumeServiceFan);
932
957
  accessory.addService(this.volumeServiceFan);
933
958
  }
934
959
  };
@@ -945,7 +970,7 @@ class DenonDevice extends EventEmitter {
945
970
  return state;
946
971
  });
947
972
 
948
- this.services.push(this.sensorPowerService);
973
+ this.allServices.push(this.sensorPowerService);
949
974
  accessory.addService(this.sensorPowerService);
950
975
  };
951
976
 
@@ -960,7 +985,7 @@ class DenonDevice extends EventEmitter {
960
985
  return state;
961
986
  });
962
987
 
963
- this.services.push(this.sensorVolumeService);
988
+ this.allServices.push(this.sensorVolumeService);
964
989
  accessory.addService(this.sensorVolumeService);
965
990
  };
966
991
 
@@ -975,7 +1000,7 @@ class DenonDevice extends EventEmitter {
975
1000
  return state;
976
1001
  });
977
1002
 
978
- this.services.push(this.sensorMuteService);
1003
+ this.allServices.push(this.sensorMuteService);
979
1004
  accessory.addService(this.sensorMuteService);
980
1005
  };
981
1006
 
@@ -990,14 +1015,14 @@ class DenonDevice extends EventEmitter {
990
1015
  return state;
991
1016
  });
992
1017
 
993
- this.services.push(this.sensorInputService);
1018
+ this.allServices.push(this.sensorInputService);
994
1019
  accessory.addService(this.sensorInputService);
995
1020
  };
996
1021
 
997
1022
  //prepare sonsor services
998
1023
  const sensorInputs = this.sensorInputs;
999
1024
  const sensorInputsCount = sensorInputs.length;
1000
- const possibleSensorInputsCount = 99 - this.services.length;
1025
+ const possibleSensorInputsCount = 99 - this.allServices.length;
1001
1026
  const maxSensorInputsCount = sensorInputsCount >= possibleSensorInputsCount ? possibleSensorInputsCount : sensorInputsCount;
1002
1027
  if (maxSensorInputsCount > 0) {
1003
1028
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare inputs sensor service`);
@@ -1030,7 +1055,7 @@ class DenonDevice extends EventEmitter {
1030
1055
  this.sensorInputsReference.push(sensorInputReference);
1031
1056
  this.sensorInputsDisplayType.push(sensorInputDisplayType);
1032
1057
  this.sensorInputsServices.push(sensorInputService);
1033
- this.services.push(sensorInputService);
1058
+ this.allServices.push(sensorInputService);
1034
1059
  accessory.addService(this.sensorInputsServices[i]);
1035
1060
  } else {
1036
1061
  this.emit('message', `Sensor Name: ${sensorInputName ? sensorInputName : 'Missing'}, Reference: ${sensorInputReference ? sensorInputReference : 'Missing'}.`);
@@ -1042,7 +1067,7 @@ class DenonDevice extends EventEmitter {
1042
1067
  //prepare buttons services
1043
1068
  const buttons = this.buttons;
1044
1069
  const buttonsCount = buttons.length;
1045
- const possibleButtonsCount = 99 - this.services.length;
1070
+ const possibleButtonsCount = 99 - this.allServices.length;
1046
1071
  const maxButtonsCount = buttonsCount >= possibleButtonsCount ? possibleButtonsCount : buttonsCount;
1047
1072
  if (maxButtonsCount > 0) {
1048
1073
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare button service`);
@@ -1086,7 +1111,7 @@ class DenonDevice extends EventEmitter {
1086
1111
  });
1087
1112
 
1088
1113
  this.buttonsServices.push(buttonService);
1089
- this.services.push(buttonService);
1114
+ this.allServices.push(buttonService);
1090
1115
  accessory.addService(this.buttonsServices[i]);
1091
1116
  } else {
1092
1117
  this.emit('message', `Button Name: ${buttonName ? buttonName : 'Missing'}, Reference: ${buttonReference ? buttonReference : 'Missing'}.`);