homebridge-xbox-tv 3.3.7-beta.2 → 3.3.7

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/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  - After update to 2.x.x the plugin settings (xboxLiveId) need to be updated
11
11
  - After update to v3.0.0 RESTFull and MQTT config settings need to be updated
12
12
 
13
+ ## [3.3.7] - (02.06.2025)
14
+
15
+ ## Changes
16
+
17
+ - cleanup and optimizations of web api control
18
+
13
19
  ## [3.3.6] - (02.06.2025)
14
20
 
15
21
  ## Changes
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",
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
@@ -164,7 +164,7 @@ class XboxDevice extends EventEmitter {
164
164
  let set = false
165
165
  switch (key) {
166
166
  case 'Power':
167
- switch (this.webApiPowerOnOff) {
167
+ switch (this.webApiControl && this.webApiPowerOnOff) {
168
168
  case true:
169
169
  switch (value) {
170
170
  case true: //off
@@ -188,30 +188,30 @@ class XboxDevice extends EventEmitter {
188
188
  break;
189
189
  case 'App':
190
190
  const payload = [{ 'oneStoreProductId': value }];
191
- set = await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', payload);
191
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', payload);
192
192
  break;
193
193
  case 'Volume':
194
194
  switch (value) {
195
195
  case 'up': //Up
196
- set = await this.xboxWebApi.send('Volume', 'Up');
196
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Volume', 'Up');
197
197
  break;
198
198
  case 'down': //Down
199
- set = await this.xboxWebApi.send('Volume', 'Down');
199
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Volume', 'Down');
200
200
  break;
201
201
  }
202
202
  break;
203
203
  case 'Mute':
204
204
  switch (value) {
205
205
  case true: //Mute
206
- set = await this.xboxWebApi.send('Audio', 'Mute');
206
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Audio', 'Mute');
207
207
  break;
208
208
  case false: //Unmute;
209
- set = await this.xboxWebApi.send('Audio', 'Unmute');
209
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Audio', 'Unmute');
210
210
  break;
211
211
  }
212
212
  break;
213
213
  case 'RcControl':
214
- set = await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': value }]);
214
+ set = !this.webApiControl ? false : await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': value }]);
215
215
  break;
216
216
  default:
217
217
  this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);
@@ -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,11 @@ class XboxDevice extends EventEmitter {
434
427
  return inputIdentifier;
435
428
  })
436
429
  .onSet(async (activeIdentifier) => {
430
+ if (!this.webApiControl) {
431
+ this.emit('warn', `web api control not enabled`);
432
+ return;
433
+ }
434
+
437
435
  try {
438
436
  const input = this.inputsConfigured.find(input => input.identifier === activeIdentifier);
439
437
  const inputOneStoreProductId = input.oneStoreProductId;
@@ -573,21 +571,20 @@ class XboxDevice extends EventEmitter {
573
571
 
574
572
  this.televisionService.getCharacteristic(Characteristic.PowerModeSelection)
575
573
  .onSet(async (powerModeSelection) => {
574
+ if (!this.webApiControl) {
575
+ this.emit('warn', `web api control not enabled`);
576
+ return;
577
+ }
578
+
576
579
  try {
577
- let channelName;
578
- let command;
579
580
  switch (powerModeSelection) {
580
581
  case 0: //SHOW
581
- channelName = 'Shell';
582
- command = 'nexus';
582
+ await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': 'nexus' }]);
583
583
  break;
584
584
  case 1: //HIDE
585
- channelName = 'Shell';
586
- command = 'b';
585
+ await this.xboxWebApi.send('Shell', 'InjectKey', [{ 'keyType': 'b' }]);
587
586
  break;
588
587
  };
589
-
590
- await this.xboxWebApi.send(channelName, 'InjectKey', [{ 'keyType': command }]);
591
588
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Power Mode Selection: ${powerModeSelection === 0 ? 'SHOW' : 'HIDE'}`);
592
589
  } catch (error) {
593
590
  this.emit('warn', `set Power Mode Selection error: ${error}`);
@@ -614,21 +611,20 @@ class XboxDevice extends EventEmitter {
614
611
 
615
612
  this.speakerService.getCharacteristic(Characteristic.VolumeSelector)
616
613
  .onSet(async (volumeSelector) => {
614
+ if (!this.webApiControl) {
615
+ this.emit('warn', `web api control not enabled`);
616
+ return;
617
+ }
618
+
617
619
  try {
618
- let channelName;
619
- let command;
620
620
  switch (volumeSelector) {
621
621
  case 0: //Up
622
- channelName = 'Volume';
623
- command = 'Up';
622
+ await this.xboxWebApi.send('Volume', 'Up');
624
623
  break;
625
624
  case 1: //Down
626
- channelName = 'Volume';
627
- command = 'Down';
625
+ await this.xboxWebApi.send('Volume', 'Down');
628
626
  break;
629
627
  }
630
-
631
- await this.xboxWebApi.send(channelName, command);
632
628
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Volume Selector: ${volumeSelector ? 'Down' : 'UP'}`);
633
629
  } catch (error) {
634
630
  this.emit('warn', `set Volume Selector error: ${error}`);
@@ -650,21 +646,20 @@ class XboxDevice extends EventEmitter {
650
646
  return state;
651
647
  })
652
648
  .onSet(async (state) => {
649
+ if (!this.webApiControl) {
650
+ this.emit('warn', `web api control not enabled`);
651
+ return;
652
+ }
653
+
653
654
  try {
654
- let channelName;
655
- let command;
656
655
  switch (volumeSelector) {
657
656
  case 0: //Mute
658
- channelName = 'Audio';
659
- command = 'Mute';
657
+ await this.xboxWebApi.send('Audio', 'Mute');
660
658
  break;
661
659
  case 1: //Unmute
662
- channelName = 'Audio';
663
- command = 'Unmute';
660
+ await this.xboxWebApi.send('Audio', 'Unmute');
664
661
  break;
665
662
  }
666
-
667
- await this.xboxWebApi.send(channelName, command);
668
663
  const logInfo = this.disableLogInfo ? false : this.emit('info', `set Mute: ${state ? 'ON' : 'OFF'}`);
669
664
  } catch (error) {
670
665
  this.emit('warn', `set Mute error: ${error}`);
@@ -959,24 +954,24 @@ class XboxDevice extends EventEmitter {
959
954
  const send1 = this.power && state ? await this.xboxLocalApi.recordGameDvr() : false;
960
955
  break;
961
956
  case 4:
962
- const send2 = this.power && state ? await this.xboxWebApi.send('Power', 'Reboot') : false;
957
+ const send2 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Power', 'Reboot') : false;
963
958
  break;
964
959
  case 5:
965
960
  switch (buttonOneStoreProductId) {
966
961
  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;
962
+ const send3 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'GoHome') : false;
968
963
  break;
969
964
  case 'Television':
970
- const send4 = this.power && state ? await this.xboxWebApi.send('TV', 'ShowGuide') : false;
965
+ const send4 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('TV', 'ShowGuide') : false;
971
966
  break;
972
967
  case 'XboxGuide':
973
- const send5 = this.power && state ? await this.xboxWebApi.send('Shell', 'ShowGuideTab', [{ 'tabName': 'Guide' }]) : false;
968
+ const send5 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'ShowGuideTab', [{ 'tabName': 'Guide' }]) : false;
974
969
  break;
975
970
  case 'Not set': case 'Web api disabled':
976
971
  this.emit('info', `trying to launch App/Game with one store product id: ${buttonOneStoreProductId}`);
977
972
  break;
978
973
  default:
979
- const send6 = this.power && state ? await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', [{ 'oneStoreProductId': buttonOneStoreProductId }]) : false;
974
+ const send6 = this.webApiControl && this.power && state ? await this.xboxWebApi.send('Shell', 'ActivateApplicationWithOneStoreProductId', [{ 'oneStoreProductId': buttonOneStoreProductId }]) : false;
980
975
  break;
981
976
  }
982
977
  break;