homebridge-xbox-tv 2.10.4 → 2.11.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
  ### NOTE!!!
8
8
  ## After update to 2.x.x the plugin settings (xboxLiveId) need to be updated.
9
9
 
10
+ ## [2.11.0] - (29.12.2023)
11
+ ## Changes
12
+ - added possibility to select display inputs order, possible by `None`, `Alphabetically Name`, `Alphabetically Reference`
13
+ - config schema updated
14
+ - cleanup
15
+
10
16
  ## [2.10.0] - (26.12.2023)
11
17
  ## After update to this version the plugin properties are changed and console must be authorized and settings need to be corrected.
12
18
  ## Changes
package/README.md CHANGED
@@ -80,6 +80,7 @@ Homebridge plugin for Microsoft game Consoles. Tested with Xbox One X/S and Xbox
80
80
  | `filterApps` | If enabled, Apps will be hidden and not displayed in the inputs list, only available if `webApiControl` enabled. |
81
81
  | `filterSystemApps` | If enabled, System Apps (Accessory, Microsoft Store, Television) will be hidden and not displayed in the inputs list, only available if `webApiControl` enabled. |
82
82
  | `filterDlc` | If enabled, Dlc will be hidden and not displayed in the inputs list, only available if `webApiControl` enabled. |
83
+ | `inputsDisplayOrder` | Here select display order of the inputs list, `None`, `Alphabetically Name`, `Alphabetically Reference`. |
83
84
  | `inputs.name` | Here set *Input Name* which You want expose to the *Homebridge/HomeKit*, `Screensaver`, `Television`, `TV Settings`, `Dashboard`, `Accessory`, `Settings`, `Network Troubleshooter`, `Microsoft Store`, `Xbox Guide` are created by default. |
84
85
  | `inputs.reference` | Required to identify current running app. |
85
86
  | `inputs.oneStoreProductId` | Required to switch apps. |
@@ -80,6 +80,35 @@
80
80
  "description": "If enabled, DLC will not be displayed on the list of inputs.",
81
81
  "required": false
82
82
  },
