homebridge-denon-tv 3.23.2 → 3.23.4

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/index.js +20 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -833,7 +833,7 @@ class denonTvDevice {
833
833
  const savedInputsTargetVisibility = fs.readFileSync(this.inputsTargetVisibilityFile).length > 0 ? JSON.parse(fs.readFileSync(this.inputsTargetVisibilityFile)) : {};
834
834
  const debug2 = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'}, Target Visibility states: ${JSON.stringify(savedInputsTargetVisibility, null, 2)}`) : false;
835
835
 
836
- //check available inputs and possible count (max 80)
836
+ //check possible inputs and possible count (max 80)
837
837
  const inputs = savedInputs;
838
838
  const inputsCount = inputs.length;
839
839
  const maxInputsCount = inputsCount < 80 ? inputsCount : 80;
@@ -921,8 +921,8 @@ class denonTvDevice {
921
921
  this.inputSwitchButtonServices = [];
922
922
  const inputsSwitchesButtons = this.inputsSwitchesButtons;
923
923
  const inputsSwitchesButtonsCount = inputsSwitchesButtons.length;
924
- const availableInputsSwitchesButtonsCount = 80 - this.inputsReference.length;
925
- const maxInputsSwitchesButtonsCount = availableInputsSwitchesButtonsCount > 0 ? (availableInputsSwitchesButtonsCount > inputsSwitchesButtonsCount ? inputsSwitchesButtonsCount : availableInputsSwitchesButtonsCount) : 0;
924
+ const possibleInputsSwitchesButtonsCount = 80 - this.inputsReference.length;
925
+ const maxInputsSwitchesButtonsCount = possibleInputsSwitchesButtonsCount >= inputsSwitchesButtonsCount ? inputsSwitchesButtonsCount : possibleInputsSwitchesButtonsCount;
926
926
  if (!this.getInputsFromDevice) {
927
927
  if (maxInputsSwitchesButtonsCount > 0) {
928
928
  this.log.debug('prepareSwitchsService');
@@ -940,7 +940,7 @@ class denonTvDevice {
940
940
  const inputMode = (zoneControl <= 2) ? this.inputsMode[index] : 'MS';
941
941
 
942
942
  //get display type
943
- const inputDisplayType = this.inputsDisplayType[index] || -1;
943
+ const inputDisplayType = this.inputsDisplayType[index] >= 0 ? this.inputsDisplayType[index] : -1;
944
944
 
945
945
  if (inputDisplayType >= 0) {
946
946
  const serviceType = [Service.Outlet, Service.Switch][inputDisplayType];
@@ -974,8 +974,8 @@ class denonTvDevice {
974
974
  this.sensorInputsServices = [];
975
975
  const sensorInputs = this.sensorInputs;
976
976
  const sensorInputsCount = sensorInputs.length;
977
- const availableSensorInputsCount = 80 - this.inputsReference.length;
978
- const maxSensorInputsCount = availableSensorInputsCount > 0 ? (availableSensorInputsCount > sensorInputsCount ? sensorInputsCount : availableSensorInputsCount) : 0;
977
+ const possibleSensorInputsCount = 80 - this.inputsReference.length;
978
+ const maxSensorInputsCount = possibleSensorInputsCount >= sensorInputsCount ? sensorInputsCount : possibleSensorInputsCount;
979
979
  if (this.getInputsFromDevice) {
980
980
  if (maxSensorInputsCount > 0) {
981
981
  this.log.debug('prepareInputSensorServices');
@@ -990,12 +990,12 @@ class denonTvDevice {
990
990
  const sensorInputReference = sensorInput.reference || 'Not set';
991
991
 
992
992
  //get display type
993
- const sensorInputDisplayType = sensorInput.displayType || -1;
993
+ const sensorInputDisplayType = sensorInput.displayType >= 0 ? sensorInput.displayType : -1;
994
994
 
995
995
  if (sensorInputDisplayType >= 0) {
996
996
  const serviceType = [Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][sensorInputDisplayType];
997
997
  const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][sensorInputDisplayType];
998
- const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${sensorInputName}`);
998
+ const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${i}`);
999
999
  sensorInputService.getCharacteristic(characteristicType)
1000
1000
  .onGet(async () => {
1001
1001
  const state = this.power ? (this.reference === sensorInputReference) : false;
@@ -1013,15 +1013,18 @@ class denonTvDevice {
1013
1013
 
1014
1014
  //prepare button services zone 0 to 2
1015
1015
  if (zoneControl <= 2) {
1016
- //check available buttons and possible count (max 80)
1016
+ this.buttonsServices = [];
1017
1017
  const buttons = this.buttons;
1018
1018
  const buttonsCount = buttons.length;
1019
1019
  const maxbuttonsCount = this.getInputsFromDevice ? this.inputsReference.length + this.sensorInputsServices.length : this.inputsReference.length + this.inputSwitchButtonServices.length;
1020
- const availableButtonsCount = 80 - (maxInputsCount + maxbuttonsCount);
1021
- const maxButtonsCount = availableButtonsCount > 0 ? (availableButtonsCount > buttonsCount ? buttonsCount : availableButtonsCount) : 0;
1020
+ const possibleButtonsCount = 80 - (maxInputsCount + maxbuttonsCount);
1021
+ const maxButtonsCount = possibleButtonsCount >= buttonsCount ? buttonsCount : possibleButtonsCount;
1022
1022
  if (maxButtonsCount > 0) {
1023
- this.log.debug('prepareButtonsService');
1024
- for (const button of buttons) {
1023
+ this.log.debug('prepareInputsButtonService');
1024
+ for (let i = 0; i < maxButtonsCount; i++) {
1025
+ //get button
1026
+ const button = buttons[i];
1027
+
1025
1028
  //get button name
1026
1029
  const buttonName = button.name || 'Not set';
1027
1030
 
@@ -1029,11 +1032,11 @@ class denonTvDevice {
1029
1032
  const buttonReference = button.reference || 'Not set'
1030
1033
 
1031
1034
  //get button display type
1032
- const buttonDisplayType = button.displayType || -1;
1035
+ const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
1033
1036
 
1034
1037
  if (buttonDisplayType >= 0) {
1035
1038
  const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
1036
- const buttonService = new serviceType(`${this.sZoneName} ${buttonName}`, `Button ${buttonName}`);
1039
+ const buttonService = new serviceType(`${this.sZoneName} ${buttonName}`, `Button ${i}`);
1037
1040
  buttonService.getCharacteristic(Characteristic.On)
1038
1041
  .onGet(async () => {
1039
1042
  const state = false;
@@ -1050,7 +1053,8 @@ class denonTvDevice {
1050
1053
  this.log.error(`Device: ${this.host} ${accessoryName}, can not set new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'}. Might be due to a wrong settings in config, error: ${error}`);
1051
1054
  };
1052
1055
  });
1053
- accessory.addService(buttonService);
1056
+ this.buttonsServices.push(buttonService);
1057
+ accessory.addService(this.buttonsServices[i]);
1054
1058
  }
1055
1059
  };
1056
1060
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "3.23.2",
4
+ "version": "3.23.4",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",