homebridge-xbox-tv 4.4.0 → 4.4.1

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 CHANGED
@@ -18,6 +18,13 @@ 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.1] - (12.11.2026)
22
+
23
+ ### Changes
24
+
25
+ - changed: the log of a console that cannot be reached shows only `not reachable` and `reachable again`
26
+ - changed: MQTT and RESTFul start when the console answers the ping for the first time, and they do not depend on the HomeKit accessory, when the accessory cannot be created the console is still controlled over MQTT and RESTFul
27
+
21
28
  ## [4.4.0] - (12.11.2026)
22
29
 
23
30
  ### Changes
package/index.js CHANGED
@@ -107,83 +107,88 @@ class XboxPlatform {
107
107
  return;
108
108
  }
109
109
 
110
- // Create RestFul and MQTT once — before the retry loop — so the port/connection
111
- // is established a single time and survives across all connect attempts.
112
110
  // The 'set' handler uses activeDevice so it always routes to the current instance.
113
111
  let activeDevice = null;
114
- let restFul1 = null;
115
- let restFulConnected = false;
116
- if (device.restFul?.enable) {
117
- try {
118
- await new Promise((resolve) => {
119
- const timer = setTimeout(resolve, 5000);
120
- restFul1 = new RestFul({
121
- port: device.restFul.port || 3000,
122
- token: device.restFul.token,
123
- logWarn: logLevel.warn,
124
- logDebug: logLevel.debug,
125
- })
126
- .once('connected', (msg) => {
127
- clearTimeout(timer);
128
- restFulConnected = true;
129
- if (logLevel.success) log.success(`Device: ${host} ${name}, ${msg}`);
130
- resolve();
131
- })
132
- .on('set', async (key, value) => {
133
- try {
134
- if (activeDevice) await activeDevice.setOverExternalIntegration('RESTFul', key, value);
135
- } catch (error) {
136
- if (logLevel.warn) log.warn(`Device: ${host} ${name}, RESTFul set error: ${error.message ?? error}`);
137
- }
112
+ // RestFul and MQTT are created once, when the console answers the ping for the first time, so nothing
113
+ // is started or published while the console is not reachable
114
+ let integrations = null;
115
+ const startIntegrations = () => (integrations ??= connectIntegrations());
116
+ const connectIntegrations = async () => {
117
+ let restFul1 = null;
118
+ let restFulConnected = false;
119
+ let mqtt1 = null;
120
+ let mqttConnected = false;
121
+ if (device.restFul?.enable) {
122
+ try {
123
+ await new Promise((resolve) => {
124
+ const timer = setTimeout(resolve, 5000);
125
+ restFul1 = new RestFul({
126
+ port: device.restFul.port || 3000,
127
+ token: device.restFul.token,
128
+ logWarn: logLevel.warn,
129
+ logDebug: logLevel.debug,
138
130
  })
139
- .on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${name}, debug: ${msg}`))
140
- .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${name}, ${msg}`))
141
- .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${name}, ${msg}`));
142
- });
143
- } catch (error) {
144
- if (logLevel.warn) log.warn(`Device: ${host} ${name}, RESTFul start error: ${error.message ?? error}`);
131
+ .once('connected', (msg) => {
132
+ clearTimeout(timer);
133
+ restFulConnected = true;
134
+ if (logLevel.success) log.success(`Device: ${host} ${name}, ${msg}`);
135
+ resolve();
136
+ })
137
+ .on('set', async (key, value) => {
138
+ try {
139
+ if (activeDevice) await activeDevice.setOverExternalIntegration('RESTFul', key, value);
140
+ } catch (error) {
141
+ if (logLevel.warn) log.warn(`Device: ${host} ${name}, RESTFul set error: ${error.message ?? error}`);
142
+ }
143
+ })
144
+ .on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${name}, debug: ${msg}`))
145
+ .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${name}, ${msg}`))
146
+ .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${name}, ${msg}`));
147
+ });
148
+ } catch (error) {
149
+ if (logLevel.warn) log.warn(`Device: ${host} ${name}, RESTFul start error: ${error.message ?? error}`);
150
+ }
145
151
  }
146
- }
147
152
 
