homebridge-xbox-tv 4.4.0 → 4.4.2

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,20 @@ 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.2] - (14.11.2026)
22
+
23
+ ### Changes
24
+
25
+ - 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
26
+ - changed: removed the word console from the log messages
27
+
28
+ ## [4.4.1] - (12.11.2026)
29
+
30
+ ### Changes
31
+
32
+ - changed: the log of a console that cannot be reached shows only `not reachable` and `reachable again`
33
+ - 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
34
+
21
35
  ## [4.4.0] - (12.11.2026)
22
36
 
23
37
  ### 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.2",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -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 to console`);
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 from console`);
62
+ if (this.logDebug) this.emit('debug', `Plugin received heartbeat`);
65
63
 
66
64
  this.connecting = true;
67
65
  try {
@@ -83,27 +81,18 @@ class XboxLocalApi extends EventEmitter {
83
81
  });
84
82
  };
85
83
 
86
- // The console that does not answer the ping for 20 seconds is shown as not responding in the Home app, the state of the console is not changed
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.lastPingOk = now;
98
- if (!this.reachable) {
99
- this.reachable = true;
100
- this.emit('success', `Console is reachable again`);
101
- this.emit('reachable', true);
102
- }
103
- } else if (this.reachable && now - this.lastPingOk >= 20000) {
104
- this.reachable = false;
105
- this.emit('warn', `Console is not reachable`);
106
- this.emit('reachable', false);
93
+ if (state.online && !this.onlineEmitted) {
94
+ this.onlineEmitted = true;
95
+ this.emit('online');
107
96
  }
108
97
 
109
98
  return state.online;
@@ -443,12 +432,12 @@ class XboxLocalApi extends EventEmitter {
443
432
  if (!this.acknowledgeInterval) {
444
433
  this.acknowledgeInterval = setInterval(async () => {
445
434
  const elapsed = (Date.now() - this.heartBeatStartTime) / 1000;
446
- if (this.logDebug) this.emit('debug', `Console last seen: ${elapsed.toFixed(1)}s ago`);
435
+ if (this.logDebug) this.emit('debug', `Last seen: ${elapsed.toFixed(1)}s ago`);
447
436
 
448
437
  if (elapsed >= 14) {
449
438
  clearInterval(this.acknowledgeInterval);
450
439
  this.acknowledgeInterval = null;
451
- if (this.logDebug) this.emit('debug', `Console inactivity timeout — disconnecting`);
440
+ if (this.logDebug) this.emit('debug', `Inactivity timeout, disconnecting`);
452
441
  // Close socket first so on('close') triggers updateState().
453
442
  // Calling updateState() directly would null this.socket before
454
443
  // close(), causing the old socket to leak in the OS.
@@ -463,7 +452,7 @@ class XboxLocalApi extends EventEmitter {
463
452
  if (Math.round(elapsed) % 5 === 0 && Math.round(elapsed) > 0) {
464
453
  try {
465
454
  const pingResult = await this.functions.ping(this.host);
466
- if (this.logDebug) this.emit('debug', `Ping ${pingResult.online ? 'OK' : 'failed'} — console ${pingResult.online ? 'reachable' : 'unreachable'}`);
455
+ if (this.logDebug) this.emit('debug', `Ping ${pingResult.online ? 'OK' : 'failed'}`);
467
456
  } catch (error) {
468
457
  if (this.logError) this.emit('error', `Ping error: ${error}`);
469
458
  }
@@ -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', `Consoles list data: ${JSON.stringify(data, null, 2)}`);
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', `Console list data error: ${error}`);
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', `Console with Live ID ${this.liveId} not found on server`);
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', `Console with Live ID ${this.liveId} remote management not enabled`);
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(`Consoles list error: ${error.message}`, { cause: 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', `Console status data: ${JSON.stringify(data, null, 2)}`);
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', `Console status error: ${status.error}`);
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(`Console status error: ${error.message}`, { cause: 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;
@@ -970,7 +967,7 @@ class XboxDevice extends EventEmitter {
970
967
  }
971
968
 
972
969
  if (!this.power) {
973
- if (this.logWarn) this.emit('warn', `console is off`);
970
+ if (this.logWarn) this.emit('warn', `power is off`);
974
971
  return;
975
972
  }
976
973
 
@@ -1015,8 +1012,6 @@ class XboxDevice extends EventEmitter {
1015
1012
  }
1016
1013
  }
1017
1014
 
1018
- applyReachability(accessory, this.hap, () => this.reachable);
1019
-
1020
1015
  return accessory;
1021
1016
  } catch (error) {
1022
1017
  throw new Error(error)
@@ -1025,6 +1020,17 @@ class XboxDevice extends EventEmitter {
1025
1020
 
1026
1021
  //home assistant discovery
1027
1022
  // MQTT connected, at start when the broker was not running yet or after a restart of the broker
1023
+ // RestFul and MQTT are connected after the console answered for the first time
1024
+ async attachIntegrations(restFul1, restFulConnected, mqtt1, mqttConnected) {
1025
+ this.restFul1 = restFul1;
1026
+ this.restFulConnected = restFulConnected;
1027
+ this.mqtt1 = mqtt1;
1028
+ if (!mqtt1) return;
1029
+
1030
+ this.mqtt1.on('online', () => this.mqttOnline().catch((error) => this.emit('warn', `MQTT online error: ${error}`)));
1031
+ if (mqttConnected) await this.mqttOnline();
1032
+ }
1033
+
1028
1034
  async mqttOnline() {
1029
1035
  this.mqttConnected = true;
1030
1036
  if (!this.haReady) return;
@@ -1159,7 +1165,13 @@ class XboxDevice extends EventEmitter {
1159
1165
 
1160
1166
  // BŁ4 FIX: pass restFulEnabled/mqttEnabled booleans, not channelsFile string
1161
1167
  this.xboxLocalApi = new XboxLocalApi(this.device, this.authTokenFile, this.devInfoFile, restFulEnabled, mqttEnabled)
1162
- .on('reachable', (reachable) => { this.reachable = reachable; })
1168
+ .on('online', async () => {
1169
+ try {
1170
+ await this.onConsoleOnline?.();
1171
+ } catch (error) {
1172
+ this.emit('warn', `Start integrations error: ${error}`);
1173
+ }
1174
+ })
1163
1175
  .on('deviceInfo', async (info) => {
1164
1176
  this.emit('devInfo', `-------- ${this.name} --------`);
1165
1177
  this.emit('devInfo', `Manufacturer: Microsoft`);
@@ -1323,11 +1335,20 @@ class XboxDevice extends EventEmitter {
1323
1335
  //prepare data for accessory
1324
1336
  await this.prepareDataForAccessory();
1325
1337
 
1326
- // Prepare accessory
1327
- const accessory = await this.prepareAccessory();
1338
+ // MQTT and Home Assistant work on the console, they do not depend on the HomeKit accessory
1328
1339
  this.haReady = true;
1329
1340
  this.setupHaDiscovery();
1330
- return accessory;
1341
+
1342
+ // Prepare accessory, when it is not possible the console is still controlled over MQTT and RESTFul
1343
+ this.accessory = null;
1344
+ try {
1345
+ this.accessory = await this.prepareAccessory();
1346
+ } catch (error) {
1347
+ this.accessory = null;
1348
+ this.emit('error', `HomeKit accessory not created: ${error}`);
1349
+ }
1350
+
1351
+ return true;
1331
1352
  } catch (error) {
1332
1353
  throw new Error(`Start error: ${error}`);
1333
1354
  }
@@ -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
- };