homebridge-xbox-tv 2.11.2 → 2.11.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.
- package/package.json +1 -1
- package/src/xboxdevice.js +32 -44
package/package.json
CHANGED
package/src/xboxdevice.js
CHANGED
|
@@ -63,15 +63,14 @@ class XboxDevice extends EventEmitter {
|
|
|
63
63
|
//add configured inputs to the default inputs
|
|
64
64
|
this.inputs = [...CONSTANTS.DefaultInputs, ...this.inputs];
|
|
65
65
|
this.inputsConfigured = [];
|
|
66
|
-
this.
|
|
66
|
+
this.sensorInputs = [];
|
|
67
67
|
|
|
68
68
|
//setup variables
|
|
69
69
|
this.restFulConnected = false;
|
|
70
70
|
this.mqttConnected = false;
|
|
71
71
|
|
|
72
72
|
this.allServices = [];
|
|
73
|
-
this.
|
|
74
|
-
this.sensorInputs = [];
|
|
73
|
+
this.sensorsInputsServices = [];
|
|
75
74
|
this.buttonsServices = [];
|
|
76
75
|
|
|
77
76
|
this.power = false;
|
|
@@ -103,7 +102,7 @@ class XboxDevice extends EventEmitter {
|
|
|
103
102
|
|
|
104
103
|
files.forEach((file) => {
|
|
105
104
|
if (!fs.existsSync(file)) {
|
|
106
|
-
fs.writeFileSync(file, '
|
|
105
|
+
fs.writeFileSync(file, '');
|
|
107
106
|
}
|
|
108
107
|
});
|
|
109
108
|
} catch (error) {
|
|
@@ -274,8 +273,9 @@ class XboxDevice extends EventEmitter {
|
|
|
274
273
|
}
|
|
275
274
|
})
|
|
276
275
|
.on('stateChanged', (power, volume, mute, mediaState, titleId, reference) => {
|
|
277
|
-
const inputIdentifierR = this.inputsConfigured.findIndex(index => index.reference === reference)
|
|
278
|
-
const
|
|
276
|
+
const inputIdentifierR = this.inputsConfigured.findIndex(index => index.reference === reference) ?? -1;
|
|
277
|
+
const inputIdentifierT = this.inputsConfigured.findIndex(index => index.titleId === titleId) ?? -1;
|
|
278
|
+
const inputIdentifier = inputIdentifierR !== -1 ? inputIdentifierR : inputIdentifierT;
|
|
279
279
|
|
|
280
280
|
//update characteristics
|
|
281
281
|
if (this.televisionService) {
|
|
@@ -283,9 +283,9 @@ class XboxDevice extends EventEmitter {
|
|
|
283
283
|
.updateCharacteristic(Characteristic.Active, power)
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
-
if (this.televisionService && inputIdentifier
|
|
286
|
+
if (this.televisionService && inputIdentifier !== -1) {
|
|
287
287
|
this.televisionService
|
|
288
|
-
.updateCharacteristic(Characteristic.ActiveIdentifier, inputIdentifier);
|
|
288
|
+
.updateCharacteristic(Characteristic.ActiveIdentifier, inputIdentifier + 1);
|
|
289
289
|
};
|
|
290
290
|
|
|
291
291
|
if (this.speakerService) {
|
|
@@ -309,7 +309,7 @@ class XboxDevice extends EventEmitter {
|
|
|
309
309
|
.updateCharacteristic(Characteristic.ContactSensorState, power)
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
if (this.sensorInputService && inputIdentifier
|
|
312
|
+
if (this.sensorInputService && inputIdentifier !== -1) {
|
|
313
313
|
const state = power ? (this.inputIdentifier !== inputIdentifier) : false;
|
|
314
314
|
this.sensorInputService
|
|
315
315
|
.updateCharacteristic(Characteristic.ContactSensorState, state)
|
|
@@ -326,19 +326,19 @@ class XboxDevice extends EventEmitter {
|
|
|
326
326
|
this.sensorScreenSaverState = state;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
if (this.
|
|
330
|
-
const servicesCount = this.
|
|
329
|
+
if (this.sensorsInputsServices) {
|
|
330
|
+
const servicesCount = this.sensorsInputsServices.length;
|
|
331
331
|
for (let i = 0; i < servicesCount; i++) {
|
|
332
332
|
const state = power ? (this.sensorInputs[i].reference === reference) : false;
|
|
333
333
|
const displayType = this.sensorInputs[i].displayType;
|
|
334
334
|
const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
335
|
-
this.
|
|
335
|
+
this.sensorsInputsServices[i]
|
|
336
336
|
.updateCharacteristic(characteristicType, state);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
this.inputIdentifier = inputIdentifier
|
|
341
|
+
this.inputIdentifier = inputIdentifier !== -1 ? inputIdentifier : this.inputIdentifier;
|
|
342
342
|
this.power = power;
|
|
343
343
|
this.volume = volume;
|
|
344
344
|
this.mute = mute;
|
|
@@ -361,7 +361,7 @@ class XboxDevice extends EventEmitter {
|
|
|
361
361
|
//read dev info from file
|
|
362
362
|
try {
|
|
363
363
|
const data = await fsPromises.readFile(this.devInfoFile);
|
|
364
|
-
this.savedInfo = data.length >
|
|
364
|
+
this.savedInfo = data.length > 0 ? JSON.parse(data) : {};
|
|
365
365
|
const debug = this.enableDebugMode ? this.emit('debug', `Read saved Info: ${JSON.stringify(this.savedInfo, null, 2)}`) : false;
|
|
366
366
|
} catch (error) {
|
|
367
367
|
this.emit('error', `read saved Info error: ${error}`);
|
|
@@ -370,7 +370,7 @@ class XboxDevice extends EventEmitter {
|
|
|
370
370
|
//read inputs file
|
|
371
371
|
try {
|
|
372
372
|
const data = await fsPromises.readFile(this.inputsFile);
|
|
373
|
-
this.savedInputs = data.length >
|
|
373
|
+
this.savedInputs = data.length > 0 ? JSON.parse(data) : this.inputs;
|
|
374
374
|
const debug = this.enableDebugMode ? this.emit('debug', `Read saved Inputs: ${JSON.stringify(this.savedInputs, null, 2)}`) : false;
|
|
375
375
|
} catch (error) {
|
|
376
376
|
this.emit('error', `read saved Inputs error: ${error}`);
|
|
@@ -379,7 +379,7 @@ class XboxDevice extends EventEmitter {
|
|
|
379
379
|
//read inputs names from file
|
|
380
380
|
try {
|
|
381
381
|
const data = await fsPromises.readFile(this.inputsNamesFile);
|
|
382
|
-
this.savedInputsNames = data.length >
|
|
382
|
+
this.savedInputsNames = data.length > 0 ? JSON.parse(data) : {};
|
|
383
383
|
const debug = this.enableDebugMode ? this.emit('debug', `Read saved Inputs Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`) : false;
|
|
384
384
|
} catch (error) {
|
|
385
385
|
this.emit('error', `read saved Inputs/Channels Names error: ${error}`);
|
|
@@ -388,7 +388,7 @@ class XboxDevice extends EventEmitter {
|
|
|
388
388
|
//read inputs visibility from file
|
|
389
389
|
try {
|
|
390
390
|
const data = await fsPromises.readFile(this.inputsTargetVisibilityFile);
|
|
391
|
-
this.savedInputsTargetVisibility = data.length >
|
|
391
|
+
this.savedInputsTargetVisibility = data.length > 0 ? JSON.parse(data) : {};
|
|
392
392
|
const debug = this.enableDebugMode ? this.emit('debug', `Read saved Inputs Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`) : false;
|
|
393
393
|
} catch (error) {
|
|
394
394
|
this.emit('error', `read saved Inputs/Channels Target Visibility error: ${error}`);
|
|
@@ -442,8 +442,8 @@ class XboxDevice extends EventEmitter {
|
|
|
442
442
|
//Prepare television service
|
|
443
443
|
const debug1 = !this.enableDebugMode ? false : this.emit('debug', `Prepare television service`);
|
|
444
444
|
this.televisionService = new Service.Television(`${accessoryName} Television`, 'Television');
|
|
445
|
-
this.televisionService.setCharacteristic(Characteristic.ConfiguredName, accessoryName)
|
|
446
|
-
|
|
445
|
+
this.televisionService.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
446
|
+
this.televisionService.setCharacteristic(Characteristic.SleepDiscoveryMode, 1);
|
|
447
447
|
|
|
448
448
|
this.televisionService.getCharacteristic(Characteristic.Active)
|
|
449
449
|
.onGet(async () => {
|
|
@@ -499,7 +499,7 @@ class XboxDevice extends EventEmitter {
|
|
|
499
499
|
const inputReference = this.inputsConfigured[inputIdentifier].reference;
|
|
500
500
|
const inputName = this.inputsConfigured[inputIdentifier].name;
|
|
501
501
|
const logInfo = this.disableLogInfo ? false : this.emit('message', `Input: ${inputName}, Reference: ${inputReference}, Product Id: ${inputOneStoreProductId}`);
|
|
502
|
-
return inputIdentifier;
|
|
502
|
+
return inputIdentifier + 1;
|
|
503
503
|
})
|
|
504
504
|
.onSet(async (inputIdentifier) => {
|
|
505
505
|
try {
|
|
@@ -786,6 +786,9 @@ class XboxDevice extends EventEmitter {
|
|
|
786
786
|
//get input
|
|
787
787
|
const input = inputs[i];
|
|
788
788
|
|
|
789
|
+
//get index
|
|
790
|
+
const index = i + 1;
|
|
791
|
+
|
|
789
792
|
//get input oneStoreProductId
|
|
790
793
|
const inputOneStoreProductId = input.oneStoreProductId;
|
|
791
794
|
|
|
@@ -807,9 +810,9 @@ class XboxDevice extends EventEmitter {
|
|
|
807
810
|
const targetVisibility = currentVisibility;
|
|
808
811
|
|
|
809
812
|
if (inputReference && inputName) {
|
|
810
|
-
const inputService = new Service.InputSource(`${inputName} ${
|
|
813
|
+
const inputService = new Service.InputSource(`${inputName} ${index}`, `Input ${index}`);
|
|
811
814
|
inputService
|
|
812
|
-
.setCharacteristic(Characteristic.Identifier,
|
|
815
|
+
.setCharacteristic(Characteristic.Identifier, index)
|
|
813
816
|
.setCharacteristic(Characteristic.Name, inputName)
|
|
814
817
|
.setCharacteristic(Characteristic.InputSourceType, inputType)
|
|
815
818
|
.setCharacteristic(Characteristic.IsConfigured, isConfigured)
|
|
@@ -820,19 +823,11 @@ class XboxDevice extends EventEmitter {
|
|
|
820
823
|
return inputName;
|
|
821
824
|
})
|
|
822
825
|
.onSet(async (value) => {
|
|
823
|
-
const valueExist = inputName;
|
|
824
|
-
if (valueExist) {
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
|
|
828
826
|
try {
|
|
829
827
|
this.savedInputsNames[inputReference] = value;
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
|
|
828
|
+
await fsPromises.writeFile(this.inputsNamesFile, JSON.stringify(this.savedInputsNames, null, 2));
|
|
833
829
|
const debug = this.enableDebugMode ? this.emit('debug', `Saved Input Name: ${value}, Reference: ${nameIdentifier}.`) : false;
|
|
834
830
|
inputService.updateCharacteristic(Characteristic.Name, value);
|
|
835
|
-
inputService.updateCharacteristic(Characteristic.ConfiguredName, value);
|
|
836
831
|
} catch (error) {
|
|
837
832
|
this.emit('error', `save Input Name error: ${error}`);
|
|
838
833
|
}
|
|
@@ -844,25 +839,17 @@ class XboxDevice extends EventEmitter {
|
|
|
844
839
|
return targetVisibility;
|
|
845
840
|
})
|
|
846
841
|
.onSet(async (state) => {
|
|
847
|
-
const stateExist = state === currentVisibility;
|
|
848
|
-
if (stateExist) {
|
|
849
|
-
return;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
842
|
try {
|
|
853
843
|
this.savedInputsTargetVisibility[inputReference] = state;
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
|
|
844
|
+
await fsPromises.writeFile(this.inputsTargetVisibilityFile, JSON.stringify(this.savedInputsTargetVisibility, null, 2));
|
|
857
845
|
const debug = this.enableDebugMode ? this.emit('debug', `Saved Input: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
|
|
858
846
|
inputService.updateCharacteristic(Characteristic.CurrentVisibilityState, state);
|
|
859
|
-
inputService.updateCharacteristic(Characteristic.TargetVisibilityState, state);
|
|
860
847
|
} catch (error) {
|
|
861
848
|
this.emit('error', `save Target Visibility error: ${error}`);
|
|
862
849
|
}
|
|
863
850
|
});
|
|
864
851
|
|
|
865
|
-
|
|
852
|
+
input.identifier = index;
|
|
866
853
|
this.inputsConfigured.push(input);
|
|
867
854
|
|
|
868
855
|
this.televisionService.addLinkedService(inputService);
|
|
@@ -873,7 +860,8 @@ class XboxDevice extends EventEmitter {
|
|
|
873
860
|
|
|
874
861
|
};
|
|
875
862
|
}
|
|
876
|
-
this.
|
|
863
|
+
const displayOrder = this.inputsConfigured.map(input => input.identifier);
|
|
864
|
+
this.televisionService.setCharacteristic(Characteristic.DisplayOrder, Encode(1, displayOrder).toString('base64'));
|
|
877
865
|
|
|
878
866
|
//Prepare volume service
|
|
879
867
|
if (this.volumeControl >= 0) {
|
|
@@ -1009,9 +997,9 @@ class XboxDevice extends EventEmitter {
|
|
|
1009
997
|
});
|
|
1010
998
|
|
|
1011
999
|
this.sensorInputs.push(sensorInput);
|
|
1012
|
-
this.
|
|
1000
|
+
this.sensorsInputsServices.push(sensorInputService);
|
|
1013
1001
|
this.allServices.push(sensorInputService);
|
|
1014
|
-
accessory.addService(this.
|
|
1002
|
+
accessory.addService(this.sensorsInputsServices[i]);
|
|
1015
1003
|
} else {
|
|
1016
1004
|
this.emit('message', `Sensor Name: ${sensorInputName ? sensorInputName : 'Missing'}, Reference: ${sensorInputReference ? sensorInputReference : 'Missing'}.`);
|
|
1017
1005
|
};
|