homebridge-xbox-tv 2.7.7 → 2.7.9
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 +124 -99
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -109,6 +109,7 @@ class XBOXDEVICE {
|
|
|
109
109
|
//setup variables
|
|
110
110
|
this.firstRun = true;
|
|
111
111
|
|
|
112
|
+
this.services = [];
|
|
112
113
|
this.inputsName = [];
|
|
113
114
|
this.inputsReference = [];
|
|
114
115
|
this.inputsOneStoreProductId = [];
|
|
@@ -246,20 +247,20 @@ class XBOXDEVICE {
|
|
|
246
247
|
|
|
247
248
|
if (this.sensorPowerService) {
|
|
248
249
|
this.sensorPowerService
|
|
249
|
-
.updateCharacteristic(Characteristic.
|
|
250
|
+
.updateCharacteristic(Characteristic.ContactSensorState, power)
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
if (this.sensorInputService) {
|
|
253
254
|
const state = power ? (this.inputIdentifier !== inputIdentifier) : false;
|
|
254
255
|
this.sensorInputService
|
|
255
|
-
.updateCharacteristic(Characteristic.
|
|
256
|
+
.updateCharacteristic(Characteristic.ContactSensorState, state)
|
|
256
257
|
this.sensorInputState = state;
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
if (this.sensorScreenSaverService) {
|
|
260
261
|
const state = power ? (reference === 'Xbox.IdleScreen_8wekyb3d8bbwe!Xbox.IdleScreen.Application') : false;
|
|
261
262
|
this.sensorScreenSaverService
|
|
262
|
-
.updateCharacteristic(Characteristic.
|
|
263
|
+
.updateCharacteristic(Characteristic.ContactSensorState, state)
|
|
263
264
|
this.sensorScreenSaverState = state;
|
|
264
265
|
}
|
|
265
266
|
|
|
@@ -384,6 +385,7 @@ class XBOXDEVICE {
|
|
|
384
385
|
.setCharacteristic(Characteristic.Model, this.modelName)
|
|
385
386
|
.setCharacteristic(Characteristic.SerialNumber, this.serialNumber)
|
|
386
387
|
.setCharacteristic(Characteristic.FirmwareRevision, this.firmwareRevision);
|
|
388
|
+
this.services.push(this.informationService);
|
|
387
389
|
|
|
388
390
|
//Prepare television service
|
|
389
391
|
this.log.debug('prepareTelevisionService');
|
|
@@ -563,6 +565,7 @@ class XBOXDEVICE {
|
|
|
563
565
|
};
|
|
564
566
|
});
|
|
565
567
|
|
|
568
|
+
this.services.push(this.televisionService);
|
|
566
569
|
accessory.addService(this.televisionService);
|
|
567
570
|
|
|
568
571
|
//Prepare speaker service
|
|
@@ -629,6 +632,7 @@ class XBOXDEVICE {
|
|
|
629
632
|
};
|
|
630
633
|
});
|
|
631
634
|
|
|
635
|
+
this.services.push(this.speakerService);
|
|
632
636
|
accessory.addService(this.speakerService);
|
|
633
637
|
|
|
634
638
|
//Prepare volume service
|
|
@@ -653,6 +657,7 @@ class XBOXDEVICE {
|
|
|
653
657
|
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
654
658
|
});
|
|
655
659
|
|
|
660
|
+
this.services.push(this.volumeService);
|
|
656
661
|
accessory.addService(this.volumeService);
|
|
657
662
|
}
|
|
658
663
|
|
|
@@ -675,6 +680,7 @@ class XBOXDEVICE {
|
|
|
675
680
|
this.speakerService.setCharacteristic(Characteristic.Mute, !state);
|
|
676
681
|
});
|
|
677
682
|
|
|
683
|
+
this.services.push(this.volumeServiceFan);
|
|
678
684
|
accessory.addService(this.volumeServiceFan);
|
|
679
685
|
}
|
|
680
686
|
}
|
|
@@ -682,34 +688,40 @@ class XBOXDEVICE {
|
|
|
682
688
|
//prepare sensor service
|
|
683
689
|
if (this.sensorPower) {
|
|
684
690
|
this.log.debug('prepareSensorPowerService')
|
|
685
|
-
this.sensorPowerService = new Service.
|
|
686
|
-
this.sensorPowerService.getCharacteristic(Characteristic.
|
|
691
|
+
this.sensorPowerService = new Service.ContactSensor(`${accessoryName} Power Sensor`, `Power Sensor`);
|
|
692
|
+
this.sensorPowerService.getCharacteristic(Characteristic.ContactSensorState)
|
|
687
693
|
.onGet(async () => {
|
|
688
694
|
const state = this.power;
|
|
689
695
|
return state;
|
|
690
696
|
});
|
|
697
|
+
|
|
698
|
+
this.services.push(this.sensorPowerService);
|
|
691
699
|
accessory.addService(this.sensorPowerService);
|
|
692
700
|
};
|
|
693
701
|
|
|
694
702
|
if (this.sensorInput) {
|
|
695
703
|
this.log.debug('prepareSensorInputService')
|
|
696
|
-
this.sensorInputService = new Service.
|
|
697
|
-
this.sensorInputService.getCharacteristic(Characteristic.
|
|
704
|
+
this.sensorInputService = new Service.ContactSensor(`${accessoryName} Input Sensor`, `Input Sensor`);
|
|
705
|
+
this.sensorInputService.getCharacteristic(Characteristic.ContactSensorState)
|
|
698
706
|
.onGet(async () => {
|
|
699
707
|
const state = this.power ? this.sensorInputState : false;
|
|
700
708
|
return state;
|
|
701
709
|
});
|
|
710
|
+
|
|
711
|
+
this.services.push(this.sensorInputService);
|
|
702
712
|
accessory.addService(this.sensorInputService);
|
|
703
713
|
};
|
|
704
714
|
|
|
705
715
|
if (this.sensorScreenSaver) {
|
|
706
716
|
this.log.debug('prepareSensorScreenSaverService')
|
|
707
|
-
this.sensorScreenSaverService = new Service.
|
|
708
|
-
this.sensorScreenSaverService.getCharacteristic(Characteristic.
|
|
717
|
+
this.sensorScreenSaverService = new Service.ContactSensor(`${accessoryName} Screen Saver Sensor`, `Screen Saver Sensor`);
|
|
718
|
+
this.sensorScreenSaverService.getCharacteristic(Characteristic.ContactSensorState)
|
|
709
719
|
.onGet(async () => {
|
|
710
720
|
const state = this.power ? this.sensorScreenSaverState : false;
|
|
711
721
|
return state;
|
|
712
722
|
});
|
|
723
|
+
|
|
724
|
+
this.services.push(this.sensorScreenSaverService);
|
|
713
725
|
accessory.addService(this.sensorScreenSaverService);
|
|
714
726
|
};
|
|
715
727
|
|
|
@@ -738,7 +750,8 @@ class XBOXDEVICE {
|
|
|
738
750
|
//check possible inputs and possible inputs count (max 80)
|
|
739
751
|
const inputs = filteredInputsArr;
|
|
740
752
|
const inputsCount = inputs.length;
|
|
741
|
-
const
|
|
753
|
+
const possibleInputsCount = 90 - this.services.length;
|
|
754
|
+
const maxInputsCount = inputsCount >= possibleInputsCount ? possibleInputsCount : inputsCount;
|
|
742
755
|
for (let i = 0; i < maxInputsCount; i++) {
|
|
743
756
|
//get input
|
|
744
757
|
const input = inputs[i];
|
|
@@ -782,7 +795,7 @@ class XBOXDEVICE {
|
|
|
782
795
|
const newCustomName = JSON.stringify(savedInputsNames, null, 2);
|
|
783
796
|
await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
|
|
784
797
|
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved Input Name: ${value}, Reference: ${nameIdentifier}.`) : false;
|
|
785
|
-
inputService.setCharacteristic(Characteristic.Name,
|
|
798
|
+
inputService.setCharacteristic(Characteristic.Name, value);
|
|
786
799
|
} catch (error) {
|
|
787
800
|
this.log.error(`Device: ${this.host} ${accessoryName}, save Input Name error: ${error}`);
|
|
788
801
|
}
|
|
@@ -812,6 +825,7 @@ class XBOXDEVICE {
|
|
|
812
825
|
this.inputsName.push(inputName);
|
|
813
826
|
|
|
814
827
|
this.televisionService.addLinkedService(inputService);
|
|
828
|
+
this.services.push(inputService);
|
|
815
829
|
accessory.addService(inputService);
|
|
816
830
|
} else {
|
|
817
831
|
this.log(`Device: ${this.host} ${accessoryName}, Input Name: ${inputName ? inputName : 'Missing'}, Reference: ${inputReference ? inputReference : 'Missing'}.`);
|
|
@@ -822,8 +836,8 @@ class XBOXDEVICE {
|
|
|
822
836
|
//prepare sonsor service
|
|
823
837
|
const sensorInputs = this.sensorInputs;
|
|
824
838
|
const sensorInputsCount = sensorInputs.length;
|
|
825
|
-
const possibleSensorInputsCount =
|
|
826
|
-
const maxSensorInputsCount =
|
|
839
|
+
const possibleSensorInputsCount = 90 - this.services.length;
|
|
840
|
+
const maxSensorInputsCount = sensorInputsCount >= possibleSensorInputsCount ? possibleSensorInputsCount : sensorInputsCount;
|
|
827
841
|
if (maxSensorInputsCount > 0) {
|
|
828
842
|
this.log.debug('prepareInputSensorServices');
|
|
829
843
|
for (let i = 0; i < maxSensorInputsCount; i++) {
|
|
@@ -831,28 +845,33 @@ class XBOXDEVICE {
|
|
|
831
845
|
const sensorInput = sensorInputs[i];
|
|
832
846
|
|
|
833
847
|
//get sensor name
|
|
834
|
-
const sensorInputName = sensorInput.name
|
|
848
|
+
const sensorInputName = sensorInput.name;
|
|
835
849
|
|
|
836
850
|
//get sensor reference
|
|
837
|
-
const sensorInputReference = sensorInput.reference
|
|
851
|
+
const sensorInputReference = sensorInput.reference;
|
|
838
852
|
|
|
839
853
|
//get sensor display type
|
|
840
854
|
const sensorInputDisplayType = sensorInput.displayType >= 0 ? sensorInput.displayType : -1;
|
|
841
855
|
|
|
842
856
|
if (sensorInputDisplayType >= 0) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
.
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
857
|
+
if (sensorInputName && sensorInputReference) {
|
|
858
|
+
const serviceType = [Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][sensorInputDisplayType];
|
|
859
|
+
const characteristicType = [Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][sensorInputDisplayType];
|
|
860
|
+
const sensorInputService = new serviceType(`${accessoryName} ${sensorInputName}`, `Sensor ${i}`);
|
|
861
|
+
sensorInputService.getCharacteristic(characteristicType)
|
|
862
|
+
.onGet(async () => {
|
|
863
|
+
const state = this.power ? (this.reference === sensorInputReference) : false;
|
|
864
|
+
return state;
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
this.sensorInputsReference.push(sensorInputReference);
|
|
868
|
+
this.sensorInputsDisplayType.push(sensorInputDisplayType);
|
|
869
|
+
this.sensorInputsServices.push(sensorInputService);
|
|
870
|
+
this.services.push(sensorInputService);
|
|
871
|
+
accessory.addService(this.sensorInputsServices[i]);
|
|
872
|
+
} else {
|
|
873
|
+
this.log(`Device: ${this.host} ${accessoryName}, Sensor Name: ${sensorInputName ? sensorInputName : 'Missing'}, Reference: ${sensorInputReference ? sensorInputReference : 'Missing'}.`);
|
|
874
|
+
};
|
|
856
875
|
}
|
|
857
876
|
}
|
|
858
877
|
}
|
|
@@ -860,8 +879,8 @@ class XBOXDEVICE {
|
|
|
860
879
|
//Prepare buttons services
|
|
861
880
|
const buttons = this.buttons;
|
|
862
881
|
const buttonsCount = buttons.length;
|
|
863
|
-
const possibleButtonsCount =
|
|
864
|
-
const maxButtonsCount =
|
|
882
|
+
const possibleButtonsCount = 90 - this.services.length;
|
|
883
|
+
const maxButtonsCount = buttonsCount >= possibleButtonsCount ? possibleButtonsCount : buttonsCount;
|
|
865
884
|
if (maxButtonsCount > 0) {
|
|
866
885
|
this.log.debug('prepareInputsButtonService');
|
|
867
886
|
for (let i = 0; i < maxButtonsCount; i++) {
|
|
@@ -869,85 +888,91 @@ class XBOXDEVICE {
|
|
|
869
888
|
const button = buttons[i];
|
|
870
889
|
|
|
871
890
|
//get button name
|
|
872
|
-
const buttonName = button.name
|
|
891
|
+
const buttonName = button.name;
|
|
873
892
|
|
|
874
893
|
//get button command
|
|
875
|
-
const buttonCommand = button.command
|
|
894
|
+
const buttonCommand = button.command;
|
|
895
|
+
|
|
896
|
+
//get button mode
|
|
897
|
+
let mode;
|
|
898
|
+
if (buttonCommand in CONSTANS.SystemMediaCommands) {
|
|
899
|
+
mode = 0;
|
|
900
|
+
} else if (buttonCommand in CONSTANS.SystemInputCommands) {
|
|
901
|
+
mode = 1;
|
|
902
|
+
} else if (buttonCommand in CONSTANS.TvRemoteCommands) {
|
|
903
|
+
mode = 2;
|
|
904
|
+
} else if (buttonCommand === 'recordGameDvr') {
|
|
905
|
+
mode = 3;
|
|
906
|
+
} else if (buttonCommand === 'reboot') {
|
|
907
|
+
mode = 4;
|
|
908
|
+
} else if (buttonCommand === 'switchAppGame') {
|
|
909
|
+
mode = 5;
|
|
910
|
+
};
|
|
911
|
+
const buttonMode = mode >= 0 ? mode : -1;
|
|
876
912
|
|
|
877
913
|
//get button inputOneStoreProductId
|
|
878
|
-
const buttonOneStoreProductId = button.oneStoreProductId
|
|
914
|
+
const buttonOneStoreProductId = button.oneStoreProductId;
|
|
879
915
|
|
|
880
916
|
//get button display type
|
|
881
917
|
const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
|
|
882
918
|
|
|
883
919
|
if (buttonDisplayType >= 0) {
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
.
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
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;
|
|
920
|
+
if (buttonName && buttonCommand && buttonMode) {
|
|
921
|
+
const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
|
|
922
|
+
const buttonService = new serviceType(`${accessoryName} ${buttonName}`, `Button ${i}`);
|
|
923
|
+
buttonService.getCharacteristic(Characteristic.On)
|
|
924
|
+
.onGet(async () => {
|
|
925
|
+
const state = false;
|
|
926
|
+
const logDebug = this.disableLogInfo ? this.log(`Device: ${this.host} ${accessoryName}, Button state: ${state}`) : false;
|
|
927
|
+
return state;
|
|
928
|
+
})
|
|
929
|
+
.onSet(async (state) => {
|
|
930
|
+
try {
|
|
931
|
+
if (state) {
|
|
932
|
+
switch (buttonMode) {
|
|
933
|
+
case 0: case 1: case 2:
|
|
934
|
+
await this.xboxWebApi.sendButtonPress(buttonCommand);
|
|
935
|
+
break;
|
|
936
|
+
case 3:
|
|
937
|
+
await this.xboxLocalApi.recordGameDvr();
|
|
938
|
+
break;
|
|
939
|
+
case 4:
|
|
940
|
+
await this.xboxWebApi.reboot();
|
|
941
|
+
break;
|
|
942
|
+
case 5:
|
|
943
|
+
switch (buttonOneStoreProductId) {
|
|
944
|
+
case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
|
|
945
|
+
await this.xboxWebApi.launchDashboard();
|
|
946
|
+
break;
|
|
947
|
+
case 'Television':
|
|
948
|
+
await this.xboxWebApi.launchOneGuide();
|
|
949
|
+
break;
|
|
950
|
+
case 'XboxGuide':
|
|
951
|
+
await this.xboxWebApi.openGuideTab();
|
|
952
|
+
break;
|
|
953
|
+
case 'Not set': case 'Web api disabled':
|
|
954
|
+
this.log(`Device: ${this.host} ${accessoryName}, trying to launch App/Game with one store product id: ${buttonOneStoreProductId}.`);
|
|
955
|
+
break;
|
|
956
|
+
default:
|
|
957
|
+
await this.xboxWebApi.launchApp(buttonOneStoreProductId);
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set Button Name: ${buttonName}, Command: ${buttonCommand}`) : false;
|
|
940
963
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
964
|
+
await new Promise(resolve => setTimeout(resolve, 300));
|
|
965
|
+
const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
|
|
966
|
+
} catch (error) {
|
|
967
|
+
this.log.error(`Device: ${this.host} ${accessoryName}, set Button error: ${error}`);
|
|
968
|
+
};
|
|
969
|
+
});
|
|
970
|
+
this.buttonsServices.push(buttonService);
|
|
971
|
+
this.services.push(buttonService);
|
|
972
|
+
accessory.addService(this.buttonsServices[i]);
|
|
973
|
+
} else {
|
|
974
|
+
this.log(`Device: ${this.host} ${accessoryName}, Button Name: ${buttonName ? buttonName : 'Missing'}, Command: ${buttonCommand ? buttonCommand : 'Missing'}, Mode: ${buttonMode ? buttonMode : 'Missing'}.`);
|
|
975
|
+
};
|
|
951
976
|
}
|
|
952
977
|
}
|
|
953
978
|
}
|
package/package.json
CHANGED