homebridge-xbox-tv 2.7.7 → 2.7.8

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 +94 -85
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -782,7 +782,7 @@ class XBOXDEVICE {
782
782
  const newCustomName = JSON.stringify(savedInputsNames, null, 2);
783
783
  await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
784
784
  const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved Input Name: ${value}, Reference: ${nameIdentifier}.`) : false;
785
- inputService.setCharacteristic(Characteristic.Name, inputName);
785
+ inputService.setCharacteristic(Characteristic.Name, value);
786
786
  } catch (error) {
787
787
  this.log.error(`Device: ${this.host} ${accessoryName}, save Input Name error: ${error}`);
788
788
  }
@@ -831,28 +831,32 @@ class XBOXDEVICE {
831
831
  const sensorInput = sensorInputs[i];
832
832
 
833
833
  //get sensor name
834
- const sensorInputName = sensorInput.name || 'Not set';
834
+ const sensorInputName = sensorInput.name;
835
835
 
836
836
  //get sensor reference
837
- const sensorInputReference = sensorInput.reference || 'Not set';
837
+ const sensorInputReference = sensorInput.reference;
838
838
 
839
839
  //get sensor display type
840
840
  const sensorInputDisplayType = sensorInput.displayType >= 0 ? sensorInput.displayType : -1;
841
841
 
842
842
  if (sensorInputDisplayType >= 0) {
843
- const serviceType = [Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][sensorInputDisplayType];
844
- const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][sensorInputDisplayType];
845
- const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${i}`);
846
- sensorInputService.getCharacteristic(characteristicType)
847
- .onGet(async () => {
848
- const state = this.power ? (this.reference === sensorInputReference) : false;
849
- return state;
850
- });
851
-
852
- this.sensorInputsReference.push(sensorInputReference);
853
- this.sensorInputsDisplayType.push(sensorInputDisplayType);
854
- this.sensorInputsServices.push(sensorInputService);
855
- accessory.addService(this.sensorInputsServices[i]);
843
+ if (sensorInputName && sensorInputReference) {
844
+ const serviceType = [Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][sensorInputDisplayType];
845
+ const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][sensorInputDisplayType];
846
+ const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${i}`);
847
+ sensorInputService.getCharacteristic(characteristicType)
848
+ .onGet(async () => {
849
+ const state = this.power ? (this.reference === sensorInputReference) : false;
850
+ return state;
851
+ });
852
+
853
+ this.sensorInputsReference.push(sensorInputReference);
854
+ this.sensorInputsDisplayType.push(sensorInputDisplayType);
855
+ this.sensorInputsServices.push(sensorInputService);
856
+ accessory.addService(this.sensorInputsServices[i]);
857
+ } else {
858
+ this.log(`Device: ${this.host} ${accessoryName}, Sensor Name: ${sensorInputName ? sensorInputName : 'Missing'}, Reference: ${sensorInputReference ? sensorInputReference : 'Missing'}.`);
859
+ };
856
860
  }
857
861
  }
858
862
  }
@@ -869,85 +873,90 @@ class XBOXDEVICE {
869
873
  const button = buttons[i];
870
874
 
871
875
  //get button name
872
- const buttonName = button.name || 'Not set';
876
+ const buttonName = button.name;
873
877
 
874
878
  //get button command
875
- const buttonCommand = button.command || 'Not set';
879
+ const buttonCommand = button.command;
880
+
881
+ //get button mode
882
+ let mode;
883
+ if (buttonCommand in CONSTANS.SystemMediaCommands) {
884
+ mode = 0;
885
+ } else if (buttonCommand in CONSTANS.SystemInputCommands) {
886
+ mode = 1;
887
+ } else if (buttonCommand in CONSTANS.TvRemoteCommands) {
888
+ mode = 2;
889
+ } else if (buttonCommand === 'recordGameDvr') {
890
+ mode = 3;
891
+ } else if (buttonCommand === 'reboot') {
892
+ mode = 4;
893
+ } else if (buttonCommand === 'switchAppGame') {
894
+ mode = 5;
895
+ };
896
+ const buttonMode = mode >= 0 ? mode : -1;
876
897
 
877
898
  //get button inputOneStoreProductId
878
- const buttonOneStoreProductId = button.oneStoreProductId || 'Not set';
899
+ const buttonOneStoreProductId = button.oneStoreProductId;
879
900
 
880
901
  //get button display type
881
902
  const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
882
903
 
883
904
  if (buttonDisplayType >= 0) {
884
- const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
885
- const buttonService = new serviceType(`${accessoryName} ${buttonName}`, `Button ${i}`);
886
- buttonService.getCharacteristic(Characteristic.On)
887
- .onGet(async () => {
888
- const state = false;
889
- const logDebug = this.disableLogInfo ? this.log(`Device: ${this.host} ${accessoryName}, Button state: ${state}`) : false;
890
- return state;
891
- })
892
- .onSet(async (state) => {
893
- try {
894
- if (state) {
895
- //get button mode
896
- let buttonMode = -1;
897
- if (buttonCommand in CONSTANS.SystemMediaCommands) {
898
- buttonMode = 0;
899
- } else if (buttonCommand in CONSTANS.SystemInputCommands) {
900
- buttonMode = 1;
901
- } else if (buttonCommand in CONSTANS.TvRemoteCommands) {
902
- buttonMode = 2;
903
- } else if (buttonCommand === 'recordGameDvr') {
904
- buttonMode = 3;
905
- } else if (buttonCommand === 'reboot') {
906
- buttonMode = 4;
907
- } else if (buttonCommand === 'switchAppGame') {
908
- buttonMode = 5;
909
- };
910
-
911
- switch (buttonMode) {
912
- case 0: case 1: case 2:
913
- await this.xboxWebApi.sendButtonPress(buttonCommand);
914
- break;
915
- case 3:
916
- await this.xboxLocalApi.recordGameDvr();
917
- break;
918
- case 4:
919
- await this.xboxWebApi.reboot();
920
- break;
921
- case 5:
922
- switch (buttonOneStoreProductId) {
923
- case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
924
- await this.xboxWebApi.launchDashboard();
925
- break;
926
- case 'Television':
927
- await this.xboxWebApi.launchOneGuide();
928
- break;
929
- case 'XboxGuide':
930
- await this.xboxWebApi.openGuideTab();
931
- break;
932
- case 'Not set': case 'Web api disabled':
933
- this.log(`Device: ${this.host} ${accessoryName}, trying to launch App/Game with one store product id: ${buttonOneStoreProductId}.`);
934
- break;
935
- default:
936
- await this.xboxWebApi.launchApp(buttonOneStoreProductId);
937
- break;
938
- }
939
- break;
905
+ if (buttonName && buttonCommand && buttonMode) {
906
+ const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
907
+ const buttonService = new serviceType(`${accessoryName} ${buttonName}`, `Button ${i}`);
908
+ buttonService.getCharacteristic(Characteristic.On)
909
+ .onGet(async () => {
910
+ const state = false;
911
+ const logDebug = this.disableLogInfo ? this.log(`Device: ${this.host} ${accessoryName}, Button state: ${state}`) : false;
912
+ return state;
913
+ })
914
+ .onSet(async (state) => {
915
+ try {
916
+ if (state) {
917
+ switch (buttonMode) {
918
+ case 0: case 1: case 2:
919
+ await this.xboxWebApi.sendButtonPress(buttonCommand);
920
+ break;
921
+ case 3:
922
+ await this.xboxLocalApi.recordGameDvr();
923
+ break;
924
+ case 4:
925
+ await this.xboxWebApi.reboot();
926
+ break;
927
+ case 5:
928
+ switch (buttonOneStoreProductId) {
929
+ case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
930
+ await this.xboxWebApi.launchDashboard();
931
+ break;
932
+ case 'Television':
933
+ await this.xboxWebApi.launchOneGuide();
934
+ break;
935
+ case 'XboxGuide':
936
+ await this.xboxWebApi.openGuideTab();
937
+ break;
938
+ case 'Not set': case 'Web api disabled':
939
+ this.log(`Device: ${this.host} ${accessoryName}, trying to launch App/Game with one store product id: ${buttonOneStoreProductId}.`);
940
+ break;
941
+ default:
942
+ await this.xboxWebApi.launchApp(buttonOneStoreProductId);
943
+ break;
944
+ }
945
+ break;
946
+ }
947
+ const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set Button Name: ${buttonName}, Command: ${buttonCommand}`) : false;
940
948
  }
941
- const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set Button Name: ${buttonName}, Command: ${buttonCommand}`) : false;
942
- }
943
- await new Promise(resolve => setTimeout(resolve, 300));
944
- const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
945
- } catch (error) {
946
- this.log.error(`Device: ${this.host} ${accessoryName}, set Button error: ${error}`);
947
- };
948
- });
949
- this.buttonsServices.push(buttonService);
950
- accessory.addService(this.buttonsServices[i]);
949
+ await new Promise(resolve => setTimeout(resolve, 300));
950
+ const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
951
+ } catch (error) {
952
+ this.log.error(`Device: ${this.host} ${accessoryName}, set Button error: ${error}`);
953
+ };
954
+ });
955
+ this.buttonsServices.push(buttonService);
956
+ accessory.addService(this.buttonsServices[i]);
957
+ } else {
958
+ this.log(`Device: ${this.host} ${accessoryName}, Button Name: ${buttonName ? buttonName : 'Missing'}, Command: ${buttonCommand ? buttonCommand : 'Missing'}, Mode: ${buttonMode ? buttonMode : 'Missing'}.`);
959
+ };
951
960
  }
952
961
  }
953
962
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.7.7",
4
+ "version": "2.7.8",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",