homebridge-xbox-tv 3.1.13 → 3.1.15

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 +57 -53
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "3.1.13",
4
+ "version": "3.1.15",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/xboxdevice.js CHANGED
@@ -170,10 +170,10 @@ class XboxDevice extends EventEmitter {
170
170
  this.emit('error', error);
171
171
  })
172
172
  .on('restFul', (path, data) => {
173
- this.emit('restFul', path, data)
173
+ const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
174
174
  })
175
175
  .on('mqtt', (topic, message) => {
176
- this.emit('mqtt', topic, message)
176
+ const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
177
177
  });
178
178
 
179
179
  //check authorization
@@ -312,64 +312,68 @@ class XboxDevice extends EventEmitter {
312
312
  try {
313
313
  //RESTFul server
314
314
  const restFulEnabled = this.restFul.enable || false;
315
- if (restFulEnabled && !this.restFulConnected) {
316
- this.restFul1 = new RestFul({
317
- port: this.restFul.port || 3000,
318
- debug: this.restFul.debug || false
319
- });
320
-
321
- this.restFul1.on('connected', (message) => {
322
- this.restFulConnected = true;
323
- this.emit('success', message);
324
- })
325
- .on('set', async (key, value) => {
326
- try {
327
- await this.setOverExternalIntegration('RESTFul', key, value);
328
- } catch (error) {
329
- this.emit('warn', `RESTFul set error: ${error}`);
330
- };
331
- })
332
- .on('debug', (debug) => {
333
- this.emit('debug', debug);
334
- })
335
- .on('error', (error) => {
336
- this.emit('warn', error);
315
+ if (restFulEnabled) {
316
+ if (!this.restFulConnected) {
317
+ this.restFul1 = new RestFul({
318
+ port: this.restFul.port || 3000,
319
+ debug: this.restFul.debug || false
337
320
  });
321
+
322
+ this.restFul1.on('connected', (message) => {
323
+ this.restFulConnected = true;
324
+ this.emit('success', message);
325
+ })
326
+ .on('set', async (key, value) => {
327
+ try {
328
+ await this.setOverExternalIntegration('RESTFul', key, value);
329
+ } catch (error) {
330
+ this.emit('warn', `RESTFul set error: ${error}`);
331
+ };
332
+ })
333
+ .on('debug', (debug) => {
334
+ this.emit('debug', debug);
335
+ })
336
+ .on('error', (error) => {
337
+ this.emit('warn', error);
338
+ });
339
+ }
338
340
  }
339
341
 
340
342
  //mqtt client
341
343
  const mqttEnabled = this.mqtt.enable || false;
342
- if (mqttEnabled && !this.mqttConnected) {
343
- this.mqtt1 = new Mqtt({
344
- host: this.mqtt.host,
345
- port: this.mqtt.port || 1883,
346
- clientId: this.mqtt.clientId || `xbox_${Math.random().toString(16).slice(3)}`,
347
- prefix: `${this.mqtt.prefix}/${device.name}`,
348
- user: this.mqtt.user,
349
- passwd: this.mqtt.passwd,
350
- debug: this.mqtt.debug || false
351
- });
352
-
353
- this.mqtt1.on('connected', (message) => {
354
- this.mqttConnected = true;
355
- this.emit('success', message);
356
- })
357
- .on('subscribed', (message) => {
344
+ if (mqttEnabled) {
345
+ if (!this.mqttConnected) {
346
+ this.mqtt1 = new Mqtt({
347
+ host: this.mqtt.host,
348
+ port: this.mqtt.port || 1883,
349
+ clientId: this.mqtt.clientId || `xbox_${Math.random().toString(16).slice(3)}`,
350
+ prefix: `${this.mqtt.prefix}/${device.name}`,
351
+ user: this.mqtt.user,
352
+ passwd: this.mqtt.passwd,
353
+ debug: this.mqtt.debug || false
354
+ });
355
+
356
+ this.mqtt1.on('connected', (message) => {
357
+ this.mqttConnected = true;
358
358
  this.emit('success', message);
359
359
  })
360
- .on('set', async (key, value) => {
361
- try {
362
- await this.setOverExternalIntegration('MQTT', key, value);
363
- } catch (error) {
364
- this.emit('warn', `MQTT set error: ${error}.`);
365
- };
366
- })
367
- .on('debug', (debug) => {
368
- this.emit('debug', debug);
369
- })
370
- .on('error', (error) => {
371
- this.emit('warn', error);
372
- });
360
+ .on('subscribed', (message) => {
361
+ this.emit('success', message);
362
+ })
363
+ .on('set', async (key, value) => {
364
+ try {
365
+ await this.setOverExternalIntegration('MQTT', key, value);
366
+ } catch (error) {
367
+ this.emit('warn', `MQTT set error: ${error}.`);
368
+ };
369
+ })
370
+ .on('debug', (debug) => {
371
+ this.emit('debug', debug);
372
+ })
373
+ .on('error', (error) => {
374
+ this.emit('warn', error);
375
+ });
376
+ };
373
377
  };
374
378
  } catch (error) {
375
379
  this.emit('warn', `External integration start error: ${error.message || error}.`);