homebridge-xbox-tv 2.7.5 → 2.7.7-beta.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/index.js CHANGED
@@ -107,7 +107,6 @@ class XBOXDEVICE {
107
107
  this.firmwareRevision = 'Firmware Revision';
108
108
 
109
109
  //setup variables
110
- this.webApiEnabled = false;
111
110
  this.firstRun = true;
112
111
 
113
112
  this.inputsReference = [];
@@ -130,7 +129,6 @@ class XBOXDEVICE {
130
129
 
131
130
  this.prefDir = path.join(api.user.storagePath(), 'xboxTv');
132
131
  this.authTokenFile = `${this.prefDir}/authToken_${this.host.split('.').join('')}`;
133
- this.inputsFile = `${this.prefDir}/inputs_${this.host.split('.').join('')}`;
134
132
  this.inputsNamesFile = `${this.prefDir}/inputsNames_${this.host.split('.').join('')}`;
135
133
  this.inputsTargetVisibilityFile = `${this.prefDir}/inputsTargetVisibility_${this.host.split('.').join('')}`;
136
134
 
@@ -315,35 +313,24 @@ class XBOXDEVICE {
315
313
  debugLog: this.enableDebugMode
316
314
  });
317
315
 
318
- this.xboxWebApi.on('authenticated', (status) => {
319
- this.webApiEnabled = status;
320
- })
321
- .on('consoleStatus', (consoleStatusData, consoleType) => {
322
- if (this.informationService) {
323
- this.informationService
324
- .setCharacteristic(Characteristic.Model, consoleType)
325
- };
316
+ this.xboxWebApi.on('consoleStatus', (consoleStatusData, consoleType) => {
317
+ if (this.informationService) {
318
+ this.informationService
319
+ .setCharacteristic(Characteristic.Model, consoleType)
320
+ };
326
321
 
327
- //this.serialNumber = id;
328
- this.modelName = consoleType;
329
- //this.power = powerState;
330
- //this.mediaState = playbackState;
322
+ //this.serialNumber = id;
323
+ this.modelName = consoleType;
324
+ //this.power = powerState;
325
+ //this.mediaState = playbackState;
331
326
 
332
- const mqtt = this.mqttEnabled ? this.mqtt.send('Status', JSON.stringify(consoleStatusData, null, 2)) : false;
333
- })
327
+ const mqtt = this.mqttEnabled ? this.mqtt.send('Status', JSON.stringify(consoleStatusData, null, 2)) : false;
328
+ })
334
329
  .on('consolesList', (consolesList) => {
335
330
  const mqtt = this.mqttEnabled ? this.mqtt.send('Consoles List', JSON.stringify(consolesList, null, 2)) : false;
336
331
  })
337
332
  .on('appsList', async (appsArray) => {
338
- try {
339
- const apps = JSON.stringify([...CONSTANS.DefaultInputs, ...appsArray], null, 2);
340
- await fsPromises.writeFile(this.inputsFile, apps);
341
- const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved apps: ${apps}`) : false;
342
-
343
- const mqtt = this.mqttEnabled ? this.mqtt.send('Apps', JSON.stringify(apps, null, 2)) : false;
344
- } catch (error) {
345
- this.log.error(`Device: ${this.host} ${this.name}, save apps error: ${error}`);
346
- };
333
+ this.inputs = [...CONSTANS.DefaultInputs, ...appsArray];
347
334
  })
348
335
  .on('storageDevices', (storageDevices) => {
349
336
  const mqtt = this.mqttEnabled ? this.mqtt.send('Storages', JSON.stringify(storageDevices, null, 2)) : false;
@@ -430,7 +417,7 @@ class XBOXDEVICE {
430
417
  const inputReference = this.inputsReference[inputIdentifier];
431
418
  const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
432
419
 
433
- switch (this.webApiEnabled && inputOneStoreProductId) {
420
+ switch (inputOneStoreProductId) {
434
421
  case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
435
422
  await this.xboxWebApi.launchDashboard();
436
423
  break;
@@ -495,7 +482,7 @@ class XBOXDEVICE {
495
482
  break;
496
483
  };
497
484
 
498
- const sendCommand = this.power && this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : false;
485
+ await this.xboxWebApi.sendButtonPress(command);
499
486
  const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, Remote Key command successful: ${command}`);
500
487
  } catch (error) {
501
488
  this.log.error(`Device: ${this.host} ${accessoryName}, set Remote Key command error: ${JSON.stringify(error, null, 2)}`);
@@ -541,7 +528,7 @@ class XBOXDEVICE {
541
528
  };
542
529
 
543
530
  const channelName = 'systemInput';
544
- const setPowerModeSelection = this.power && this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : false;
531
+ await this.xboxWebApi.sendButtonPress(command);
545
532
  const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command successful: ${command}`);
546
533
  } catch (error) {
547
534
  this.log.error(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command error: ${error}`);
@@ -568,7 +555,7 @@ class XBOXDEVICE {
568
555
  break;
569
556
  };
570
557
 
571
- const setVolume = this.power && this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : false;
558
+ await this.xboxWebApi.sendButtonPress(command);
572
559
  const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Volume command successful: ${command}`);
573
560
  } catch (error) {
574
561
  this.log.error(`Device: ${this.host} ${accessoryName}, set Volume command error: ${error}`);
@@ -596,7 +583,7 @@ class XBOXDEVICE {
596
583
  })
597
584
  .onSet(async (state) => {
598
585
  try {
599
- const toggleMute = this.power && this.webApiEnabled ? (state ? await this.xboxWebApi.mute() : await this.xboxWebApi.unmute()) : false;
586
+ const toggleMute = state ? await this.xboxWebApi.mute() : await this.xboxWebApi.unmute();
600
587
  const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Mute successful: ${state ? 'ON' : 'OFF'}`);
601
588
  } catch (error) {
602
589
  this.log.error(`Device: ${this.host} ${accessoryName}, set Mute error: ${error}`);
@@ -616,7 +603,7 @@ class XBOXDEVICE {
616
603
  return volume;
617
604
  })