83
+ "inputsDisplayOrder": {
84
+ "title": "Inputs Display Order",
85
+ "type": "integer",
86
+ "minimum": 0,
87
+ "maximum": 2,
88
+ "default": 0,
89
+ "description": "Here select display order of the inputs list.",
90
+ "oneOf": [
91
+ {
92
+ "title": "None",
93
+ "enum": [
94
+ 0
95
+ ]
96
+ },
97
+ {
98
+ "title": "Alphabetically Name",
99
+ "enum": [
100
+ 1
101
+ ]
102
+ },
103
+ {
104
+ "title": "Alphabetically Reference",
105
+ "enum": [
106
+ 2
107
+ ]
108
+ }
109
+ ],
110
+ "required": true
111
+ },
83
112
  "inputs": {
84
113
  "type": "array",
85
114
  "items": {
@@ -779,6 +808,7 @@
779
808
  "devices[].filterApps",
780
809
  "devices[].filterSystemApps",
781
810
  "devices[].filterDlc",
811
+ "devices[].inputsDisplayOrder",
782
812
  {
783
813
  "key": "devices[].inputs",
784
814
  "type": "tabarray",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.10.4",
4
+ "version": "2.11.0",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/xboxdevice.js CHANGED
@@ -62,20 +62,16 @@ class XboxDevice extends EventEmitter {
62
62
 
63
63
  //add configured inputs to the default inputs
64
64
  this.inputs = [...CONSTANTS.DefaultInputs, ...this.inputs];
65
- this.displayOrder = []
65
+ this.inputsConfigured = [];
66
+ this.displayOrder = [];
66
67
 
67
68
  //setup variables
68
69
  this.restFulConnected = false;
69
70
  this.mqttConnected = false;
70
71
 
71
72
  this.allServices = [];
72
- this.inputsName = [];
73
- this.inputsReference = [];
74
- this.inputsOneStoreProductId = [];
75
-
76
73
  this.sensorInputsServices = [];
77
- this.sensorInputsReference = [];
78
- this.sensorInputsDisplayType = [];
74
+ this.sensorInputs = [];
79
75
  this.buttonsServices = [];
80
76
 
81
77
  this.power = false;
@@ -278,7 +274,7 @@ class XboxDevice extends EventEmitter {
278
274
  }
279
275
  })
280
276
  .on('stateChanged', (power, volume, mute, mediaState, titleId, reference) => {
281
- const inputIdentifier = this.inputsReference.includes(reference) ? this.inputsReference.findIndex(index => index === reference) : this.inputsReference.includes(titleId) ? this.inputsReference.findIndex(index => index === titleId) : undefined;
277
+ const inputIdentifier = this.inputsConfigured.findIndex(index => index.reference === reference) + 1 ?? this.inputsConfigured.findIndex(index => index.titleId === titleId) + 1;
282
278
 
283
279
  //update characteristics
284
280
  if (this.televisionService) {
@@ -286,7 +282,7 @@ class XboxDevice extends EventEmitter {
286
282
  .updateCharacteristic(Characteristic.Active, power)
287
283
  };
288
284
 
289
- if (this.televisionService && inputIdentifier !== undefined) {
285
+ if (this.televisionService && inputIdentifier !== 0) {
290
286
  this.televisionService
291
287
  .updateCharacteristic(Characteristic.ActiveIdentifier, inputIdentifier);
292
288
  this.inputIdentifier = inputIdentifier;
@@ -313,7 +309,7 @@ class XboxDevice extends EventEmitter {
313
309
  .updateCharacteristic(Characteristic.ContactSensorState, power)
314
310
  }
315
311
 
316
- if (this.sensorInputService && inputIdentifier !== undefined) {
312
+ if (this.sensorInputService && inputIdentifier !== 0) {
317
313
  const state = power ? (this.inputIdentifier !== inputIdentifier) : false;
318
314
  this.sensorInputService
319
315
  .updateCharacteristic(Characteristic.ContactSensorState, state)
@@ -331,8 +327,8 @@ class XboxDevice extends EventEmitter {
331
327
  if (this.sensorInputsServices) {
332
328
  const servicesCount = this.sensorInputsServices.length;
333
329
  for (let i = 0; i < servicesCount; i++) {
334
- const state = power ? (this.sensorInputsReference[i] === reference) : false;
335
- const displayType = this.sensorInputsDisplayType[i];
330
+ const state = power ? (this.sensorInputs[i].reference === reference) : false;
331
+ const displayType = this.sensorInputs[i].displayType;
336
332
  const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
337
333
  this.sensorInputsServices[i]
338
334
  .updateCharacteristic(characteristicType, state);
@@ -496,17 +492,17 @@ class XboxDevice extends EventEmitter {
496
492
  this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
497
493
  .onGet(async () => {
498
494
  const inputIdentifier = this.inputIdentifier;
499
- const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
500
- const inputReference = this.inputsReference[inputIdentifier];
501
- const inputName = this.inputsName[inputIdentifier];
495
+ const inputOneStoreProductId = this.inputsConfigured[inputIdentifier].oneStoreProductId;
496
+ const inputReference = this.inputsConfigured[inputIdentifier].reference;
497
+ const inputName = this.inputsConfigured[inputIdentifier].name;
502
498
  const logInfo = this.disableLogInfo ? false : this.emit('message', `Input: ${inputName}, Reference: ${inputReference}, Product Id: ${inputOneStoreProductId}`);
503
499
  return inputIdentifier;
504
500
  })
505
501
  .onSet(async (inputIdentifier) => {
506
502
  try {
507
- const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
508
- const inputReference = this.inputsReference[inputIdentifier];
509
- const inputName = this.inputsName[inputIdentifier];
503
+ const inputOneStoreProductId = this.inputsConfigured[inputIdentifier].oneStoreProductId;
504
+ const inputReference = this.inputsConfigured[inputIdentifier].reference;
505
+ const inputName = this.inputsConfigured[inputIdentifier].name;
510
506
 
511
507
  let channelName;
512
508
  let command;
@@ -765,7 +761,19 @@ class XboxDevice extends EventEmitter {
765
761
  }
766
762
 
767
763
  //check possible inputs and possible inputs count (max 80)
768
- const inputs = filteredInputsArr;
764
+ let inputs = filteredInputsArr;
765
+ switch (this.inputsDisplayOrder) {
766
+ case 0:
767
+ inputs = inputs
768
+ break;
769
+ case 1:
770
+ inputs.sort((a, b) => a.name.localeCompare(b.name));
771
+ break;
772
+ case 2:
773
+ inputs.sort((a, b) => a.reference.localeCompare(b.reference));
774
+ break;
775
+ }
776
+
769
777
  const inputsCount = inputs.length;
770
778
  const possibleInputsCount = 90 - this.allServices.length;
771
779
  const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
@@ -797,7 +805,7 @@ class XboxDevice extends EventEmitter {
797
805
  if (inputReference && inputName) {
798
806
  const inputService = new Service.InputSource(`${inputName} ${i}`, `Input ${i}`);
799
807
  inputService
800
- .setCharacteristic(Characteristic.Identifier, i)
808
+ .setCharacteristic(Characteristic.Identifier, i + 1)
801
809
  .setCharacteristic(Characteristic.Name, inputName)
802
810
  .setCharacteristic(Characteristic.InputSourceType, inputType)
803
811
  .setCharacteristic(Characteristic.IsConfigured, isConfigured)
@@ -808,7 +816,7 @@ class XboxDevice extends EventEmitter {
808
816
  return inputName;
809
817
  })
810
818
  .onSet(async (value) => {
811
- const valueExist = value === this.savedInputsNames[inputReference];
819
+ const valueExist = inputName;
812
820
  if (valueExist) {
813
821
  return;
814
822
  }
@@ -832,7 +840,7 @@ class XboxDevice extends EventEmitter {
832
840
  return targetVisibility;
833
841
  })
834
842
  .onSet(async (state) => {
835
- const stateExist = state === this.savedInputsTargetVisibility[inputReference];
843
+ const stateExist = state === currentVisibility;
836
844
  if (stateExist) {
837
845
  return;
838
846
  };
@@ -850,10 +858,8 @@ class XboxDevice extends EventEmitter {
850
858
  }
851
859
  });
852
860
 
853
- this.displayOrder.push(1);
854
- this.inputsOneStoreProductId.push(inputOneStoreProductId);
855
- this.inputsReference.push(inputReference);
856
- this.inputsName.push(inputName);
861
+ this.displayOrder.push(i + 1);
862
+ this.inputsConfigured.push(input);
857
863
 
858
864
  this.televisionService.addLinkedService(inputService);
859
865
  this.allServices.push(inputService);
@@ -863,6 +869,7 @@ class XboxDevice extends EventEmitter {
863
869
 
864
870
  };
865
871
  }
872
+ this.televisionService.setCharacteristic(Characteristic.DisplayOrder, Encode(1, this.displayOrder).toString('base64'));
866
873
 
867
874
  //Prepare volume service
868
875
  if (this.volumeControl >= 0) {
@@ -997,8 +1004,7 @@ class XboxDevice extends EventEmitter {
997
1004
  return state;
998
1005
  });
999
1006
 
1000
- this.sensorInputsReference.push(sensorInputReference);
1001
- this.sensorInputsDisplayType.push(sensorInputDisplayType);
1007
+ this.sensorInputs.push(sensorInput);
1002
1008
  this.sensorInputsServices.push(sensorInputService);
1003
1009
  this.allServices.push(sensorInputService);
1004
1010
  accessory.addService(this.sensorInputsServices[i]);