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 +1 -1
- package/src/bedjet/BedJet.ts +32 -19
package/package.json
CHANGED
package/src/bedjet/BedJet.ts
CHANGED
|
@@ -149,22 +149,26 @@ export class BedJet extends EventEmitter {
|
|
|
149
149
|
|
|
150
150
|
peripheral.once('disconnect', () => this._onDisconnected());
|
|
151
151
|
|
|
152
|
-
|
|
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
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
peripheral.discoverAllServicesAndCharacteristicsAsync()
|
|
159
|
-
|
|
160
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
184
|
-
this.statusChar.subscribeAsync()
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|