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