homebridge-denon-tv 3.23.0 → 3.23.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.
Files changed (3) hide show
  1. package/index.js +49 -40
  2. package/package.json +1 -1
  3. package/src/denon.js +1 -1
package/index.js CHANGED
@@ -192,7 +192,15 @@ class denonTvDevice {
192
192
  if (!fs.existsSync(this.devInfoFile)) {
193
193
  await fsPromises.writeFile(this.devInfoFile, '');
194
194
  }
195
- await fsPromises.writeFile(this.devInfoFile, JSON.stringify(devInfo, null, 2));
195
+
196
+ //save device info to the file
197
+ try {
198
+ const devInfo1 = JSON.stringify(devInfo, null, 2);
199
+ const writeDevInfo = await fsPromises.writeFile(this.devInfoFile, devInfo1);
200
+ const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved device info: ${devInfo1}`) : false;
201
+ } catch (error) {
202
+ this.log.error(`Device: ${this.host} ${this.name}, save device info error: ${error}`);
203
+ };
196
204
  }
197
205
 
198
206
  // Create inputs file if it doesn't exist
@@ -251,7 +259,7 @@ class denonTvDevice {
251
259
  const allInputsArr = this.zoneControl <= 2 ? (this.getInputsFromDevice ? inputsArr : this.inputs) : this.soundModes;
252
260
  const inputs = JSON.stringify(allInputsArr, null, 2);
253
261
  const writeInputs = await fsPromises.writeFile(this.inputsFile, inputs);
254
- const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, save ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'} succesful: ${inputs}`) : false;
262
+ const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'}: ${inputs}`) : false;
255
263
  } catch (error) {
256
264
  this.log.error(`Device: ${this.host} ${this.name}, save ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'} error: ${error}`);
257
265
  };
@@ -260,7 +268,6 @@ class denonTvDevice {
260
268
  };
261
269
  })
262
270
  .on('deviceInfo', (manufacturer, modelName, serialNumber, firmwareRevision, zones, apiVersion) => {
263
-
264
271
  if (!this.disableLogDeviceInfo) {
265
272
  this.log(`-------- ${this.name} --------`);
266
273
  this.log(`Manufacturer: ${manufacturer}`);
@@ -818,13 +825,13 @@ class denonTvDevice {
818
825
  //prepare input service
819
826
  this.log.debug('prepareInputsService');
820
827
  const savedInputs = fs.readFileSync(this.inputsFile).length > 0 ? JSON.parse(fs.readFileSync(this.inputsFile)) : (this.zoneControl <= 2 ? this.inputs : this.soundModes);
821
- const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved ${this.zoneControl <= 2 ? 'Input' : 'Sound Mode'}, successful: ${JSON.stringify(savedInputs, null, 2)}`) : false;
828
+ const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'}: ${JSON.stringify(savedInputs, null, 2)}`) : false;
822
829
 
823
830
  const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 0 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
824
- const debug1 = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved custom ${this.zoneControl <= 2 ? 'Input' : 'Sound Mode'}, Names successful: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
831
+ const debug1 = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved ${this.zoneControl <= 2 ? 'Inputs' : 'Sound Modes'} names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
825
832
 
826
833
  const savedInputsTargetVisibility = fs.readFileSync(this.inputsTargetVisibilityFile).length > 0 ? JSON.parse(fs.readFileSync(this.inputsTargetVisibilityFile)) : {};
827
- const debug2 = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, read saved ${this.zoneControl <= 2 ? 'Input' : 'Sound Mode'}, Target Visibility successful: ${JSON.stringify(savedInputsTargetVisibility, null, 2)}`) : false;
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;
828
835
 
829
836
  //check available inputs and possible count (max 80)
830
837
  const inputs = savedInputs;
@@ -877,9 +884,9 @@ class denonTvDevice {
877
884
  const newCustomName = JSON.stringify(savedInputsNames, null, 2);
878
885
 
879
886
  const writeNewCustomName = nameIdentifier ? await fsPromises.writeFile(this.inputsNamesFile, newCustomName) : false;
880
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'} name saved successful, name: ${name}, reference: ${inputReference}`);
887
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, saved new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'} name: ${name}, reference: ${inputReference}`);
881
888
  } catch (error) {
882
- this.log.error(`Device: ${this.host} ${accessoryName}, new Input name saved failed, error: ${error}`);
889
+ this.log.error(`Device: ${this.host} ${accessoryName}, new Input name save error: ${error}`);
883
890
  }
884
891
  });
885
892
 
@@ -892,10 +899,10 @@ class denonTvDevice {
892
899
  const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
893
900
 
894
901
  const writeNewTargetVisibility = targetVisibilityIdentifier ? await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility) : false;
895
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'}: ${inputName}, saved target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`);
902
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, saved new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'}: ${inputName}, target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`);
896
903
  inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
897
904
  } catch (error) {
898
- this.log.error(`Device: ${this.host} ${accessoryName}, saved target visibility state error: ${error}`);
905
+ this.log.error(`Device: ${this.host} ${accessoryName}, new target visibility state save error: ${error}`);
899
906
  }
900
907
  });
901
908
 