618
605
  .onSet(async (volume) => {
619
- const setVolume = this.power ? this.speakerService.setCharacteristic(Characteristic.Volume, volume) : false;
606
+ this.speakerService.setCharacteristic(Characteristic.Volume, volume);
620
607
  });
621
608
  this.volumeService.getCharacteristic(Characteristic.On)
622
609
  .onGet(async () => {
@@ -624,7 +611,7 @@ class XBOXDEVICE {
624
611
  return state;
625
612
  })
626
613
  .onSet(async (state) => {
627
- const setMute = this.power ? this.speakerService.setCharacteristic(Characteristic.Mute, !state) : false;
614
+ this.speakerService.setCharacteristic(Characteristic.Mute, !state);
628
615
  });
629
616
 
630
617
  accessory.addService(this.volumeService);
@@ -638,7 +625,7 @@ class XBOXDEVICE {
638
625
  return volume;
639
626
  })
640
627
  .onSet(async (volume) => {
641
- const setVolume = this.power ? this.speakerService.setCharacteristic(Characteristic.Volume, volume) : false;
628
+ this.speakerService.setCharacteristic(Characteristic.Volume, volume);
642
629
  });
643
630
  this.volumeServiceFan.getCharacteristic(Characteristic.On)
644
631
  .onGet(async () => {
@@ -646,7 +633,7 @@ class XBOXDEVICE {
646
633
  return state;
647
634
  })
648
635
  .onSet(async (state) => {
649
- const setMute = this.power ? this.speakerService.setCharacteristic(Characteristic.Mute, !state) : false;
636
+ this.speakerService.setCharacteristic(Characteristic.Mute, !state);
650
637
  });
651
638
 
652
639
  accessory.addService(this.volumeServiceFan);
@@ -689,10 +676,6 @@ class XBOXDEVICE {
689
676
 
690
677
  //Prepare inputs services
691
678
  this.log.debug('prepareInputServices');
692
-
693
- const savedInputs = this.getInputsFromDevice ? fs.readFileSync(this.inputsFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsFile)) : this.inputs : this.inputs;
694
- const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, read saved Inputs: ${JSON.stringify(savedInputs, null, 2)}`) : false;
695
-
696
679
  const savedInputsNames = fs.readFileSync(this.inputsNamesFile).length > 2 ? JSON.parse(fs.readFileSync(this.inputsNamesFile)) : {};
697
680
  const debug1 = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, read saved Inputs names: ${JSON.stringify(savedInputsNames, null, 2)}`) : false;
