homebridge-bedjet 0.1.4 → 0.1.6
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 +1 -1
- package/src/bedjet/BedJet.ts +27 -14
package/package.json
CHANGED
package/src/bedjet/BedJet.ts
CHANGED
|
@@ -152,14 +152,20 @@ export class BedJet extends EventEmitter {
|
|
|
152
152
|
await peripheral.connectAsync();
|
|
153
153
|
this.log.info(`[${this.config.name}] Connected — discovering services…`);
|
|
154
154
|
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
// discoverAllServicesAndCharacteristicsAsync can hang on Linux/BlueZ even after
|
|
156
|
+
// returning characteristics — use the callback API directly instead.
|
|
157
|
+
const characteristics = await new Promise<Characteristic[]>((resolve, reject) => {
|
|
158
|
+
const timer = setTimeout(() =>
|
|
159
|
+
reject(new Error(`[${this.config.name}] Service discovery timed out`)), 10_000);
|
|
160
|
+
peripheral.discoverAllServicesAndCharacteristics((err, _services, chars) => {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
if (err) {
|
|
163
|
+
reject(new Error(`[${this.config.name}] Discovery error: ${err}`));
|
|
164
|
+
} else {
|
|
165
|
+
resolve(chars ?? []);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
163
169
|
|
|
164
170
|
this.log.info(`[${this.config.name}] Found ${characteristics.length} characteristics`);
|
|
165
171
|
for (const char of characteristics) {
|
|
@@ -180,12 +186,19 @@ export class BedJet extends EventEmitter {
|
|
|
180
186
|
|
|
181
187
|
// Subscribe to notifications on the status characteristic
|
|
182
188
|
this.log.info(`[${this.config.name}] Subscribing to notifications…`);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
+
const statusChar = this.statusChar;
|
|
190
|
+
await new Promise<void>((resolve, reject) => {
|
|
191
|
+
const timer = setTimeout(() =>
|
|
192
|
+
reject(new Error(`[${this.config.name}] Subscribe timed out`)), 10_000);
|
|
193
|
+
statusChar.subscribe((err) => {
|
|
194
|
+
clearTimeout(timer);
|
|
195
|
+
if (err) {
|
|
196
|
+
reject(new Error(`[${this.config.name}] Subscribe error: ${err}`));
|
|
197
|
+
} else {
|
|
198
|
+
resolve();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
189
202
|
this.log.info(`[${this.config.name}] Subscribed — reading device status…`);
|
|
190
203
|
this.statusChar.on('data', (data: Buffer) => this._handleNotification(data));
|
|
191
204
|
|