148
- let mqtt1 = null;
149
- let mqttConnected = false;
150
- if (device.mqtt?.enable) {
151
- try {
152
- await new Promise((resolve) => {
153
- const timer = setTimeout(resolve, 10000);
154
- mqtt1 = new Mqtt({
155
- host: device.mqtt.host,
156
- port: device.mqtt.port || 1883,
157
- clientId: device.mqtt.clientId ? `microsoft_${device.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `microsoft_${Math.random().toString(16).slice(3)}`,
158
- prefix: device.mqtt.prefix ? `microsoft/${device.mqtt.prefix}/${name}` : `microsoft/${name}`,
159
- protocolVersion: device.mqtt.protocolVersion,
160
- haDiscovery: device.mqtt.haDiscovery,
161
- user: device.mqtt.auth?.user,
162
- passwd: device.mqtt.auth?.passwd,
163
- logWarn: logLevel.warn,
164
- logDebug: logLevel.debug,
165
- })
166
- .once('connected', (msg) => {
167
- clearTimeout(timer);
168
- mqttConnected = true;
169
- if (logLevel.success) log.success(`Device: ${host} ${name}, ${msg}`);
170
- resolve();
171
- })
172
- .on('set', async (key, value) => {
173
- try {
174
- if (activeDevice) await activeDevice.setOverExternalIntegration('MQTT', key, value);
175
- } catch (error) {
176
- if (logLevel.warn) log.warn(`Device: ${host} ${name}, MQTT set error: ${error.message ?? error}`);
177
- }
153
+ if (device.mqtt?.enable) {
154
+ try {
155
+ await new Promise((resolve) => {
156
+ const timer = setTimeout(resolve, 10000);
157
+ mqtt1 = new Mqtt({
158
+ host: device.mqtt.host,
159
+ port: device.mqtt.port || 1883,
160
+ clientId: device.mqtt.clientId ? `microsoft_${device.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `microsoft_${Math.random().toString(16).slice(3)}`,
161
+ prefix: device.mqtt.prefix ? `microsoft/${device.mqtt.prefix}/${name}` : `microsoft/${name}`,
162
+ protocolVersion: device.mqtt.protocolVersion,
163
+ haDiscovery: device.mqtt.haDiscovery,
164
+ user: device.mqtt.auth?.user,
165
+ passwd: device.mqtt.auth?.passwd,
166
+ logWarn: logLevel.warn,
167
+ logDebug: logLevel.debug,
178
168
  })
179
- .on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${name}, debug: ${msg}`))
180
- .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${name}, ${msg}`))
181
- .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${name}, ${msg}`));
182
- });
183
- } catch (error) {
184
- if (logLevel.warn) log.warn(`Device: ${host} ${name}, MQTT start error: ${error.message ?? error}`);
169
+ .once('connected', (msg) => {
170
+ clearTimeout(timer);
171
+ mqttConnected = true;
172
+ if (logLevel.success) log.success(`Device: ${host} ${name}, ${msg}`);
173
+ resolve();
174
+ })
175
+ .on('set', async (key, value) => {
176
+ try {
177
+ if (activeDevice) await activeDevice.setOverExternalIntegration('MQTT', key, value);
178
+ } catch (error) {
179
+ if (logLevel.warn) log.warn(`Device: ${host} ${name}, MQTT set error: ${error.message ?? error}`);
180
+ }
181
+ })
182
+ .on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${name}, debug: ${msg}`))
183
+ .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${name}, ${msg}`))
184
+ .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${name}, ${msg}`));
185
+ });
186
+ } catch (error) {
187
+ if (logLevel.warn) log.warn(`Device: ${host} ${name}, MQTT start error: ${error.message ?? error}`);
188
+ }
185
189
  }
186
- }
190
+ return { restFul1, restFulConnected, mqtt1, mqttConnected };
191
+ };
187
192
 
188
193
  // The startup impulse generator retries the full connect cycle
189
194
  // every 120 s until it succeeds, then hands off to the xboxDevice
@@ -195,7 +200,7 @@ class XboxPlatform {
195
200
  device, name, host,
196
201
  authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile,
197
202
  logLevel, log, api, impulseGenerator,
198
- restFul1, restFulConnected, mqtt1, mqttConnected,
203
+ startIntegrations,
199
204
  onDeviceReady: (d) => { activeDevice = d; },
200
205
  });