@@ -924,39 +931,41 @@ class denonTvDevice {
924
931
  const index = inputsSwitchesButtons[i];
925
932
 
926
933
  //get name
927
- const inputName = this.inputsName[index];
934
+ const inputName = this.inputsName[index] || 'Not set';
928
935
 
929
936
  //get reference
930
- const inputReference = this.inputsReference[index];
937
+ const inputReference = this.inputsReference[index] || 'Not set';
931
938
 
932
939
  //get mode
933
940
  const inputMode = (zoneControl <= 2) ? this.inputsMode[index] : 'MS';
934
941
 
935
942
  //get display type
936
- const inputDisplayType = this.inputsDisplayType[index];
937
-
938
- const serviceType = [Service.Outlet, Service.Switch][inputDisplayType];
939
- const characteristicType = [Characteristic.On, Characteristic.On][inputDisplayType];
940
- const inputSwitchButtonService = new serviceType(`${this.sZoneName} ${inputName}`, `Switch ${i}`);
941
- inputSwitchButtonService.getCharacteristic(characteristicType)
942
- .onGet(async () => {
943
- const state = this.power ? (this.reference === inputReference) : false;
944
- return state;
945
- })
946
- .onSet(async (state) => {
947
- try {
948
- const zone = [inputMode, 'Z2', 'Z3', inputMode][zoneControl];
949
- const reference = zone + inputReference;
950
-
951
- const setSwitchInput = (state && this.power) ? await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + reference) : false;
952
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, set new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'} successful, name: ${inputName}, reference: ${inputReference}`);
953
- } catch (error) {
954
- 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}`);
955
- };
956
- });
957
-
958
- this.inputSwitchButtonServices.push(inputSwitchButtonService);
959
- accessory.addService(this.inputSwitchButtonServices[i]);
943
+ const inputDisplayType = this.inputsDisplayType[index] || -1;
944
+
945
+ if (inputDisplayType >= 0) {
946
+ const serviceType = [Service.Outlet, Service.Switch][inputDisplayType];
947
+ const characteristicType = [Characteristic.On, Characteristic.On][inputDisplayType];
948
+ const inputSwitchButtonService = new serviceType(`${this.sZoneName} ${inputName}`, `Switch ${i}`);
949
+ inputSwitchButtonService.getCharacteristic(characteristicType)
950
+ .onGet(async () => {
951
+ const state = this.power ? (this.reference === inputReference) : false;
952
+ return state;
953
+ })
954
+ .onSet(async (state) => {
955
+ try {
956
+ const zone = [inputMode, 'Z2', 'Z3', inputMode][zoneControl];
957
+ const reference = zone + inputReference;
958
+
959
+ const setSwitchInput = (state && this.power) ? await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + reference) : false;
960
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${accessoryName}, set new ${zoneControl <= 2 ? 'Input' : 'Sound Mode'} successful, name: ${inputName}, reference: ${inputReference}`);
961
+ } catch (error) {
962
+ 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}`);
963
+ };
964
+ });
965
+
966
+ this.inputSwitchButtonServices.push(inputSwitchButtonService);
967
+ accessory.addService(this.inputSwitchButtonServices[i]);
968
+ }
960
969
  }
961
970
  };
962
971
  };
@@ -975,10 +984,10 @@ class denonTvDevice {
975
984
  const sensorInput = sensorInputs[i];
976
985
 
977
986
  //get name
978
- const sensorInputName = sensorInput.name || 'Not set in config';
987
+ const sensorInputName = sensorInput.name || 'Not set';
979
988
 
980
989
  //get reference
981
- const sensorInputReference = sensorInput.reference || 'Not set in config';
990
+ const sensorInputReference = sensorInput.reference || 'Not set';
982
991
 
983
992
  //get display type
984
993
  const sensorInputDisplayType = sensorInput.displayType || -1;
@@ -1014,10 +1023,10 @@ class denonTvDevice {
1014
1023
  this.log.debug('prepareButtonsService');
1015
1024
  for (const button of buttons) {
1016
1025
  //get button name
1017
- const buttonName = button.name || 'Not set in config';
1026
+ const buttonName = button.name || 'Not set';
1018
1027
 
1019
1028
  //get button reference
1020
- const buttonReference = button.reference || 'Not set in config'
1029
+ const buttonReference = button.reference || 'Not set'
1021
1030
 
1022
1031
  //get button display type
1023
1032
  const buttonDisplayType = button.displayType || -1;
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.0",
4
+ "version": "3.23.2",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/denon.js CHANGED
@@ -54,7 +54,7 @@ class DENON extends EventEmitter {
54
54
  const devInfo = parseDeviceInfo.Device_Info;
55
55
  const debug = debugLog ? this.emit('debug', `Info: ${JSON.stringify(devInfo, null, 2)}`) : false;
56
56
 
57
- const manufacturer = ['Denon', 'Marantz'][devInfo.BrandCode[0]] || 'Marantz';
57
+ const manufacturer = ['Denon', 'Marantz'][devInfo.BrandCode[0]] || 'Denon/Marantz';
58
58
  const modelName = devInfo.ModelName[0] || 'undefined';
59
59
  const serialNumber = devInfo.MacAddress[0] || false;
60
60
  const firmwareRevision = devInfo.UpgradeVersion[0] || 'undefined';