698
681
 
@@ -701,7 +684,7 @@ class XBOXDEVICE {
701
684
 
702
685
  //check possible inputs and filter custom unnecessary inputs
703
686
  const filteredInputsArr = [];
704
- for (const input of savedInputs) {
687
+ for (const input of this.inputs) {
705
688
  const contentType = input.contentType;
706
689
  const filterGames = this.filterGames ? (contentType === 'Game') : false;
707
690
  const filterApps = this.filterApps ? (contentType === 'App') : false;
@@ -719,13 +702,13 @@ class XBOXDEVICE {
719
702
  const input = inputs[i];
720
703
 
721
704
  //get title Id
722
- const inputTitleId = input.titleId || 'undefined';
705
+ const inputTitleId = input.titleId;
723
706
 
724
707
  //get input reference
725
- const inputReference = input.reference || 'undefined';
708
+ const inputReference = input.reference;
726
709
 
727
710
  //get input oneStoreProductId
728
- const inputOneStoreProductId = this.webApiEnabled ? input.oneStoreProductId || 'undefined' : 'undefined';
711
+ const inputOneStoreProductId = input.oneStoreProductId;
729
712
 
730
713
  //get input name
731
714
  const inputName = savedInputsNames[inputTitleId] ? savedInputsNames[inputTitleId] : savedInputsNames[inputReference] ? savedInputsNames[inputReference] : savedInputsNames[inputOneStoreProductId] ? savedInputsNames[inputOneStoreProductId] : input.name;
@@ -740,51 +723,63 @@ class XBOXDEVICE {
740
723
  const currentVisibility = savedInputsTargetVisibility[inputTitleId] ? savedInputsTargetVisibility[inputTitleId] : savedInputsTargetVisibility[inputReference] ? savedInputsTargetVisibility[inputReference] : savedInputsTargetVisibility[inputOneStoreProductId] ? savedInputsTargetVisibility[inputOneStoreProductId] : 0;
741
724
  const targetVisibility = currentVisibility;
742
725
 
743
- const inputService = new Service.InputSource(inputName, `Input ${i}`);
744
- inputService
745
- .setCharacteristic(Characteristic.Identifier, i)
746
- .setCharacteristic(Characteristic.ConfiguredName, inputName)
747
- .setCharacteristic(Characteristic.IsConfigured, isConfigured)
748
- .setCharacteristic(Characteristic.InputSourceType, inputType)
749
- .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
750
- .setCharacteristic(Characteristic.TargetVisibilityState, targetVisibility);
751
-
752
- inputService
753
- .getCharacteristic(Characteristic.ConfiguredName)
754
- .onSet(async (name) => {
755
- try {
756
- const nameIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
757
- savedInputsNames[nameIdentifier] = name;
758
- const newCustomName = JSON.stringify(savedInputsNames, null, 2);
759
- fs.writeFileSync(this.inputsNamesFile, newCustomName);
760
- const logInfo = this.enableDebugMode || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, saved new Input name: ${name}, one store product id: ${inputOneStoreProductId}`);
761
- } catch (error) {
762
- this.log.error(`Device: ${this.host} ${accessoryName}, new Input name save error: ${error}`);
763
- }
764
- });
726
+ if (inputReference && inputName) {
727
+ const inputService = new Service.InputSource(inputName, `Input ${i}`);
728
+ inputService
729
+ .setCharacteristic(Characteristic.Identifier, i)
730
+ .setCharacteristic(Characteristic.Name, inputName)
731
+ .setCharacteristic(Characteristic.IsConfigured, isConfigured)
732
+ .setCharacteristic(Characteristic.InputSourceType, inputType)
733
+ .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility)
765
734
 
766
- inputService
767
- .getCharacteristic(Characteristic.TargetVisibilityState)
768
- .onSet(async (state) => {
769
- try {
770
- const targetVisibilityIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
771
- savedInputsTargetVisibility[targetVisibilityIdentifier] = state;
772
- const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
773
- fs.writeFileSync(this.inputsTargetVisibilityFile, newTargetVisibility);
774
- const logInfo = this.enableDebugMode || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, saved new Input: ${inputName} target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`);
775
- inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
776
- } catch (error) {
777
- this.log.error(`Device: ${this.host} ${accessoryName}, new target visibility state save error: ${error}`);
778
- }
779
- });
735
+ inputService.getCharacteristic(Characteristic.ConfiguredName)
736
+ .onGet(async () => {
737
+ return inputName;
738
+ })
739
+ .onSet(async (name) => {
740
+ try {
741
+ const nameIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
742
+ savedInputsNames[nameIdentifier] = name;
743
+
744
+ const newCustomName = JSON.stringify(savedInputsNames, null, 2);
745
+ await fsPromises.writeFile(this.inputsNamesFile, newCustomName);
746
+ const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input name: ${name}, one store product id: ${inputOneStoreProductId}`) : false;
747
+ inputService.setCharacteristic(Characteristic.Name, inputName);
748
+ } catch (error) {
749
+ this.log.error(`Device: ${this.host} ${accessoryName}, new Input name save error: ${error}`);
750
+ }
751
+ });
752
+
753
+ inputService
754
+ .getCharacteristic(Characteristic.TargetVisibilityState)
755
+ .onGet(async () => {
756
+ return targetVisibility;
757
+ })
758
+ .onSet(async (state) => {
759
+ try {
760
+ const targetVisibilityIdentifier = inputTitleId ? inputTitleId : inputReference ? inputReference : inputOneStoreProductId ? inputOneStoreProductId : false;
761
+ savedInputsTargetVisibility[targetVisibilityIdentifier] = state;
762
+
763
+ const newTargetVisibility = JSON.stringify(savedInputsTargetVisibility, null, 2);
764
+ await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility);
765
+ const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, saved new Input: ${inputName} target visibility state: ${state ? 'HIDEN' : 'SHOWN'}`) : false;
766
+ inputService.setCharacteristic(Characteristic.CurrentVisibilityState, state);
767
+ } catch (error) {
768
+ this.log.error(`Device: ${this.host} ${accessoryName}, new target visibility state save error: ${error}`);
769
+ }
770
+ });
771
+
772
+ this.inputsTitleId.push(inputTitleId);
773
+ this.inputsReference.push(inputReference);
774
+ this.inputsOneStoreProductId.push(inputOneStoreProductId);
775
+ this.inputsName.push(inputName);
780
776
 
781
- this.inputsTitleId.push(inputTitleId);
782
- this.inputsReference.push(inputReference);
783
- this.inputsOneStoreProductId.push(inputOneStoreProductId);
784
- this.inputsName.push(inputName);
777
+ this.televisionService.addLinkedService(inputService);
778
+ accessory.addService(inputService);
779
+ } else {
780
+ this.log(`Device: ${this.host} ${accessoryName}, ${!inputName ? 'name: Missing' : 'name: OK'}, ${!inputReference ? 'reference: Missing' : 'reference: OK'}, check your Inputs config!!!`);
785
781
 
786
- this.televisionService.addLinkedService(inputService);
787
- accessory.addService(inputService);
782
+ };
788
783
  }
789
784
 
790
785
  //prepare sonsor service
@@ -845,7 +840,7 @@ class XBOXDEVICE {
845
840
  const buttonCommand = button.command || 'Not set';
846
841
 
847
842
  //get button inputOneStoreProductId
848
- const buttonOneStoreProductId = this.webApiEnabled ? button.oneStoreProductId || 'Not set' : 'Web api disabled';
843
+ const buttonOneStoreProductId = button.oneStoreProductId || 'Not set';
849
844
 
850
845
  //get button display type
851
846
  const buttonDisplayType = button.displayType >= 0 ? button.displayType : -1;
@@ -856,12 +851,12 @@ class XBOXDEVICE {
856
851
  buttonService.getCharacteristic(Characteristic.On)
857
852
  .onGet(async () => {
858
853
  const state = false;
859
- const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, get Button state successful: ${state}`);
854
+ const logDebug = this.disableLogInfo ? this.log(`Device: ${this.host} ${accessoryName}, get Button state successful: ${state}`) : false;
860
855
  return state;
861
856
  })
862
857
  .onSet(async (state) => {
863
858
  try {
864
- if (this.power && state && this.webApiEnabled) {
859
+ if (state) {
865
860
  //get button mode
866
861
  let buttonMode = -1;
867
862
  if (buttonCommand in CONSTANS.SystemMediaCommands) {
@@ -908,10 +903,10 @@ class XBOXDEVICE {
908
903
  }
909
904
  break;
910
905
  }
911
- const logInfo = this.enableDebugMode || this.firstRun || buttonMode === -1 ? false : this.log(`Device: ${this.host} ${accessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`);
906
+ const logDebug = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`) : false;
912
907
  }
913
908
  await new Promise(resolve => setTimeout(resolve, 300));
914
- const setChar = this.power && state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
909
+ const setChar = state ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
915
910
  } catch (error) {
916
911
  this.log.error(`Device: ${this.host} ${accessoryName}, set button error, name: ${buttonName}, error: ${error}`);
917
912
  };
@@ -925,4 +920,4 @@ class XBOXDEVICE {
925
920
  this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
926
921
  const debug3 = this.enableDebugMode ? this.log(`Device: ${this.host} ${accessoryName}, published as external accessory.`) : false;
927
922
  }
928
- };
923
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.7.5",
4
+ "version": "2.7.7-beta.0",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -50,12 +50,13 @@ class XBOXWEBAPI extends EventEmitter {
50
50
  try {
51
51
  const authorized = await this.authentication.isAuthenticated();
52
52
  if (!authorized) {
53
- this.emit(`message', 'not authorized, please use authorization manager first!!!`)
53
+ this.emit(`message', 'not authorized, please use authorization manager first.`)
54
+ this.auhorized = false;
54
55
  return;
55
56
  }
56
57
 
57
58
  try {
58
- this.emit('authenticated', true);
59
+ this.auhorized = true;
59
60
  this.headers = {
60
61
  'Authorization': (this.userToken !== '' && this.uhs !== '') ? `XBL3.0 x=${this.uhs};${this.userToken}` : `XBL3.0 x=${this.authentication.user.uhs};${this.authentication.tokens.xsts.Token}`,
61
62
  'Accept-Language': 'en-US',
@@ -478,6 +479,11 @@ class XBOXWEBAPI extends EventEmitter {
478
479
  send(commandType, command, params) {
479
480
  return new Promise(async (resolve, reject) => {
480
481
  try {
482
+ if (!this.auhorized) {
483
+ reject('not authorized.');
484
+ return;
485
+ };
486
+
481
487
  const sessionid = Uuid4();
482
488
  const postParams = {
483
489
  "destination": "Xbox",