homebridge-xbox-tv 3.6.7 → 3.6.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/xboxdevice.js +45 -41
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "3.6.7",
4
+ "version": "3.6.8",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/xboxdevice.js CHANGED
@@ -437,47 +437,51 @@ class XboxDevice extends EventEmitter {
437
437
  })
438
438
  .onSet(async (activeIdentifier) => {
439
439
  try {
440
- const input = this.inputsConfigured.find(input => input.identifier === activeIdentifier);
441
- const inputOneStoreProductId = input.oneStoreProductId;
442
- const inputReference = input.reference;
443
- const inputName = input.name;
440
+ const input = this.inputsConfigured.find(i => i.identifier === activeIdentifier);
441
+ if (!input) {
442
+ this.emit('warn', `Input with identifier ${activeIdentifier} not found`);
443
+ return;
444
+ }
445
+
446
+ const { oneStoreProductId: oneStoreProductId, name: name, reference: reference } = input;
447
+
448
+ if (!this.power) {
449
+ for (let attempt = 0; attempt < 10; attempt++) {
450
+ await new Promise(resolve => setTimeout(resolve, 2000));
451
+ if (this.power && this.inputIdentifier !== activeIdentifier) {
452
+ this.televisionService.setCharacteristic(Characteristic.ActiveIdentifier, activeIdentifier);
453
+ break;
454
+ }
455
+ }
456
+ return;
457
+ }
444
458
 
445
459
  let channelName;
446
460
  let command;
447
461
  let payload;
448
- switch (this.power) {
449
- case false:
450
- for (let attempt = 0; attempt < 10; attempt++) {
451
- await new Promise(resolve => setTimeout(resolve, 2000));
452
- const setInput = this.power && this.inputIdentifier !== activeIdentifier ? this.televisionService.setCharacteristic(Characteristic.ActiveIdentifier, activeIdentifier) : false;
453
- }
462
+ switch (oneStoreProductId) {
463
+ case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
464
+ channelName = 'Shell';
465
+ command = 'GoHome';
454
466
  break;
455
- case true:
456
- switch (inputOneStoreProductId) {
457
- case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
458
- channelName = 'Shell';
459
- command = 'GoHome';
460
- break;
461
- case 'Television':
462
- channelName = 'TV';
463
- command = 'ShowGuide';
464
- break;
465
- case 'XboxGuide':
466
- channelName = 'Shell';
467
- command = 'ShowGuideTab';
468
- payload = [{ 'tabName': 'Guide' }];
469
- break;
470
- default:
471
- channelName = 'Shell';
472
- command = 'ActivateApplicationWithOneStoreProductId';
473
- payload = [{ 'oneStoreProductId': inputOneStoreProductId }];
474
- break;
475
- }
476
-
477
- await this.xboxWebApi.send(channelName, command, payload);
478
- const logInfo = this.disableLogInfo ? false : this.emit('info', `set Input: ${inputName}, Reference: ${inputReference}, Product Id: ${inputOneStoreProductId}`);
467
+ case 'Television':
468
+ channelName = 'TV';
469
+ command = 'ShowGuide';
470
+ break;
471
+ case 'XboxGuide':
472
+ channelName = 'Shell';
473
+ command = 'ShowGuideTab';
474
+ payload = [{ 'tabName': 'Guide' }];
475
+ break;
476
+ default:
477
+ channelName = 'Shell';
478
+ command = 'ActivateApplicationWithOneStoreProductId';
479
+ payload = [{ 'oneStoreProductId': oneStoreProductId }];
479
480
  break;
480
481
  }
482
+
483
+ await this.xboxWebApi.send(channelName, command, payload);
484
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `set Input: ${name}, Reference: ${reference}, Product Id: ${oneStoreProductId}`);
481
485
  } catch (error) {
482
486
  this.emit('warn', `set Input error: ${JSON.stringify(error, null, 2)}`);
483
487
  }
@@ -1084,6 +1088,13 @@ class XboxDevice extends EventEmitter {
1084
1088
  const input = this.inputsConfigured.find(input => input.reference === reference || input.titleId === titleId) ?? false;
1085
1089
  const inputIdentifier = input ? input.identifier : this.inputIdentifier;
1086
1090
 
1091
+ this.inputIdentifier = inputIdentifier;
1092
+ this.power = power;
1093
+ this.reference = reference;
1094
+ this.volume = volume;
1095
+ this.mute = mute;
1096
+ this.mediaState = mediaState;
1097
+
1087
1098
  //update characteristics
1088
1099
  if (this.televisionService) {
1089
1100
  this.televisionService
@@ -1162,13 +1173,6 @@ class XboxDevice extends EventEmitter {
1162
1173
  }
1163
1174
  }
1164
1175
 
1165
- this.inputIdentifier = inputIdentifier;
1166
- this.power = power;
1167
- this.reference = reference;
1168
- this.volume = volume;
1169
- this.mute = mute;
1170
- this.mediaState = mediaState;
1171
-
1172
1176
  if (!this.disableLogInfo) {
1173
1177
  const name = input ? input.name : reference;
1174
1178
  const productId = input ? input.oneStoreProductId : reference;