homebridge-xbox-tv 2.12.25 → 2.12.26
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/index.js +1 -1
- package/package.json +1 -1
- package/src/webApi/xboxwebapi.js +2 -1
- package/src/xboxdevice.js +90 -85
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ class XboxPlatform {
|
|
|
19
19
|
fs.mkdirSync(prefDir);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
api.on('didFinishLaunching', () => {
|
|
22
|
+
api.on('didFinishLaunching', async () => {
|
|
23
23
|
for (const device of config.devices) {
|
|
24
24
|
if (!device.name || !device.host || !device.xboxLiveId) {
|
|
25
25
|
log.warn(`Name: ${device.name ? 'OK' : device.name}, Host: ${device.host ? 'OK' : device.host}, Xbox Live ID: ${device.xboxLiveId ? 'OK' : device.xboxLiveId}, wrong or missing.`);
|
package/package.json
CHANGED
package/src/webApi/xboxwebapi.js
CHANGED
|
@@ -362,9 +362,10 @@ class XBOXWEBAPI extends EventEmitter {
|
|
|
362
362
|
//chack duplicated inputs
|
|
363
363
|
const inputsArr = [];
|
|
364
364
|
for (const input of inputs) {
|
|
365
|
+
const inputName = input.name;
|
|
365
366
|
const inputReference = input.reference;
|
|
366
367
|
const duplicatedInput = inputsArr.some(input => input.reference === inputReference);
|
|
367
|
-
const push = !duplicatedInput ? inputsArr.push(input) : false;
|
|
368
|
+
const push = inputName && inputReference && !duplicatedInput ? inputsArr.push(input) : false;
|
|
368
369
|
}
|
|
369
370
|
|
|
370
371
|
//save inputs
|
package/src/xboxdevice.js
CHANGED
|
@@ -73,9 +73,10 @@ class XboxDevice extends EventEmitter {
|
|
|
73
73
|
const tempInputs = [...CONSTANTS.DefaultInputs, ...this.inputs];
|
|
74
74
|
const inputsArr = [];
|
|
75
75
|
for (const input of tempInputs) {
|
|
76
|
+
const inputName = input.name;
|
|
76
77
|
const inputReference = input.reference;
|
|
77
78
|
const duplicatedInput = inputsArr.some(input => input.reference === inputReference);
|
|
78
|
-
const push = !duplicatedInput ? inputsArr.push(input) : false;
|
|
79
|
+
const push = inputName && inputReference && !duplicatedInput ? inputsArr.push(input) : false;
|
|
79
80
|
}
|
|
80
81
|
this.inputs = inputsArr;
|
|
81
82
|
|
|
@@ -326,43 +327,27 @@ class XboxDevice extends EventEmitter {
|
|
|
326
327
|
})
|
|
327
328
|
.on('prepareAccessory', async () => {
|
|
328
329
|
try {
|
|
329
|
-
|
|
330
330
|
//read dev info from file
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read saved Info: ${JSON.stringify(this.savedInfo, null, 2)}`);
|
|
335
|
-
} catch (error) {
|
|
336
|
-
this.emit('error', `read saved Info error: ${error}`);
|
|
337
|
-
};
|
|
331
|
+
const savedInfo = await this.readData(this.devInfoFile);
|
|
332
|
+
this.savedInfo = savedInfo.toString().trim() !== '' ? JSON.parse(savedInfo) : {};
|
|
333
|
+
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read saved Info: ${JSON.stringify(this.savedInfo, null, 2)}`);
|
|
338
334
|
|
|
339
335
|
//read inputs file
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs: ${JSON.stringify(this.savedInputs, null, 2)}`);
|
|
344
|
-
} catch (error) {
|
|
345
|
-
this.emit('error', `read saved Inputs error: ${error}`);
|
|
346
|
-
};
|
|
336
|
+
const savedInputs = await this.readData(this.inputsFile);
|
|
337
|
+
this.savedInputs = savedInputs.toString().trim() !== '' ? JSON.parse(savedInputs) : this.inputs;
|
|
338
|
+
const debug2 = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs: ${JSON.stringify(this.savedInputs, null, 2)}`);
|
|
347
339
|
|
|
348
340
|
//read inputs names from file
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`);
|
|
353
|
-
} catch (error) {
|
|
354
|
-
this.emit('error', `read saved Inputs Names error: ${error}`);
|
|
355
|
-
};
|
|
341
|
+
const savedInputsNames = await this.readData(this.inputsNamesFile);
|
|
342
|
+
this.savedInputsNames = savedInputsNames.toString().trim() !== '' ? JSON.parse(savedInputsNames) : {};
|
|
343
|
+
const debug3 = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs Names: ${JSON.stringify(this.savedInputsNames, null, 2)}`);
|
|
356
344
|
|
|
357
345
|
//read inputs visibility from file
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
this.emit('error', `read saved Inputs Target Visibility error: ${error}`);
|
|
364
|
-
};
|
|
346
|
+
const savedInputsTargetVisibility = await this.readData(this.inputsTargetVisibilityFile);
|
|
347
|
+
this.savedInputsTargetVisibility = savedInputsTargetVisibility.toString().trim() !== '' ? JSON.parse(savedInputsTargetVisibility) : {};
|
|
348
|
+
const debug4 = !this.enableDebugMode ? false : this.emit('debug', `Read saved Inputs Target Visibility: ${JSON.stringify(this.savedInputsTargetVisibility, null, 2)}`);
|
|
365
349
|
|
|
350
|
+
//prepare accessory
|
|
366
351
|
await new Promise(resolve => setTimeout(resolve, 2500));
|
|
367
352
|
const accessory = await this.prepareAccessory();
|
|
368
353
|
this.emit('publishAccessory', accessory)
|
|
@@ -425,6 +410,30 @@ class XboxDevice extends EventEmitter {
|
|
|
425
410
|
});
|
|
426
411
|
}
|
|
427
412
|
|
|
413
|
+
saveData(path, data) {
|
|
414
|
+
return new Promise(async (resolve, reject) => {
|
|
415
|
+
try {
|
|
416
|
+
await fsPromises.writeFile(path, JSON.stringify(data, null, 2));
|
|
417
|
+
const debug = !this.enableDebugMode ? false : this.emit('debug', `Saved data: ${JSON.stringify(data, null, 2)}`);
|
|
418
|
+
resolve();
|
|
419
|
+
} catch (error) {
|
|
420
|
+
reject(error);
|
|
421
|
+
};
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
readData(path) {
|
|
426
|
+
return new Promise(async (resolve, reject) => {
|
|
427
|
+
try {
|
|
428
|
+
const data = await fsPromises.readFile(path);
|
|
429
|
+
const debug = !this.enableDebugMode ? false : this.emit('debug', `Read data: ${JSON.stringify(data, null, 2)}`);
|
|
430
|
+
resolve(data);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
reject(`Read saved data error: ${error}`);
|
|
433
|
+
};
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
428
437
|
|
|
429
438
|
//Prepare accessory
|
|
430
439
|
prepareAccessory() {
|
|
@@ -798,63 +807,59 @@ class XboxDevice extends EventEmitter {
|
|
|
798
807
|
input.identifier = inputIdentifier;
|
|
799
808
|
|
|
800
809
|
//input service
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
try {
|
|
820
|
-
this.savedInputsNames[inputReference] = value;
|
|
821
|
-
await fsPromises.writeFile(this.inputsNamesFile, JSON.stringify(this.savedInputsNames, null, 2));
|
|
822
|
-
const debug = !this.enableDebugMode ? false : this.emit('debug', `Saved Input Name: ${value}, Reference: ${nameIdentifier}.`);
|
|
823
|
-
|
|
824
|
-
//sort inputs
|
|
825
|
-
const index = this.inputsConfigured.findIndex(input => input.reference === inputReference);
|
|
826
|
-
this.inputsConfigured[index].name = value;
|
|
827
|
-
await this.displayOrder();
|
|
828
|
-
} catch (error) {
|
|
829
|
-
this.emit('error', `save Input Name error: ${error}`);
|
|
830
|
-
}
|
|
831
|
-
});
|
|
810
|
+
const inputService = new Service.InputSource(inputName, `Input ${inputIdentifier}`);
|
|
811
|
+
inputService
|
|
812
|
+
.setCharacteristic(Characteristic.Identifier, inputIdentifier)
|
|
813
|
+
.setCharacteristic(Characteristic.Name, inputName)
|
|
814
|
+
.setCharacteristic(Characteristic.InputSourceType, inputSourceType)
|
|
815
|
+
.setCharacteristic(Characteristic.IsConfigured, isConfigured)
|
|
816
|
+
.setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
|
|
817
|
+
|
|
818
|
+
inputService.getCharacteristic(Characteristic.ConfiguredName)
|
|
819
|
+
.onGet(async () => {
|
|
820
|
+
return inputName;
|
|
821
|
+
})
|
|
822
|
+
.onSet(async (value) => {
|
|
823
|
+
if (value === this.savedInputsNames[inputReference]) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
832
826
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
} catch (error) {
|
|
847
|
-
this.emit('error', `save Target Visibility error: ${error}`);
|
|
848
|
-
}
|
|
849
|
-
});
|
|
827
|
+
try {
|
|
828
|
+
this.savedInputsNames[inputReference] = value;
|
|
829
|
+
await this.saveData(this.inputsNamesFile, this.savedInputsNames);
|
|
830
|
+
const debug = !this.enableDebugMode ? false : this.emit('debug', `Saved Input Name: ${value}, Reference: ${nameIdentifier}.`);
|
|
831
|
+
|
|
832
|
+
//sort inputs
|
|
833
|
+
const index = this.inputsConfigured.findIndex(input => input.reference === inputReference);
|
|
834
|
+
this.inputsConfigured[index].name = value;
|
|
835
|
+
await this.displayOrder();
|
|
836
|
+
} catch (error) {
|
|
837
|
+
this.emit('error', `save Input Name error: ${error}`);
|
|
838
|
+
}
|
|
839
|
+
});
|
|
850
840
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
841
|
+
inputService.getCharacteristic(Characteristic.TargetVisibilityState)
|
|
842
|
+
.onGet(async () => {
|
|
843
|
+
return currentVisibility;
|
|
844
|
+
})
|
|
845
|
+
.onSet(async (state) => {
|
|
846
|
+
if (state === this.savedInputsTargetVisibility[inputReference]) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
try {
|
|
851
|
+
this.savedInputsTargetVisibility[inputReference] = state;
|
|
852
|
+
await this.saveData(this.inputsTargetVisibilityFile, this.savedInputsTargetVisibility);
|
|
853
|
+
const debug = !this.enableDebugMode ? false : this.emit('debug', `Saved Input: ${inputName} Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`);
|
|
854
|
+
} catch (error) {
|
|
855
|
+
this.emit('error', `save Target Visibility error: ${error}`);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
this.inputsConfigured.push(input);
|
|
860
|
+
this.televisionService.addLinkedService(inputService);
|
|
861
|
+
this.allServices.push(inputService);
|
|
862
|
+
accessory.addService(inputService);
|
|
858
863
|
}
|
|
859
864
|
|
|
860
865
|
//Prepare volume service
|