@switchbot/homebridge-switchbot 1.7.1-beta.1 → 1.7.1-beta.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/dist/devices/bots.d.ts +1 -0
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +21 -6
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/contact.d.ts +1 -5
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +58 -77
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +4 -0
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +28 -3
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/meters.d.ts +1 -0
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +8 -3
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +1 -4
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +47 -63
- package/dist/devices/motion.js.map +1 -1
- package/package.json +1 -1
- package/src/devices/bots.ts +21 -6
- package/src/devices/contact.ts +56 -76
- package/src/devices/curtains.ts +30 -3
- package/src/devices/meters.ts +9 -3
- package/src/devices/motion.ts +48 -63
package/src/devices/motion.ts
CHANGED
|
@@ -27,6 +27,7 @@ export class Motion {
|
|
|
27
27
|
// BLE Others
|
|
28
28
|
connected?: boolean;
|
|
29
29
|
switchbot!: switchbot;
|
|
30
|
+
SwitchToOpenAPI?: boolean;
|
|
30
31
|
serviceData!: serviceData;
|
|
31
32
|
battery!: serviceData['battery'];
|
|
32
33
|
movement!: serviceData['movement'];
|
|
@@ -108,12 +109,20 @@ export class Motion {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
// Battery Service
|
|
111
|
-
if (device.ble) {
|
|
112
|
+
if (!device.ble) {
|
|
113
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Battery Service`);
|
|
114
|
+
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
115
|
+
accessory.removeService(this.batteryService!);
|
|
116
|
+
} else if (!this.batteryService) {
|
|
117
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Add Battery Service`);
|
|
112
118
|
(this.batteryService =
|
|
113
|
-
accessory.getService(this.platform.Service.Battery) ||
|
|
114
|
-
accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
119
|
+
this.accessory.getService(this.platform.Service.Battery) ||
|
|
120
|
+
this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
|
|
115
121
|
|
|
116
122
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
123
|
+
|
|
124
|
+
} else {
|
|
125
|
+
this.debugLog(`Motion Sensor: ${accessory.displayName} Battery Service Not Added`);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
// Retrieve initial values and updateHomekit
|
|
@@ -196,36 +205,32 @@ export class Motion {
|
|
|
196
205
|
* Parse the device status from the SwitchBot api
|
|
197
206
|
*/
|
|
198
207
|
async parseStatus() {
|
|
199
|
-
if (this.device.ble) {
|
|
200
|
-
await this.BLEparseStatus();
|
|
201
|
-
} else {
|
|
208
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
202
209
|
await this.openAPIparseStatus();
|
|
210
|
+
} else {
|
|
211
|
+
await this.BLEparseStatus();
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
214
|
|
|
206
215
|
private async BLEparseStatus() {
|
|
207
216
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
|
|
208
217
|
// Movement
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} else if (this.movement === undefined) {
|
|
212
|
-
this.movement = false;
|
|
213
|
-
this.BLEmotion();
|
|
214
|
-
} else {
|
|
215
|
-
this.BLEmotion();
|
|
216
|
-
}
|
|
218
|
+
this.MotionDetected = Boolean(this.movement);
|
|
219
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
217
220
|
// Light Level
|
|
218
221
|
if (!this.device.motion?.hide_lightsensor) {
|
|
219
222
|
this.set_minLux = this.minLux();
|
|
220
223
|
this.set_maxLux = this.maxLux();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
switch (this.lightLevel) {
|
|
225
|
+
case 'dark':
|
|
226
|
+
case 1:
|
|
227
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
228
231
|
}
|
|
232
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
233
|
+
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
229
234
|
}
|
|
230
235
|
// Battery
|
|
231
236
|
if (this.battery === undefined) {
|
|
@@ -240,55 +245,33 @@ export class Motion {
|
|
|
240
245
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
241
246
|
}
|
|
242
247
|
|
|
243
|
-
private BLEmotion() {
|
|
244
|
-
this.MotionDetected = Boolean(this.movement);
|
|
245
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private BLElux() {
|
|
249
|
-
switch (this.lightLevel) {
|
|
250
|
-
case 'dark':
|
|
251
|
-
case 1:
|
|
252
|
-
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
253
|
-
break;
|
|
254
|
-
default:
|
|
255
|
-
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
256
|
-
}
|
|
257
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
258
|
-
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
248
|
private async openAPIparseStatus() {
|
|
249
|
+
if (this.device.ble) {
|
|
250
|
+
this.SwitchToOpenAPI = false;
|
|
251
|
+
}
|
|
262
252
|
if (this.platform.config.credentials?.openToken) {
|
|
263
253
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
264
254
|
// Motion State
|
|
265
|
-
this.
|
|
255
|
+
if (typeof this.deviceStatus.body.moveDetected === 'boolean') {
|
|
256
|
+
this.MotionDetected = this.deviceStatus.body.moveDetected;
|
|
257
|
+
}
|
|
258
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
266
259
|
// Light Level
|
|
267
260
|
if (!this.device.motion?.hide_lightsensor) {
|
|
268
|
-
this.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
this.set_minLux = this.minLux();
|
|
262
|
+
this.set_maxLux = this.maxLux();
|
|
263
|
+
switch (this.deviceStatus.body.brightness) {
|
|
264
|
+
case 'dim':
|
|
265
|
+
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
266
|
+
break;
|
|
267
|
+
case 'bright':
|
|
268
|
+
default:
|
|
269
|
+
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
270
|
+
}
|
|
271
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
279
272
|
|
|
280
|
-
|
|
281
|
-
this.set_minLux = this.minLux();
|
|
282
|
-
this.set_maxLux = this.maxLux();
|
|
283
|
-
switch (this.deviceStatus.body.brightness) {
|
|
284
|
-
case 'dim':
|
|
285
|
-
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
286
|
-
break;
|
|
287
|
-
case 'bright':
|
|
288
|
-
default:
|
|
289
|
-
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
273
|
+
}
|
|
290
274
|
}
|
|
291
|
-
this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
292
275
|
}
|
|
293
276
|
|
|
294
277
|
/**
|
|
@@ -333,7 +316,7 @@ export class Motion {
|
|
|
333
316
|
// Start to monitor advertisement packets
|
|
334
317
|
if (switchbot !== false) {
|
|
335
318
|
switchbot.startScan({
|
|
336
|
-
|
|
319
|
+
model: 's',
|
|
337
320
|
id: this.device.bleMac,
|
|
338
321
|
}).then(() => {
|
|
339
322
|
// Set an event hander
|
|
@@ -377,6 +360,7 @@ export class Motion {
|
|
|
377
360
|
}
|
|
378
361
|
if (this.platform.config.credentials?.openToken) {
|
|
379
362
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
363
|
+
this.SwitchToOpenAPI = true;
|
|
380
364
|
await this.openAPIRefreshStatus();
|
|
381
365
|
}
|
|
382
366
|
this.apiError(e);
|
|
@@ -390,6 +374,7 @@ export class Motion {
|
|
|
390
374
|
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
391
375
|
if (this.platform.config.credentials?.openToken) {
|
|
392
376
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
377
|
+
this.SwitchToOpenAPI = true;
|
|
393
378
|
await this.openAPIRefreshStatus();
|
|
394
379
|
}
|
|
395
380
|
}
|