@switchbot/homebridge-switchbot 1.6.3 → 1.6.4-beta.3
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 +9 -0
- package/config.schema.json +18 -0
- package/dist/devices/bots.d.ts +11 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -44
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/contact.d.ts +2 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +26 -9
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -2
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +27 -10
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +28 -11
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +27 -10
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +2 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +27 -10
- package/dist/devices/motion.js.map +1 -1
- package/dist/platform.d.ts +0 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +0 -12
- package/dist/platform.js.map +1 -1
- package/package.json +71 -71
- package/src/devices/bots.ts +244 -46
- package/src/devices/contact.ts +25 -9
- package/src/devices/curtains.ts +26 -10
- package/src/devices/humidifiers.ts +27 -11
- package/src/devices/meters.ts +26 -11
- package/src/devices/motion.ts +26 -10
- package/src/platform.ts +0 -13
package/src/devices/motion.ts
CHANGED
|
@@ -226,18 +226,34 @@ export class Motion {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
public async connectBLE() {
|
|
230
|
+
let switchbot: any;
|
|
231
|
+
try {
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
233
|
+
const Switchbot = require('node-switchbot');
|
|
234
|
+
switchbot = new Switchbot();
|
|
235
|
+
// Convert to BLE Address
|
|
236
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
237
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
238
|
+
} catch (e: any) {
|
|
239
|
+
switchbot = false;
|
|
240
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
|
|
241
|
+
if (this.deviceLogging === 'debug') {
|
|
242
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
243
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
244
|
+
}
|
|
245
|
+
if (this.platform.debugMode) {
|
|
246
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
|
|
247
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
234
250
|
return switchbot;
|
|
235
251
|
}
|
|
236
252
|
|
|
237
253
|
private async BLERefreshStatus() {
|
|
238
254
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
239
255
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
240
|
-
const switchbot = this.connectBLE();
|
|
256
|
+
const switchbot = await this.connectBLE();
|
|
241
257
|
// Start to monitor advertisement packets
|
|
242
258
|
if (switchbot !== false) {
|
|
243
259
|
switchbot.startScan({
|
|
@@ -271,7 +287,7 @@ export class Motion {
|
|
|
271
287
|
this.parseStatus();
|
|
272
288
|
this.updateHomeKitCharacteristics();
|
|
273
289
|
} else {
|
|
274
|
-
await this.BLEconnection();
|
|
290
|
+
await this.BLEconnection(switchbot);
|
|
275
291
|
}
|
|
276
292
|
}).catch(async (e: any) => {
|
|
277
293
|
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
@@ -290,12 +306,12 @@ export class Motion {
|
|
|
290
306
|
this.apiError(e);
|
|
291
307
|
});
|
|
292
308
|
} else {
|
|
293
|
-
await this.BLEconnection();
|
|
309
|
+
await this.BLEconnection(switchbot);
|
|
294
310
|
}
|
|
295
311
|
}
|
|
296
312
|
|
|
297
|
-
|
|
298
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
313
|
+
public async BLEconnection(switchbot: any) {
|
|
314
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
299
315
|
if (this.platform.config.credentials?.openToken) {
|
|
300
316
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
301
317
|
await this.openAPIRefreshStatus();
|
package/src/platform.ts
CHANGED
|
@@ -41,7 +41,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
41
41
|
registeringDevice!: boolean;
|
|
42
42
|
debugMode!: boolean;
|
|
43
43
|
platformLogging?: string;
|
|
44
|
-
switchbot: any;
|
|
45
44
|
|
|
46
45
|
constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
|
|
47
46
|
this.logs();
|
|
@@ -193,18 +192,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
connectBLE() {
|
|
197
|
-
try {
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
199
|
-
const Switchbot = require('node-switchbot');
|
|
200
|
-
this.switchbot = new Switchbot();
|
|
201
|
-
} catch (e) {
|
|
202
|
-
this.switchbot = false;
|
|
203
|
-
this.errorLog(`Was 'node-switchbot' found: ${this.switchbot}`);
|
|
204
|
-
}
|
|
205
|
-
return this.switchbot;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
195
|
/**
|
|
209
196
|
* this method discovers the Locations
|
|
210
197
|
*/
|