homebridge-denon-tv 4.2.0-beta.0 → 4.2.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 +102 -102
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "4.2.0-beta.0",
4
+ "version": "4.2.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",
@@ -744,13 +744,107 @@ class DenonDevice extends EventEmitter {
744
744
  this.services.push(this.tvSpeakerService);
745
745
  accessory.addService(this.tvSpeakerService);
746
746
 
747
+ //prepare input service
748
+ const debug4 = !this.enableDebugMode ? false : this.emit('debug', `Prepare inputs service`);
749
+ const savedInputs = fs.readFileSync(this.inputsFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsFile)) : (this.zoneControl <= 2 ? this.inputs : this.surrounds);
750
+ const debug5 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround}: ${JSON.stringify(savedInputs, null, 2)}`) : false;
751
+
752
+ const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
753
+ const debug6 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
754
+
755
+ const savedInputsTargetVisibility = fs.readFileSync(this.inputsTargetVisibilityFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsTargetVisibilityFile)) : {};
756
+ const debug7 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Target Visibility: ${JSON.stringify(savedInputsTargetVisibility, null, 2)}`) : false;
757
+
758
+ //check possible inputs and possible count (max 80)
759
+ const inputs = savedInputs;
760
+ const inputsCount = inputs.length;
761
+ const possibleInputsCount = 90 - this.services.length;
762
+ const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
763
+ for (let i = 0; i < maxInputsCount; i++) {
764
+ //get input
765
+ const input = inputs[i];
766
+
767
+ //get reference
768
+ const inputReference = input.reference;
769
+
770
+ //get name
771
+ const inputName = savedInputsNames[inputReference] || input.name;
772
+
773
+ //get mode
774
+ const inputMode = zoneControl <= 2 ? input.mode : 'MS';
775
+
776
+ //get type
777
+ const inputSourceType = 0;
778
+
779
+ //get configured
780
+ const isConfigured = 1;
781
+
782
+ //get visibility state
783
+ const currentVisibility = savedInputsTargetVisibility[inputReference] || 0;
784
+
785
+ if (inputReference && inputName && inputMode) {
786
+ const inputService = new Service.InputSource(inputName, `${this.inputSurround} ${i}`);
787
+ inputService
788
+ .setCharacteristic(Characteristic.Identifier, i)
789
+ .setCharacteristic(Characteristic.Name, inputName)
790
+ .setCharacteristic(Characteristic.IsConfigured, isConfigured)
791
+ .setCharacteristic(Characteristic.InputSourceType, inputSourceType)
792
+ .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
793
+
794
+ inputService.getCharacteristic(Characteristic.ConfiguredName)
795
+ .onGet(async () => {
796
+ return inputName;
797
+ })
798
+ .onSet(async (value) => {
799
+ try {
800
+ savedInputsNames[inputReference] = value;
801
+ const newCustomName = JSON.stringify(savedInputsNames, null, 2);
802
+
803
+ await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
804
+ const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround} Name: ${value}, Reference: ${inputReference}`) : false;
805
+ inputService.setCharacteristic(Characteristic.Name, value);
806
+ } catch (error) {
807
+ this.emit('error', `save Input Name error: ${error}`);
808
+ }
809
+ });
810
+
811
+ inputService.getCharacteristic(Characteristic.TargetVisibilityState)
812
+ .onGet(async () => {
813
+ return currentVisibility;
814
+ })
815
+ .onSet(async (state) => {
816
+ try {
817
+ savedInputsTargetVisibility[inputReference] = state;
818
+ const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
819
+
820
+ await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
821
+ const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround}: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
822
+ inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
823
+ } catch (error) {
824
+ this.emit('error', `save Target Visibility error: ${error}`);
825
+ }
826
+ });
827
+
828
+ this.inputsName.push(inputName);
829
+ this.inputsReference.push(inputReference);
830
+ this.inputsMode.push(inputMode);
831
+
832
+ this.televisionService.addLinkedService(inputService);
833
+ this.services.push(inputService);
834
+ accessory.addService(inputService);
835
+ } else {
836
+ this.emit('message', `Name: ${inputName ? inputName : 'Missing'}, Reference: ${inputReference ? inputReference : 'Missing'}, Mode: ${inputMode ? inputMode : 'Missing'}.`);
837
+
838
+ };
839
+ };
840
+
747
841
  //prepare volume service
748
842
  if (this.volumeControl >= 0) {
749
843
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare volume service`);
750
844
  if (this.volumeControl === 0) {
751
845
  this.volumeService = new Service.Lightbulb(`${accessoryName} Volume`, 'Volume');
752
846
  this.volumeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
753
- this.volumeService.setCharacteristic(Characteristic.ConfiguredName, `Volume`);
847
+ this.volumeService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Volume`);
754
848
  this.volumeService.getCharacteristic(Characteristic.Brightness)
755
849
  .onGet(async () => {
756
850
  const volume = this.volume;
@@ -775,7 +869,7 @@ class DenonDevice extends EventEmitter {
775
869
  if (this.volumeControl === 1) {
776
870
  this.volumeServiceFan = new Service.Fan(`${accessoryName} Volume`, 'Volume');
777
871
  this.volumeServiceFan.addOptionalCharacteristic(Characteristic.ConfiguredName);
778
- this.volumeServiceFan.setCharacteristic(Characteristic.ConfiguredName, `Volume`);
872
+ this.volumeServiceFan.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Volume`);
779
873
  this.volumeServiceFan.getCharacteristic(Characteristic.RotationSpeed)
780
874
  .onGet(async () => {
781
875
  const volume = this.volume;
@@ -803,7 +897,7 @@ class DenonDevice extends EventEmitter {
803
897
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare power sensor service`);
804
898
  this.sensorPowerService = new Service.ContactSensor(`${this.sZoneName} Power Sensor`, `Power Sensor`);
805
899
  this.sensorPowerService.addOptionalCharacteristic(Characteristic.ConfiguredName);
806
- this.sensorPowerService.setCharacteristic(Characteristic.ConfiguredName, `Power Sensor`);
900
+ this.sensorPowerService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Power Sensor`);
807
901
  this.sensorPowerService.getCharacteristic(Characteristic.ContactSensorState)
808
902
  .onGet(async () => {
809
903
  const state = this.power;
@@ -818,7 +912,7 @@ class DenonDevice extends EventEmitter {
818
912
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare volume sensor service`);
819
913
  this.sensorVolumeService = new Service.ContactSensor(`${this.sZoneName} Volume Sensor`, `Volume Sensor`);
820
914
  this.sensorVolumeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
821
- this.sensorVolumeService.setCharacteristic(Characteristic.ConfiguredName, `Volume Sensor`);
915
+ this.sensorVolumeService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Volume Sensor`);
822
916
  this.sensorVolumeService.getCharacteristic(Characteristic.ContactSensorState)
823
917
  .onGet(async () => {
824
918
  const state = this.sensorVolumeState;
@@ -833,7 +927,7 @@ class DenonDevice extends EventEmitter {
833
927
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare mute sensor service`);
834
928
  this.sensorMuteService = new Service.ContactSensor(`${this.sZoneName} Mute Sensor`, `Mute Sensor`);
835
929
  this.sensorMuteService.addOptionalCharacteristic(Characteristic.ConfiguredName);
836
- this.sensorMuteService.setCharacteristic(Characteristic.ConfiguredName, `Mute Sensor`);
930
+ this.sensorMuteService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Mute Sensor`);
837
931
  this.sensorMuteService.getCharacteristic(Characteristic.ContactSensorState)
838
932
  .onGet(async () => {
839
933
  const state = this.power ? this.mute : false;
@@ -848,7 +942,7 @@ class DenonDevice extends EventEmitter {
848
942
  const debug = !this.enableDebugMode ? false : this.emit('debug', `Prepare input sensor service`);
849
943
  this.sensorInputService = new Service.ContactSensor(`${this.sZoneName} Input Sensor`, `Input Sensor`);
850
944
  this.sensorInputService.addOptionalCharacteristic(Characteristic.ConfiguredName);
851
- this.sensorInputService.setCharacteristic(Characteristic.ConfiguredName, `Input Sensor`);
945
+ this.sensorInputService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Input Sensor`);
852
946
  this.sensorInputService.getCharacteristic(Characteristic.ContactSensorState)
853
947
  .onGet(async () => {
854
948
  const state = this.sensorInputState;
@@ -859,100 +953,6 @@ class DenonDevice extends EventEmitter {
859
953
  accessory.addService(this.sensorInputService);
860
954
  };
861
955
 
862
- //prepare input service
863
- const debug4 = !this.enableDebugMode ? false : this.emit('debug', `Prepare inputs service`);
864
- const savedInputs = fs.readFileSync(this.inputsFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsFile)) : (this.zoneControl <= 2 ? this.inputs : this.surrounds);
865
- const debug5 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround}: ${JSON.stringify(savedInputs, null, 2)}`) : false;
866
-
867
- const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
868
- const debug6 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
869
-
870
- const savedInputsTargetVisibility = fs.readFileSync(this.inputsTargetVisibilityFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsTargetVisibilityFile)) : {};
871
- const debug7 = this.enableDebugMode ? this.emit('debug', `Read saved ${this.inputSurround} Target Visibility: ${JSON.stringify(savedInputsTargetVisibility, null, 2)}`) : false;
872
-
873
- //check possible inputs and possible count (max 80)
874
- const inputs = savedInputs;
875
- const inputsCount = inputs.length;
876
- const possibleInputsCount = 90 - this.services.length;
877
- const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
878
- for (let i = 0; i < maxInputsCount; i++) {
879
- //get input
880
- const input = inputs[i];
881
-
882
- //get reference
883
- const inputReference = input.reference;
884
-
885
- //get name
886
- const inputName = savedInputsNames[inputReference] || input.name;
887
-
888
- //get mode
889
- const inputMode = zoneControl <= 2 ? input.mode : 'MS';
890
-
891
- //get type
892
- const inputSourceType = 0;
893
-
894
- //get configured
895
- const isConfigured = 1;
896
-
897
- //get visibility state
898
- const currentVisibility = savedInputsTargetVisibility[inputReference] || 0;
899
-
900
- if (inputReference && inputName && inputMode) {
901
- const inputService = new Service.InputSource(inputName, `${this.inputSurround} ${i}`);
902
- inputService
903
- .setCharacteristic(Characteristic.Identifier, i)
904
- .setCharacteristic(Characteristic.Name, inputName)
905
- .setCharacteristic(Characteristic.IsConfigured, isConfigured)
906
- .setCharacteristic(Characteristic.InputSourceType, inputSourceType)
907
- .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
908
-
909
- inputService.getCharacteristic(Characteristic.ConfiguredName)
910
- .onGet(async () => {
911
- return inputName;
912
- })
913
- .onSet(async (value) => {
914
- try {
915
- savedInputsNames[inputReference] = value;
916
- const newCustomName = JSON.stringify(savedInputsNames, null, 2);
917
-
918
- await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
919
- const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround} Name: ${value}, Reference: ${inputReference}`) : false;
920
- inputService.setCharacteristic(Characteristic.Name, value);
921
- } catch (error) {
922
- this.emit('error', `save Input Name error: ${error}`);
923
- }
924
- });
925
-
926
- inputService.getCharacteristic(Characteristic.TargetVisibilityState)
927
- .onGet(async () => {
928
- return currentVisibility;
929
- })
930
- .onSet(async (state) => {
931
- try {
932
- savedInputsTargetVisibility[inputReference] = state;
933
- const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
934
-
935
- await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
936
- const debug = this.enableDebugMode ? this.emit('debug', `Saved ${this.inputSurround}: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
937
- inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
938
- } catch (error) {
939
- this.emit('error', `save Target Visibility error: ${error}`);
940
- }
941
- });
942
-
943
- this.inputsName.push(inputName);
944
- this.inputsReference.push(inputReference);
945
- this.inputsMode.push(inputMode);
946
-
947
- this.televisionService.addLinkedService(inputService);
948
- this.services.push(inputService);
949
- accessory.addService(inputService);
950
- } else {
951
- this.emit('message', `Name: ${inputName ? inputName : 'Missing'}, Reference: ${inputReference ? inputReference : 'Missing'}, Mode: ${inputMode ? inputMode : 'Missing'}.`);
952
-
953
- };
954
- };
955
-
956
956
  //prepare sonsor services
957
957
  const sensorInputs = this.sensorInputs;
958
958
  const sensorInputsCount = sensorInputs.length;
@@ -979,7 +979,7 @@ class DenonDevice extends EventEmitter {
979
979
  const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][sensorInputDisplayType];
980
980
  const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${i}`);
981
981
  sensorInputService.addOptionalCharacteristic(Characteristic.ConfiguredName);
982
- sensorInputService.setCharacteristic(Characteristic.ConfiguredName, sensorInputName);
982
+ sensorInputService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${sensorInputName}`);
983
983
  sensorInputService.getCharacteristic(characteristicType)
984
984
  .onGet(async () => {
985
985
  const state = this.power ? (this.reference === sensorInputReference) : false;
@@ -1023,7 +1023,7 @@ class DenonDevice extends EventEmitter {
1023
1023
  const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
1024
1024
  const buttonService = new serviceType(`${this.sZoneName} ${buttonName}`, `Button ${i}`);
1025
1025
  buttonService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1026
- buttonService.setCharacteristic(Characteristic.ConfiguredName, buttonName);
1026
+ buttonService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${buttonName}`);
1027
1027
  buttonService.getCharacteristic(Characteristic.On)
1028
1028
  .onGet(async () => {
1029
1029
  const state = false;