Skip to content

Commit

Permalink
fix mqtt and restful know issues
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Aug 15, 2024
1 parent 6ae10a5 commit 0cd569b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Xbox TV",
"name": "homebridge-xbox-tv",
"version": "3.0.0",
"version": "3.0.1",
"description": "Homebridge plugin to control Xbox game consoles.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
27 changes: 16 additions & 11 deletions src/xboxdevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ class XboxDevice extends EventEmitter {
this.volumeControlName = device.volumeControlName || 'Volume';

//external integration
//restRul
const restFul = device.restFul ?? {};
const restFulEnabled = restFul.enable || false;
this.restFulConnected = false;

//mqtt
const mqtt = device.restFul ?? {};
const mqttEnabled = mqtt.enable || false;
this.mqttConnected = false;

//accessory services
Expand Down Expand Up @@ -313,11 +320,10 @@ class XboxDevice extends EventEmitter {
})
.on('prepareAccessory', async () => {
//RESTFul server
const restFulEnabled = device.restFul.enable || false;
if (restFulEnabled) {
this.restFul = new RestFul({
port: device.restFul.port || 3000,
debug: device.restFul.debug || false
port: restFul.port || 3000,
debug: restFul.debug || false
});

this.restFul.on('connected', (message) => {
Expand All @@ -333,16 +339,15 @@ class XboxDevice extends EventEmitter {
}

//mqtt client
const mqttEnabled = device.mqtt.enable || false;
if (mqttEnabled) {
this.mqtt = new Mqtt({
host: device.mqtt.host,
port: device.mqtt.port || 1883,
clientId: device.mqtt.clientId || `xbox_${Math.random().toString(16).slice(3)}`,
prefix: `${device.mqtt.prefix}/${device.name}`,
user: device.mqtt.user,
passwd: device.mqtt.passwd,
debug: device.mqtt.debug || false
host: mqtt.host,
port: mqtt.port || 1883,
clientId: mqtt.clientId || `xbox_${Math.random().toString(16).slice(3)}`,
prefix: `${mqtt.prefix}/${device.name}`,
user: mqtt.user,
passwd: mqtt.passwd,
debug: mqtt.debug || false
});

this.mqtt.on('connected', (message) => {
Expand Down

0 comments on commit 0cd569b

Please sign in to comment.