201
206
  } catch (error) {
@@ -211,8 +216,8 @@ class XboxPlatform {
211
216
 
212
217
  // ── Connect and register a single Xbox device as a Homebridge accessory ───
213
218
 
214
- async startDevice({ device, name, host, authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, logLevel, log, api, impulseGenerator, restFul1, restFulConnected, mqtt1, mqttConnected, onDeviceReady }) {
215
- const xboxDevice = new XboxDevice(api, device, authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, restFul1, restFulConnected, mqtt1, mqttConnected)
219
+ async startDevice({ device, name, host, authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, logLevel, log, api, impulseGenerator, startIntegrations, onDeviceReady }) {
220
+ const xboxDevice = new XboxDevice(api, device, authTokenFile, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile)
216
221
  .on('devInfo', (info) => logLevel.devInfo && log.info(info))
217
222
  .on('success', (msg) => logLevel.success && log.success(`Device: ${host} ${name}, ${msg}`))
218
223
  .on('info', (msg) => logLevel.info && log.info(`Device: ${host} ${name}, ${msg}`))
@@ -220,12 +225,20 @@ class XboxPlatform {
220
225
  .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${name}, ${msg}`))
221
226
  .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${name}, ${msg}`));
222
227
 
223
- const accessory = await xboxDevice.start();
224
- if (!accessory) return;
228
+ // The integrations start when the console answers, they do not need the HomeKit accessory
229
+ xboxDevice.onConsoleOnline = async () => {
230
+ const { restFul1, restFulConnected, mqtt1, mqttConnected } = await startIntegrations();
231
+ await xboxDevice.attachIntegrations(restFul1, restFulConnected, mqtt1, mqttConnected);
232
+ };
233
+
234
+ const started = await xboxDevice.start();
235
+ if (!started) return;
225
236
 
226
237
  onDeviceReady(xboxDevice);
227
- api.publishExternalAccessories(PluginName, [accessory]);
228
- if (logLevel.success) log.success(`Device: ${host} ${name}, Published as external accessory.`);
238
+ if (xboxDevice.accessory) {
239
+ api.publishExternalAccessories(PluginName, [xboxDevice.accessory]);
240
+ if (logLevel.success) log.success(`Device: ${host} ${name}, Published as external accessory.`);
241
+ }
229
242
 
230
243
  // Hand off to the xboxDevice impulse generator and stop the startup one.
231
244
  await xboxDevice.startStopImpulseGenerator(true, [{ name: 'connect', sampling: 6000 }]);
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.0",
4
+ "version": "4.4.1",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -95,14 +95,18 @@ class XboxLocalApi extends EventEmitter {
95
95
 
96
96
  if (state.online) {
97
97
  this.lastPingOk = now;
98
+ if (!this.onlineEmitted) {
99
+ this.onlineEmitted = true;
100
+ this.emit('online');
101
+ }
98
102
  if (!this.reachable) {
99
103
  this.reachable = true;
100
- this.emit('success', `Console is reachable again`);
104
+ this.emit('success', `reachable again`);
101
105
  this.emit('reachable', true);
102
106
  }
103
107
  } else if (this.reachable && now - this.lastPingOk >= 20000) {
104
108
  this.reachable = false;
105
- this.emit('warn', `Console is not reachable`);
109
+ this.emit('warn', `not reachable`);
106
110
  this.emit('reachable', false);
107
111
  }
108
112
 
package/src/xboxdevice.js CHANGED
@@ -1025,6 +1025,17 @@ class XboxDevice extends EventEmitter {
1025
1025
 
1026
1026
  //home assistant discovery
1027
1027
  // MQTT connected, at start when the broker was not running yet or after a restart of the broker
1028
+ // RestFul and MQTT are connected after the console answered for the first time
1029
+ async attachIntegrations(restFul1, restFulConnected, mqtt1, mqttConnected) {
1030
+ this.restFul1 = restFul1;
1031
+ this.restFulConnected = restFulConnected;
1032
+ this.mqtt1 = mqtt1;
1033
+ if (!mqtt1) return;
1034
+
1035
+ this.mqtt1.on('online', () => this.mqttOnline().catch((error) => this.emit('warn', `MQTT online error: ${error}`)));
1036
+ if (mqttConnected) await this.mqttOnline();
1037
+ }
1038
+
1028
1039
  async mqttOnline() {
1029
1040
  this.mqttConnected = true;
1030
1041
  if (!this.haReady) return;
@@ -1160,6 +1171,13 @@ class XboxDevice extends EventEmitter {
1160
1171
  // BŁ4 FIX: pass restFulEnabled/mqttEnabled booleans, not channelsFile string
1161
1172
  this.xboxLocalApi = new XboxLocalApi(this.device, this.authTokenFile, this.devInfoFile, restFulEnabled, mqttEnabled)
1162
1173
  .on('reachable', (reachable) => { this.reachable = reachable; })
1174
+ .on('online', async () => {
1175
+ try {
1176
+ await this.onConsoleOnline?.();
1177
+ } catch (error) {
1178
+ this.emit('warn', `Start integrations error: ${error}`);
1179
+ }
1180
+ })
1163
1181
  .on('deviceInfo', async (info) => {
1164
1182
  this.emit('devInfo', `-------- ${this.name} --------`);
1165
1183
  this.emit('devInfo', `Manufacturer: Microsoft`);
@@ -1323,11 +1341,20 @@ class XboxDevice extends EventEmitter {
1323
1341
  //prepare data for accessory
1324
1342
  await this.prepareDataForAccessory();
1325
1343
 
1326
- // Prepare accessory
1327
- const accessory = await this.prepareAccessory();
1344
+ // MQTT and Home Assistant work on the console, they do not depend on the HomeKit accessory
1328
1345
  this.haReady = true;
1329
1346
  this.setupHaDiscovery();
1330
- return accessory;
1347
+
1348
+ // Prepare accessory, when it is not possible the console is still controlled over MQTT and RESTFul
1349
+ this.accessory = null;
1350
+ try {
1351
+ this.accessory = await this.prepareAccessory();
1352
+ } catch (error) {
1353
+ this.accessory = null;
1354
+ this.emit('error', `HomeKit accessory not created: ${error}`);
1355
+ }
1356
+
1357
+ return true;
1331
1358
  } catch (error) {
1332
1359
  throw new Error(`Start error: ${error}`);
1333
1360
  }