homebridge-xbox-tv 3.7.5 → 3.7.6

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
@@ -47,7 +47,8 @@ class XboxPlatform {
47
47
  const disableLogSuccess = device.disableLogSuccess || false;
48
48
  const disableLogWarn = device.disableLogWarn || false;
49
49
  const disableLogError = device.disableLogError || false;
50
- const debug = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, did finish launching.`);
50
+ if (enableDebugMode) log.info(`Device: ${host} ${deviceName}, did finish launching.`);
51
+
51
52
  const config = {
52
53
  ...device,
53
54
  xboxLiveId: 'removed',
@@ -58,7 +59,7 @@ class XboxPlatform {
58
59
  passwd: 'removed'
59
60
  }
60
61
  }
61
- const debug1 = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(config, null, 2)}.`);
62
+ if (enableDebugMode) log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(config, null, 2)}.`);
62
63
 
63
64
  //check files exists, if not then create it
64
65
  const postFix = host.split('.').join('');
@@ -84,58 +85,58 @@ class XboxPlatform {
84
85
  }
85
86
  });
86
87
  } catch (error) {
87
- const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}.`);
88
+ if (!disableLogError) log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}.`);
88
89
  return;
89
90
  }
90
91
 
91
92
  //xbox device
92
93
  try {
93
94
  const xboxDevice = new XboxDevice(api, device, authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile)
94
- .on('publishAccessory', (accessory) => {
95
- api.publishExternalAccessories(PluginName, [accessory]);
96
- const emitLog = disableLogSuccess ? false : log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
97
- })
98
95
  .on('devInfo', (devInfo) => {
99
- const emitLog = disableLogDeviceInfo ? false : log.info(devInfo);
96
+ if (!disableLogDeviceInfo) log.info(devInfo);
100
97
  })
101
98
  .on('success', (success) => {
102
- const emitLog = disableLogSuccess ? false : log.success(`Device: ${host} ${deviceName}, ${success}.`);
99
+ if (!disableLogSuccess) log.success(`Device: ${host} ${deviceName}, ${success}.`);
103
100
  })
104
101
  .on('info', (info) => {
105
- const emitLog = disableLogInfo ? false : log.info(`Device: ${host} ${deviceName}, ${info}.`);
102
+ if (!disableLogInfo) log.info(`Device: ${host} ${deviceName}, ${info}.`);
106
103
  })
107
104
  .on('debug', (debug) => {
108
- const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
105
+ if (enableDebugMode) log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
109
106
  })
110
107
  .on('warn', (warn) => {
111
- const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
108
+ if (!disableLogWarn) log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
112
109
  })
113
110
  .on('error', (error) => {
114
- const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}.`);
111
+ if (!disableLogError) log.error(`Device: ${host} ${deviceName}, ${error}.`);
115
112
  });
116
113
 
117
114
  //create impulse generator
118
115
  const impulseGenerator = new ImpulseGenerator();
119
116
  impulseGenerator.on('start', async () => {
120
117
  try {
121
- const startDone = await xboxDevice.start();
122
- const stopImpulseGenerator = startDone ? await impulseGenerator.stop() : false;
123
-
124
- //start xbox device impulse generator
125
- const startImpulseGenerator = startDone ? await xboxDevice.startImpulseGenerator() : false;
118
+ const accessory = await xboxDevice.start();
119
+ if (accessory) {
120
+ api.publishExternalAccessories(PluginName, [accessory]);
121
+ if (!disableLogSuccess) log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
122
+
123
+ await impulseGenerator.stop();
124
+ await xboxDevice.startImpulseGenerator();
125
+ }
126
126
  } catch (error) {
127
- const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
127
+ if (!disableLogError) log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
128
128
  }
129
129
  }).on('state', (state) => {
130
- const emitLog = !enableDebugMode ? false : state ? log.info(`Device: ${host} ${deviceName}, Start impulse generator started.`) : log.info(`Device: ${host} ${deviceName}, Start impulse generator stopped.`);
130
+ if (enableDebugMode) state ? log.info(`Device: ${host} ${deviceName}, Start impulse generator started.`) : log.info(`Device: ${host} ${deviceName}, Start impulse generator stopped.`);
131
131
  });
132
132
 
133
133
  //start impulse generator
134
134
  await impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
135
135
  } catch (error) {
136
- const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
136
+ if (!disableLogError) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
137
137
  }
138
- await new Promise(resolve => setTimeout(resolve, 500));
138
+
139
+ await new Promise(resolve => setTimeout(resolve, 300));
139
140
  }
140
141
  });
141
142
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "3.7.5",
4
+ "version": "3.7.6",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/xboxdevice.js CHANGED
@@ -107,7 +107,6 @@ class XboxDevice extends EventEmitter {
107
107
  this.sensorsInputsServices = [];
108
108
  this.buttonsServices = [];
109
109
  this.inputIdentifier = 1;
110
- this.startPrepareAccessory = true;
111
110
  this.power = false;
112
111
  this.volume = 0;
113
112
  this.mute = false;
@@ -1075,10 +1074,10 @@ class XboxDevice extends EventEmitter {
1075
1074
  this.emit('error', error);
1076
1075
  })
1077
1076
  .on('restFul', (path, data) => {
1078
- const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
1077
+ if (this.restFulConnected) this.restFul1.update(path, data);
1079
1078
  })
1080
1079
  .on('mqtt', (topic, message) => {
1081
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
1080
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
1082
1081
  });
1083
1082
 
1084
1083
  //check authorization
@@ -1228,10 +1227,10 @@ class XboxDevice extends EventEmitter {
1228
1227
  this.emit('error', error);
1229
1228
  })
1230
1229
  .on('restFul', (path, data) => {
1231
- const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
1230
+ if (this.restFulConnected) this.restFul1.update(path, data);
1232
1231
  })
1233
1232
  .on('mqtt', (topic, message) => {
1234
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
1233
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
1235
1234
  });
1236
1235
 
1237
1236
  //connect to local api
@@ -1241,19 +1240,14 @@ class XboxDevice extends EventEmitter {
1241
1240
  }
1242
1241
 
1243
1242
  //start external integrations
1244
- const startExternalIntegrations = this.mqtt.enable ? await this.externalIntegrations() : false;
1243
+ if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
1245
1244
 
1246
1245
  //prepare data for accessory
1247
1246
  await this.prepareDataForAccessory();
1248
1247
 
1249
1248
  //prepare accessory
1250
- if (this.startPrepareAccessory) {
1251
- const accessory = await this.prepareAccessory();
1252
- this.emit('publishAccessory', accessory);
1253
- this.startPrepareAccessory = false;
1254
- }
1255
-
1256
- return true;
1249
+ const accessory = await this.prepareAccessory();
1250
+ return accessory;
1257
1251
  } catch (error) {
1258
1252
  throw new Error(`Start error: ${error}`);
1259
1253
  }