homebridge-xbox-tv 3.3.7-beta.2 → 3.3.7-beta.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "3.3.7-beta.2",
4
+ "version": "3.3.7-beta.3",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -16,7 +16,7 @@ class XboxWebApi extends EventEmitter {
16
16
  this.enableDebugMode = config.enableDebugMode;
17
17
 
18
18
  //variables
19
- this.authorized = false;
19
+ this.consoleAuthorized = false;
20
20
  this.rmEnabled = false;
21
21
 
22
22
  const authConfig = {
@@ -50,7 +50,7 @@ class XboxWebApi extends EventEmitter {
50
50
  return false;
51
51
  };
52
52
  this.tokens = data.tokens;
53
- this.authorized = true;
53
+ this.consoleAuthorized = true;
54
54
 
55
55
  //check xbox live data
56
56
  try {
@@ -401,7 +401,7 @@ class XboxWebApi extends EventEmitter {
401
401
  }
402
402
 
403
403
  async send(commandType, command, payload) {
404
- if (!this.authorized || !this.rmEnabled) {
404
+ if (!this.consoleAuthorized || !this.rmEnabled) {
405
405
  this.emit('warn', `not authorized or remote management not enabled`);
406
406
  return;
407
407
  };
package/src/xboxdevice.js CHANGED
@@ -392,23 +392,16 @@ class XboxDevice extends EventEmitter {
392
392
  }
393
393
 
394
394
  try {
395
- let channelName;
396
- let command;
397
-
398
- switch (this.webApiPowerOnOff) {
395
+ switch (this.webApiControl && this.webApiPowerOnOff) {
399
396
  case true:
400
397
  switch (this.power) {
401
398
  case true: //off
402
- channelName = 'Power';
403
- command = 'TurnOff';
399
+ await this.xboxWebApi.send('Power', 'TurnOff');
404
400
  break;
405
401
  case false: //on
406
- channelName = 'Power';
407
- command = 'WakeUp';
402
+ await this.xboxWebApi.send('Power', 'WakeUp');
408
403
  break;
409
404
  }
410
-
411
- await this.xboxWebApi.send(channelName, command);
412
405
  break;
413
406
  case false:
414
407
  switch (this.power) {
@@ -434,6 +427,10 @@ class XboxDevice extends EventEmitter {
434
427
  return inputIdentifier;
435
428
  })
436
429
  .onSet(async (activeIdentifier) => {
430
+ if (!this.webApiControl) {
431
+ return;
432
+ }
433
+
437
434
  try {
438
435
  const input = this.inputsConfigured.find(input => input.identifier === activeIdentifier);
439
436
  const inputOneStoreProductId = input.oneStoreProductId;
@@ -573,21 +570,19 @@ class XboxDevice extends EventEmitter {
573
570
 
574
571
  this.televisionService.getCharacteristic(Characteristic.PowerModeSelection)
575
572
  .onSet(async (powerModeSelection) => {
573
+ if (!this.webApiControl) {
574
+ return;
575
+ }
576
+
576
577
  try {
577
- let channelName;
578
- let command;
579
578
  switch (powerModeSelection) {
580
579
  case 0: //SHOW
581
- channelName = 'Shell';
582
- command = 'nexus';
580
+ await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': 'nexus' }]);
583
581
  break;
584
582
  case 1: //HIDE
585
- channelName = 'Shell';
586
- command = 'b';
583
+ await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': 'b' }]);
587
584
  break;
588
585
  };
589
-
590
- await this.xboxWebApi.send(channelName, 'InjectKey', [{ 'keyType': command }]);
591
586
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Power Mode Selection: ${powerModeSelection === 0 ? 'SHOW' : 'HIDE'}`);
592
587
  } catch (error) {
593
588
  this.emit('warn', `set Power Mode Selection error: ${error}`);
@@ -614,21 +609,19 @@ class XboxDevice extends EventEmitter {
614
609
 
615
610
  this.speakerService.getCharacteristic(Characteristic.VolumeSelector)
616
611
  .onSet(async (volumeSelector) => {
612
+ if (!this.webApiControl) {
613
+ return;
614
+ }
615
+
617
616
  try {
618
- let channelName;
619
- let command;
620
617
  switch (volumeSelector) {
621
618
  case 0: //Up
622
- channelName = 'Volume';
623
- command = 'Up';
619
+ await this.xboxWebApi.send('Volume', 'Up');
624
620
  break;
625
621
  case 1: //Down
626
- channelName = 'Volume';
627
- command = 'Down';
622
+ await this.xboxWebApi.send('Volume', 'Down');
628
623
  break;
629
624
  }
630
-
631
- await this.xboxWebApi.send(channelName, command);
632
625
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Volume Selector: ${volumeSelector ? 'Down' : 'UP'}`);
633
626
  } catch (error) {
634
627
  this.emit('warn', `set Volume Selector error: ${error}`);
@@ -650,21 +643,19 @@ class XboxDevice extends EventEmitter {
650
643
  return state;
651
644
  })
652
645
  .onSet(async (state) => {
646
+ if (!this.webApiControl) {
647
+ return;
648
+ }
649
+
653
650
  try {
654
- let channelName;
655
- let command;
656
651
  switch (volumeSelector) {
657
652
  case 0: //Mute
658
- channelName = 'Audio';
659
- command = 'Mute';
653
+ await this.xboxWebApi.send('Audio', 'Mute');
660
654
  break;
661
655
  case 1: //Unmute
662
- channelName = 'Audio';
663
- command = 'Unmute';
656
+ await this.xboxWebApi.send('Audio', 'Unmute');
664
657
  break;
665
658
  }
666
-
667
- await this.xboxWebApi.send(channelName, command);
668
659
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Mute: ${state ? 'ON' : 'OFF'}`);
669
660
  } catch (error) {
670
661
  this.emit('warn', `set Mute error: ${error}`);
@@ -959,24 +950,24 @@ class XboxDevice extends EventEmitter {
959
950
  const send1 = this.power && state ? await this.xboxLocalApi.recordGameDvr() : false;
960
951
  break;
961
952
  case 4:
962
- const send2 = this.power && state ? await this.xboxWebApi.send('Power', 'Reboot') : false;
953
+ const send2 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Power', 'Reboot') : false;
963
954
  break;
964
955
  case 5:
965
956
  switch (buttonOneStoreProductId) {
966
957
  case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
967
- const send3 = this.power && state ? await this.xboxWebApi.send('Shell', 'GoHome') : false;
958
+ const send3 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'GoHome') : false;
968
959
  break;
969
960
  case 'Television':
970
- const send4 = this.power && state ? await this.xboxWebApi.send('TV', 'ShowGuide') : false;
961
+ const send4 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('TV', 'ShowGuide') : false;
971
962
  break;
972
963
  case 'XboxGuide':
973
- const send5 = this.power && state ? await this.xboxWebApi.send('Shell', 'ShowGuideTab', [{ 'tabName': 'Guide' }]) : false;
964
+ const send5 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'ShowGuideTab', [{ 'tabName': 'Guide' }]) : false;
974
965
  break;
975
966
  case 'Not set': case 'Web api disabled':
976
967
  this.emit('info', `trying to launch App/Game with one store product id: ${buttonOneStoreProductId}`);
977
968
  break;
978
969
  default:
979
- const send6 = this.power && state ? await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', [{ 'oneStoreProductId': buttonOneStoreProductId }]) : false;
970
+ const send6 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', [{ 'oneStoreProductId': buttonOneStoreProductId }]) : false;
980
971
  break;
981
972
  }
982
973
  break;