homebridge-xbox-tv 4.4.1 → 4.4.3
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 +15 -0
- package/index.js +3 -1
- package/package.json +3 -3
- package/src/localApi/xboxlocalapi.js +9 -24
- package/src/mqtt.js +3 -0
- package/src/restful.js +19 -3
- package/src/webApi/xboxwebapi.js +8 -8
- package/src/xboxdevice.js +3 -7
- package/src/reachability.js +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
18
18
|
- For plugin < v4.1.0 use Homebridge UI <= v5.5.0
|
|
19
19
|
- For plugin >= v4.1.0 use Homebridge UI >= v5.13.0
|
|
20
20
|
|
|
21
|
+
## [4.4.3] - (18.11.2026)
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
|
|
25
|
+
- fixed: the RESTFul server tries again every 10 seconds when its port cannot be opened at the start of the plugin, a server that starts later is used by the running device
|
|
26
|
+
- fixed: MQTT does not queue the messages while the broker is not connected, the plugin stops to publish when the connection to the broker is lost and starts again after it is connected
|
|
27
|
+
- updated: dependencies, axios and @homebridge/plugin-ui-utils to the latest versions
|
|
28
|
+
|
|
29
|
+
## [4.4.2] - (14.11.2026)
|
|
30
|
+
|
|
31
|
+
### Changes
|
|
32
|
+
|
|
33
|
+
- fixed: the console was shown as not responding in the Home app when it did not answer the ping, for example in the energy saving mode, the change of `4.4.0` is reverted, the state of the console is set by the connection with it again
|
|
34
|
+
- changed: removed the word console from the log messages
|
|
35
|
+
|
|
21
36
|
## [4.4.1] - (12.11.2026)
|
|
22
37
|
|
|
23
38
|
### Changes
|
package/index.js
CHANGED
|
@@ -128,9 +128,11 @@ class XboxPlatform {
|
|
|
128
128
|
logWarn: logLevel.warn,
|
|
129
129
|
logDebug: logLevel.debug,
|
|
130
130
|
})
|
|
131
|
-
.
|
|
131
|
+
.on('connected', (msg) => {
|
|
132
132
|
clearTimeout(timer);
|
|
133
133
|
restFulConnected = true;
|
|
134
|
+
// The server can start later than the plugin, when the port was busy, the running device uses it from then
|
|
135
|
+
if (activeDevice) activeDevice.restFulConnected = true;
|
|
134
136
|
if (logLevel.success) log.success(`Device: ${host} ${name}, ${msg}`);
|
|
135
137
|
resolve();
|
|
136
138
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Xbox TV",
|
|
3
3
|
"name": "homebridge-xbox-tv",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.3",
|
|
5
5
|
"description": "Homebridge plugin to control Xbox game consoles.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"node": "^20 || ^22 || ^24 || ^25 || ^26"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@homebridge/plugin-ui-utils": "^2.
|
|
39
|
+
"@homebridge/plugin-ui-utils": "^2.3.0",
|
|
40
40
|
"mqtt": "^5.16.1",
|
|
41
41
|
"hex-to-binary": "^1.0.1",
|
|
42
42
|
"uuid": "^14.0.3",
|
|
43
43
|
"express": "^5.3.0",
|
|
44
|
-
"axios": "^1.21.
|
|
44
|
+
"axios": "^1.21.1"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|
|
47
47
|
"homebridge",
|
|
@@ -26,8 +26,6 @@ class XboxLocalApi extends EventEmitter {
|
|
|
26
26
|
this.mqttEnabled = mqttEnabled || false;
|
|
27
27
|
|
|
28
28
|
this.connected = false;
|
|
29
|
-
this.reachable = true;
|
|
30
|
-
this.lastPingOk = Date.now();
|
|
31
29
|
this.pingOnline = false;
|
|
32
30
|
this.pinging = false;
|
|
33
31
|
this.power = false;
|
|
@@ -55,13 +53,13 @@ class XboxLocalApi extends EventEmitter {
|
|
|
55
53
|
// the presence of the console in the network is checked all the time, also when the plugin is connected
|
|
56
54
|
const online = await this.checkReachability();
|
|
57
55
|
if (this.connected || this.connecting) return;
|
|
58
|
-
if (this.logDebug) this.emit('debug', `Plugin send heartbeat
|
|
56
|
+
if (this.logDebug) this.emit('debug', `Plugin send heartbeat`);
|
|
59
57
|
|
|
60
58
|
if (!online) {
|
|
61
59
|
return;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
if (this.logDebug) this.emit('debug', `Plugin received heartbeat
|
|
62
|
+
if (this.logDebug) this.emit('debug', `Plugin received heartbeat`);
|
|
65
63
|
|
|
66
64
|
this.connecting = true;
|
|
67
65
|
try {
|
|
@@ -83,31 +81,18 @@ class XboxLocalApi extends EventEmitter {
|
|
|
83
81
|
});
|
|
84
82
|
};
|
|
85
83
|
|
|
86
|
-
// The
|
|
84
|
+
// The presence of the console in the network, the state of the console is set by the connection with it
|
|
87
85
|
async checkReachability() {
|
|
88
86
|
if (this.pinging) return false;
|
|
89
87
|
|
|
90
88
|
this.pinging = true;
|
|
91
89
|
try {
|
|
92
90
|
const state = await this.functions.ping(this.host);
|
|
93
|
-
const now = Date.now();
|
|
94
91
|
this.pingOnline = state.online;
|
|
95
92
|
|
|
96
|
-
if (state.online) {
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
this.onlineEmitted = true;
|
|
100
|
-
this.emit('online');
|
|
101
|
-
}
|
|
102
|
-
if (!this.reachable) {
|
|
103
|
-
this.reachable = true;
|
|
104
|
-
this.emit('success', `reachable again`);
|
|
105
|
-
this.emit('reachable', true);
|
|
106
|
-
}
|
|
107
|
-
} else if (this.reachable && now - this.lastPingOk >= 20000) {
|
|
108
|
-
this.reachable = false;
|
|
109
|
-
this.emit('warn', `not reachable`);
|
|
110
|
-
this.emit('reachable', false);
|
|
93
|
+
if (state.online && !this.onlineEmitted) {
|
|
94
|
+
this.onlineEmitted = true;
|
|
95
|
+
this.emit('online');
|
|
111
96
|
}
|
|
112
97
|
|
|
113
98
|
return state.online;
|
|
@@ -447,12 +432,12 @@ class XboxLocalApi extends EventEmitter {
|
|
|
447
432
|
if (!this.acknowledgeInterval) {
|
|
448
433
|
this.acknowledgeInterval = setInterval(async () => {
|
|
449
434
|
const elapsed = (Date.now() - this.heartBeatStartTime) / 1000;
|
|
450
|
-
if (this.logDebug) this.emit('debug', `
|
|
435
|
+
if (this.logDebug) this.emit('debug', `Last seen: ${elapsed.toFixed(1)}s ago`);
|
|
451
436
|
|
|
452
437
|
if (elapsed >= 14) {
|
|
453
438
|
clearInterval(this.acknowledgeInterval);
|
|
454
439
|
this.acknowledgeInterval = null;
|
|
455
|
-
if (this.logDebug) this.emit('debug', `
|
|
440
|
+
if (this.logDebug) this.emit('debug', `Inactivity timeout, disconnecting`);
|
|
456
441
|
// Close socket first so on('close') triggers updateState().
|
|
457
442
|
// Calling updateState() directly would null this.socket before
|
|
458
443
|
// close(), causing the old socket to leak in the OS.
|
|
@@ -467,7 +452,7 @@ class XboxLocalApi extends EventEmitter {
|
|
|
467
452
|
if (Math.round(elapsed) % 5 === 0 && Math.round(elapsed) > 0) {
|
|
468
453
|
try {
|
|
469
454
|
const pingResult = await this.functions.ping(this.host);
|
|
470
|
-
if (this.logDebug) this.emit('debug', `Ping ${pingResult.online ? 'OK' : 'failed'}
|
|
455
|
+
if (this.logDebug) this.emit('debug', `Ping ${pingResult.online ? 'OK' : 'failed'}`);
|
|
471
456
|
} catch (error) {
|
|
472
457
|
if (this.logError) this.emit('error', `Ping error: ${error}`);
|
|
473
458
|
}
|
package/src/mqtt.js
CHANGED
|
@@ -94,7 +94,10 @@ class Mqtt extends EventEmitter {
|
|
|
94
94
|
if (config.logDebug) this.emit('debug', 'MQTT Reconnecting...');
|
|
95
95
|
})
|
|
96
96
|
.on('close', () => {
|
|
97
|
+
// The broker is gone, the plugin stops to publish until it is connected again, the client would only queue the messages
|
|
98
|
+
const wasConnected = this.connected;
|
|
97
99
|
this.connected = false;
|
|
100
|
+
if (wasConnected) this.emit('offline');
|
|
98
101
|
if (!hasConnected && !warnedStalled && Date.now() - startTime > 30000) {
|
|
99
102
|
warnedStalled = true;
|
|
100
103
|
this.emit('warn', `MQTT has not connected after 30s of retries using protocol v${protocolVersion}. Check broker address, credentials, and whether the broker supports this MQTT protocol version.`);
|
package/src/restful.js
CHANGED
|
@@ -126,15 +126,31 @@ class RestFul extends EventEmitter {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
// Start the server
|
|
129
|
-
this.
|
|
130
|
-
this.emit('connected', `RESTful started on port: ${this.port}`);
|
|
131
|
-
});
|
|
129
|
+
this.listen(app);
|
|
132
130
|
} catch (error) {
|
|
133
131
|
if (this.logWarn) this.emit('warn', `RESTful Connect error: ${error}`);
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
134
|
|
|
135
|
+
// When the port cannot be opened, for example it is still used after a restart, the server tries again until it starts
|
|
136
|
+
listen(app) {
|
|
137
|
+
this.server = app.listen(this.port);
|
|
138
|
+
const server = this.server;
|
|
139
|
+
server.once('listening', () => {
|
|
140
|
+
this.listenWarned = false;
|
|
141
|
+
this.emit('connected', `RESTful started on port: ${this.port}`);
|
|
142
|
+
});
|
|
143
|
+
server.on('error', (error) => {
|
|
144
|
+
if (this.closed) return;
|
|
145
|
+
if (this.logWarn && !this.listenWarned) this.emit('warn', `RESTful cannot start on port: ${this.port}, ${error.code ?? error}, trying again every 10 seconds`);
|
|
146
|
+
this.listenWarned = true;
|
|
147
|
+
server.close();
|
|
148
|
+
setTimeout(() => this.listen(app), 10000).unref?.();
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
137
152
|
close() {
|
|
153
|
+
this.closed = true;
|
|
138
154
|
if (this.server) {
|
|
139
155
|
this.server.close();
|
|
140
156
|
this.server = null;
|
package/src/webApi/xboxwebapi.js
CHANGED
|
@@ -106,18 +106,18 @@ class XboxWebApi extends EventEmitter {
|
|
|
106
106
|
async consolesList() {
|
|
107
107
|
try {
|
|
108
108
|
const { data } = await this.axiosInstance.get('/lists/devices?queryCurrentDevice=false&includeStorageDevices=true');
|
|
109
|
-
if (this.logDebug) this.emit('debug', `
|
|
109
|
+
if (this.logDebug) this.emit('debug', `List data: ${JSON.stringify(data, null, 2)}`);
|
|
110
110
|
|
|
111
111
|
const status = data.status?.errorCode === 'OK';
|
|
112
112
|
const error = data.status?.errorMessage;
|
|
113
113
|
if (!status) {
|
|
114
|
-
if (this.logDebug) this.emit('debug', `
|
|
114
|
+
if (this.logDebug) this.emit('debug', `List data error: ${error}`);
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
const console = data.result.find(c => c.id === this.liveId);
|
|
119
119
|
if (!console) {
|
|
120
|
-
if (this.logWarn) this.emit('warn', `
|
|
120
|
+
if (this.logWarn) this.emit('warn', `Live ID ${this.liveId} not found on server`);
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -143,7 +143,7 @@ class XboxWebApi extends EventEmitter {
|
|
|
143
143
|
}))
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
if (!obj.remoteManagementEnabled && this.logWarn) this.emit('warn', `
|
|
146
|
+
if (!obj.remoteManagementEnabled && this.logWarn) this.emit('warn', `Live ID ${this.liveId} remote management not enabled`);
|
|
147
147
|
this.rmEnabled = obj.remoteManagementEnabled;
|
|
148
148
|
|
|
149
149
|
if (this.restFulEnabled) this.emit('restFul', 'consoleslist', data);
|
|
@@ -151,7 +151,7 @@ class XboxWebApi extends EventEmitter {
|
|
|
151
151
|
|
|
152
152
|
return true;
|
|
153
153
|
} catch (error) {
|
|
154
|
-
throw new Error(`
|
|
154
|
+
throw new Error(`List error: ${error.message}`, { cause: error });
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -159,7 +159,7 @@ class XboxWebApi extends EventEmitter {
|
|
|
159
159
|
try {
|
|
160
160
|
const url = `/consoles/${this.liveId}`;
|
|
161
161
|
const { data } = await this.axiosInstance.get(url);
|
|
162
|
-
if (this.logDebug) this.emit('debug', `
|
|
162
|
+
if (this.logDebug) this.emit('debug', `Status data: ${JSON.stringify(data, null, 2)}`);
|
|
163
163
|
|
|
164
164
|
const status = {
|
|
165
165
|
id: data.id,
|
|
@@ -180,7 +180,7 @@ class XboxWebApi extends EventEmitter {
|
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
if (!status.status) {
|
|
183
|
-
if (this.logDebug) this.emit('debug', `
|
|
183
|
+
if (this.logDebug) this.emit('debug', `Status error: ${status.error}`);
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -191,7 +191,7 @@ class XboxWebApi extends EventEmitter {
|
|
|
191
191
|
|
|
192
192
|
return true;
|
|
193
193
|
} catch (error) {
|
|
194
|
-
throw new Error(`
|
|
194
|
+
throw new Error(`Status error: ${error.message}`, { cause: error });
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
package/src/xboxdevice.js
CHANGED
|
@@ -2,7 +2,6 @@ import EventEmitter from 'events';
|
|
|
2
2
|
import XboxWebApi from './webApi/xboxwebapi.js';
|
|
3
3
|
import XboxLocalApi from './localApi/xboxlocalapi.js';
|
|
4
4
|
import Functions from './functions.js';
|
|
5
|
-
import { applyReachability } from './reachability.js';
|
|
6
5
|
import HaDiscovery from './hadiscovery.js';
|
|
7
6
|
import AppIcons from './appicons.js';
|
|
8
7
|
import { DefaultInputs, WebApi } from './constants.js';
|
|
@@ -19,8 +18,6 @@ class XboxDevice extends EventEmitter {
|
|
|
19
18
|
Categories = api.hap.Categories;
|
|
20
19
|
Encode = api.hap.encode;
|
|
21
20
|
AccessoryUUID = api.hap.uuid;
|
|
22
|
-
this.hap = api.hap;
|
|
23
|
-
this.reachable = true;
|
|
24
21
|
|
|
25
22
|
//device configuration
|
|
26
23
|
this.device = device;
|
|
@@ -60,6 +57,7 @@ class XboxDevice extends EventEmitter {
|
|
|
60
57
|
// The broker may come online after the start or restart, the device then publishes again
|
|
61
58
|
this.haReady = false;
|
|
62
59
|
this.mqtt1?.on('online', () => this.mqttOnline().catch((error) => this.emit('warn', `MQTT online error: ${error}`)));
|
|
60
|
+
this.mqtt1?.on('offline', () => { this.mqttConnected = false; });
|
|
63
61
|
this.functions = new Functions();
|
|
64
62
|
|
|
65
63
|
//sensors
|
|
@@ -970,7 +968,7 @@ class XboxDevice extends EventEmitter {
|
|
|
970
968
|
}
|
|
971
969
|
|
|
972
970
|
if (!this.power) {
|
|
973
|
-
if (this.logWarn) this.emit('warn', `
|
|
971
|
+
if (this.logWarn) this.emit('warn', `power is off`);
|
|
974
972
|
return;
|
|
975
973
|
}
|
|
976
974
|
|
|
@@ -1015,8 +1013,6 @@ class XboxDevice extends EventEmitter {
|
|
|
1015
1013
|
}
|
|
1016
1014
|
}
|
|
1017
1015
|
|
|
1018
|
-
applyReachability(accessory, this.hap, () => this.reachable);
|
|
1019
|
-
|
|
1020
1016
|
return accessory;
|
|
1021
1017
|
} catch (error) {
|
|
1022
1018
|
throw new Error(error)
|
|
@@ -1033,6 +1029,7 @@ class XboxDevice extends EventEmitter {
|
|
|
1033
1029
|
if (!mqtt1) return;
|
|
1034
1030
|
|
|
1035
1031
|
this.mqtt1.on('online', () => this.mqttOnline().catch((error) => this.emit('warn', `MQTT online error: ${error}`)));
|
|
1032
|
+
this.mqtt1.on('offline', () => { this.mqttConnected = false; });
|
|
1036
1033
|
if (mqttConnected) await this.mqttOnline();
|
|
1037
1034
|
}
|
|
1038
1035
|
|
|
@@ -1170,7 +1167,6 @@ class XboxDevice extends EventEmitter {
|
|
|
1170
1167
|
|
|
1171
1168
|
// BŁ4 FIX: pass restFulEnabled/mqttEnabled booleans, not channelsFile string
|
|
1172
1169
|
this.xboxLocalApi = new XboxLocalApi(this.device, this.authTokenFile, this.devInfoFile, restFulEnabled, mqttEnabled)
|
|
1173
|
-
.on('reachable', (reachable) => { this.reachable = reachable; })
|
|
1174
1170
|
.on('online', async () => {
|
|
1175
1171
|
try {
|
|
1176
1172
|
await this.onConsoleOnline?.();
|
package/src/reachability.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// While the device cannot be reached every read of the accessory fails with a communication error, so the Home app shows the accessory
|
|
2
|
-
// as not responding and decides itself what to do with it. The plugin does not pretend any state of the device.
|
|
3
|
-
export const applyReachability = (accessory, hap, isReachable) => {
|
|
4
|
-
for (const service of accessory.services) {
|
|
5
|
-
for (const characteristic of service.characteristics) {
|
|
6
|
-
const handler = characteristic.getHandler;
|
|
7
|
-
if (typeof handler !== 'function') continue;
|
|
8
|
-
|
|
9
|
-
characteristic.getHandler = async (...args) => {
|
|
10
|
-
if (!isReachable()) throw new hap.HapStatusError(hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
11
|
-
return handler.apply(characteristic, args);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|