homebridge-bedjet 0.1.5 → 0.1.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-bedjet",
3
3
  "displayName": "BedJet",
4
- "version": "0.1.5",
4
+ "version": "0.1.7",
5
5
  "description": "Homebridge plugin for BedJet V3 via Bluetooth LE",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
@@ -149,22 +149,26 @@ export class BedJet extends EventEmitter {
149
149
 
150
150
  peripheral.once('disconnect', () => this._onDisconnected());
151
151
 
152
- await peripheral.connectAsync();
152
+ try {
153
+ await peripheral.connectAsync();
154
+ } catch (err) {
155
+ throw new Error(`[${this.config.name}] connectAsync failed: ${err}`);
156
+ }
153
157
  this.log.info(`[${this.config.name}] Connected — discovering services…`);
154
158
 
155
- // Wrap service discovery in a timeout it hangs indefinitely on Linux/BlueZ
156
- // if the adapter is busy or the device is in a bad state.
157
- const { characteristics } = await Promise.race([
158
- peripheral.discoverAllServicesAndCharacteristicsAsync(),
159
- new Promise<never>((_, reject) =>
160
- setTimeout(() => reject(new Error(`[${this.config.name}] Service discovery timed out`)), 10_000),
161
- ),
162
- ]);
159
+ // Use async discovery works on Linux when the device is already bonded
160
+ let characteristics: Characteristic[];
161
+ try {
162
+ const result = await peripheral.discoverAllServicesAndCharacteristicsAsync();
163
+ characteristics = result.characteristics;
164
+ } catch (err) {
165
+ throw new Error(`[${this.config.name}] discoverAllServices failed: ${err}`);
166
+ }
163
167
 
164
168
  this.log.info(`[${this.config.name}] Found ${characteristics.length} characteristics`);
165
169
  for (const char of characteristics) {
166
170
  const uuid = normalize(char.uuid);
167
- this.log.debug(`[${this.config.name}] char: ${uuid}`);
171
+ this.log.info(`[${this.config.name}] char: ${uuid}`);
168
172
  if (uuid === NORM_STATUS_UUID) {
169
173
  this.statusChar = char;
170
174
  this.log.info(`[${this.config.name}] Found status characteristic`);
@@ -174,25 +178,34 @@ export class BedJet extends EventEmitter {
174
178
  }
175
179
  }
176
180
 
181
+ this.log.info(`[${this.config.name}] Char check: status=${!!this.statusChar} command=${!!this.commandChar}`);
182
+
177
183
  if (!this.commandChar || !this.statusChar) {
178
- throw new Error(`[${this.config.name}] Required characteristics not found (status=${!!this.statusChar} command=${!!this.commandChar})`);
184
+ throw new Error(`[${this.config.name}] Required characteristics not found`);
179
185
  }
180
186
 
181
187
  // Subscribe to notifications on the status characteristic
182
188
  this.log.info(`[${this.config.name}] Subscribing to notifications…`);
183
- await Promise.race([
184
- this.statusChar.subscribeAsync(),
185
- new Promise<never>((_, reject) =>
186
- setTimeout(() => reject(new Error(`[${this.config.name}] Subscribe timed out`)), 10_000),
187
- ),
188
- ]);
189
+ try {
190
+ await this.statusChar.subscribeAsync();
191
+ } catch (err) {
192
+ throw new Error(`[${this.config.name}] subscribeAsync failed: ${err}`);
193
+ }
189
194
  this.log.info(`[${this.config.name}] Subscribed — reading device status…`);
190
195
  this.statusChar.on('data', (data: Buffer) => this._handleNotification(data));
191
196
 
192
197
  // Read extended status and device name
193
- await this._readDeviceStatus();
198
+ try {
199
+ await this._readDeviceStatus();
200
+ } catch (err) {
201
+ this.log.warn(`[${this.config.name}] _readDeviceStatus failed: ${err}`);
202
+ }
194
203
  this.log.info(`[${this.config.name}] Reading device name…`);
195
- await this._readDeviceName();
204
+ try {
205
+ await this._readDeviceName();
206
+ } catch (err) {
207
+ this.log.warn(`[${this.config.name}] _readDeviceName failed: ${err}`);
208
+ }
196
209
 
197
210
  this.reconnectAttempts = 0;
198
211
  this._state = { ...this._state, isConnected: true };