@switchbot/homebridge-switchbot 2.8.0 → 2.8.1-beta.1
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/.github/npm-version-script.js +81 -0
- package/dist/device/blindtilt.d.ts +21 -23
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +71 -73
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -15
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +38 -34
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -14
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +33 -23
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -24
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +49 -43
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -24
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +49 -51
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -26
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +49 -47
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +42 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -10
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +27 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -21
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +8 -13
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +28 -25
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -21
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +75 -26
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +16 -21
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +40 -37
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +16 -21
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +40 -37
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -21
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +44 -46
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +5 -15
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +22 -19
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -13
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +30 -28
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +4 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/fan.d.ts +3 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/other.d.ts +2 -2
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/device/blindtilt.ts +96 -95
- package/src/device/bot.ts +54 -54
- package/src/device/ceilinglight.ts +46 -39
- package/src/device/colorbulb.ts +68 -69
- package/src/device/contact.ts +69 -77
- package/src/device/curtain.ts +75 -74
- package/src/device/hub.ts +53 -38
- package/src/device/humidifier.ts +33 -26
- package/src/device/iosensor.ts +53 -48
- package/src/device/lightstrip.ts +39 -40
- package/src/device/lock.ts +94 -49
- package/src/device/meter.ts +59 -59
- package/src/device/meterplus.ts +59 -60
- package/src/device/motion.ts +61 -65
- package/src/device/plug.ts +27 -35
- package/src/device/robotvacuumcleaner.ts +43 -43
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +3 -6
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/settings.ts +5 -1
package/src/device/meterplus.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { skipWhile } from 'rxjs/operators';
|
|
|
7
7
|
import { request } from 'undici';
|
|
8
8
|
import { Context } from 'vm';
|
|
9
9
|
import { SwitchBotPlatform } from '../platform';
|
|
10
|
-
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData,
|
|
10
|
+
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings';
|
|
11
11
|
import { sleep } from '../utils';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -17,34 +17,31 @@ import { sleep } from '../utils';
|
|
|
17
17
|
*/
|
|
18
18
|
export class MeterPlus {
|
|
19
19
|
// Services
|
|
20
|
-
batteryService
|
|
21
|
-
temperatureservice?: Service;
|
|
20
|
+
batteryService: Service;
|
|
22
21
|
humidityservice?: Service;
|
|
22
|
+
temperatureservice?: Service;
|
|
23
23
|
|
|
24
24
|
// Characteristic Values
|
|
25
|
-
|
|
25
|
+
BatteryLevel!: CharacteristicValue;
|
|
26
|
+
StatusLowBattery!: CharacteristicValue;
|
|
26
27
|
CurrentTemperature?: CharacteristicValue;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
29
|
+
|
|
30
|
+
// OpenAPI Status
|
|
31
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
32
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
33
|
+
OpenAPI_CurrentTemperature: deviceStatus['temperature'];
|
|
34
|
+
OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
|
|
30
35
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// BLE Status
|
|
37
|
+
BLE_Celsius!: temperature['c'];
|
|
38
|
+
BLE_Fahrenheit!: temperature['f'];
|
|
39
|
+
BLE_BatteryLevel!: serviceData['battery'];
|
|
40
|
+
BLE_CurrentTemperature!: serviceData['temperature'];
|
|
41
|
+
BLE_CurrentRelativeHumidity!: serviceData['humidity'];
|
|
37
42
|
|
|
38
43
|
// BLE Others
|
|
39
|
-
|
|
40
|
-
switchbot!: switchbot;
|
|
41
|
-
serviceData!: serviceData;
|
|
42
|
-
address!: ad['address'];
|
|
43
|
-
temperature!: serviceData['temperature'];
|
|
44
|
-
celsius!: temperature['c'];
|
|
45
|
-
fahrenheit!: temperature['f'];
|
|
46
|
-
battery!: serviceData['battery'];
|
|
47
|
-
humidity!: serviceData['humidity'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
48
45
|
|
|
49
46
|
//MQTT stuff
|
|
50
47
|
mqttClient: MqttClient | null = null;
|
|
@@ -155,19 +152,14 @@ export class MeterPlus {
|
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
// Battery Service
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.batteryService.
|
|
164
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
165
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
166
|
-
}
|
|
167
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
168
|
-
} else {
|
|
169
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
155
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
156
|
+
`${accessory.displayName} Battery`;
|
|
157
|
+
|
|
158
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
159
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
160
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
170
161
|
}
|
|
162
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
171
163
|
|
|
172
164
|
// Retrieve initial values and updateHomekit
|
|
173
165
|
this.updateHomeKitCharacteristics();
|
|
@@ -202,7 +194,7 @@ export class MeterPlus {
|
|
|
202
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
203
195
|
|
|
204
196
|
// Battery
|
|
205
|
-
this.BatteryLevel = Number(this.
|
|
197
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
206
198
|
if (this.BatteryLevel < 15) {
|
|
207
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
208
200
|
} else {
|
|
@@ -212,14 +204,14 @@ export class MeterPlus {
|
|
|
212
204
|
|
|
213
205
|
// Humidity
|
|
214
206
|
if (!this.device.meter?.hide_humidity) {
|
|
215
|
-
this.CurrentRelativeHumidity = this.
|
|
207
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
216
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
217
209
|
}
|
|
218
210
|
|
|
219
211
|
// Current Temperature
|
|
220
212
|
if (!this.device.meter?.hide_temperature) {
|
|
221
|
-
this.
|
|
222
|
-
this.CurrentTemperature = this.
|
|
213
|
+
this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
|
|
214
|
+
this.CurrentTemperature = this.BLE_Celsius;
|
|
223
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
224
216
|
}
|
|
225
217
|
}
|
|
@@ -228,7 +220,7 @@ export class MeterPlus {
|
|
|
228
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
229
221
|
|
|
230
222
|
// Battery
|
|
231
|
-
this.BatteryLevel = Number(this.
|
|
223
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
232
224
|
if (this.BatteryLevel < 15) {
|
|
233
225
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
234
226
|
} else {
|
|
@@ -238,13 +230,13 @@ export class MeterPlus {
|
|
|
238
230
|
|
|
239
231
|
// Current Relative Humidity
|
|
240
232
|
if (!this.device.meter?.hide_humidity) {
|
|
241
|
-
this.CurrentRelativeHumidity = this.
|
|
233
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
242
234
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
243
235
|
}
|
|
244
236
|
|
|
245
237
|
// Current Temperature
|
|
246
238
|
if (!this.device.meter?.hide_temperature) {
|
|
247
|
-
this.CurrentTemperature = this.
|
|
239
|
+
this.CurrentTemperature = this.BLE_CurrentTemperature!;
|
|
248
240
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
249
241
|
}
|
|
250
242
|
}
|
|
@@ -288,20 +280,18 @@ export class MeterPlus {
|
|
|
288
280
|
.then(async () => {
|
|
289
281
|
// Set an event hander
|
|
290
282
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
291
|
-
this.address = ad.address;
|
|
292
283
|
this.debugLog(
|
|
293
284
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
294
|
-
` BLE Address Found: ${
|
|
285
|
+
` BLE Address Found: ${ad.address}`,
|
|
295
286
|
);
|
|
296
287
|
if (ad.serviceData.humidity! > 0) {
|
|
297
288
|
// reject unreliable data
|
|
298
|
-
this.
|
|
289
|
+
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
299
290
|
}
|
|
300
|
-
this.
|
|
301
|
-
this.
|
|
302
|
-
this.
|
|
303
|
-
this.
|
|
304
|
-
this.battery = ad.serviceData.battery;
|
|
291
|
+
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
292
|
+
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
293
|
+
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
294
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
305
295
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
306
296
|
this.debugLog(
|
|
307
297
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -309,13 +299,13 @@ export class MeterPlus {
|
|
|
309
299
|
`battery: ${ad.serviceData.battery}`,
|
|
310
300
|
);
|
|
311
301
|
|
|
312
|
-
if (
|
|
313
|
-
this.
|
|
314
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
302
|
+
if (ad.serviceData) {
|
|
303
|
+
this.BLE_IsConnected = true;
|
|
304
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
315
305
|
await this.stopScanning(switchbot);
|
|
316
306
|
} else {
|
|
317
|
-
this.
|
|
318
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
307
|
+
this.BLE_IsConnected = false;
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
319
309
|
}
|
|
320
310
|
};
|
|
321
311
|
// Wait
|
|
@@ -349,10 +339,10 @@ export class MeterPlus {
|
|
|
349
339
|
this.statusCode(statusCode);
|
|
350
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
351
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
this.
|
|
342
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity!;
|
|
343
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
|
|
344
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
345
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
356
346
|
this.openAPIparseStatus();
|
|
357
347
|
this.updateHomeKitCharacteristics();
|
|
358
348
|
} catch (e: any) {
|
|
@@ -425,7 +415,6 @@ export class MeterPlus {
|
|
|
425
415
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
426
416
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
427
417
|
}
|
|
428
|
-
|
|
429
418
|
if (this.device.mqttURL) {
|
|
430
419
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
431
420
|
}
|
|
@@ -435,6 +424,16 @@ export class MeterPlus {
|
|
|
435
424
|
this.historyService?.addEntry(entry);
|
|
436
425
|
}
|
|
437
426
|
}
|
|
427
|
+
// FirmwareRevision
|
|
428
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
430
|
+
} else {
|
|
431
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
432
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
433
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
434
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
435
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
436
|
+
}
|
|
438
437
|
}
|
|
439
438
|
|
|
440
439
|
/*
|
|
@@ -488,7 +487,7 @@ export class MeterPlus {
|
|
|
488
487
|
|
|
489
488
|
async stopScanning(switchbot: any) {
|
|
490
489
|
await switchbot.stopScan();
|
|
491
|
-
if (this.
|
|
490
|
+
if (this.BLE_IsConnected) {
|
|
492
491
|
await this.BLEparseStatus();
|
|
493
492
|
await this.updateHomeKitCharacteristics();
|
|
494
493
|
} else {
|
package/src/device/motion.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { skipWhile } from 'rxjs/operators';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, serviceData,
|
|
8
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Platform Accessory
|
|
@@ -16,35 +16,33 @@ export class Motion {
|
|
|
16
16
|
// Services
|
|
17
17
|
motionSensorService: Service;
|
|
18
18
|
lightSensorService?: Service;
|
|
19
|
-
batteryService
|
|
19
|
+
batteryService: Service;
|
|
20
20
|
|
|
21
21
|
// Characteristic Values
|
|
22
22
|
MotionDetected!: CharacteristicValue;
|
|
23
23
|
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
24
|
-
BatteryLevel
|
|
25
|
-
StatusLowBattery
|
|
24
|
+
BatteryLevel!: CharacteristicValue;
|
|
25
|
+
StatusLowBattery!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI Others
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
deviceStatus
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
29
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
30
|
+
OpenAPI_MotionDetected: deviceStatus['moveDetected'];
|
|
31
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
32
|
+
|
|
33
|
+
// Status
|
|
34
|
+
BLE_BatteryLevel!: serviceData['battery'];
|
|
35
|
+
BLE_MotionDetected!: serviceData['movement'];
|
|
36
|
+
BLE_CurrentAmbientLightLevel!: serviceData['lightLevel'];
|
|
33
37
|
|
|
34
38
|
// BLE Others
|
|
35
39
|
scanning!: boolean;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
serviceData!: serviceData;
|
|
39
|
-
address!: ad['address'];
|
|
40
|
-
battery!: serviceData['battery'];
|
|
41
|
-
movement!: serviceData['movement'];
|
|
42
|
-
lightLevel!: serviceData['lightLevel'];
|
|
43
|
-
is_light!: any; //serviceData['is_light'];
|
|
40
|
+
BLE_IsConnected?: boolean;
|
|
41
|
+
/*is_light!: any; //serviceData['is_light'];
|
|
44
42
|
tested!: any;
|
|
45
43
|
led!: any;
|
|
46
44
|
iot!: any;
|
|
47
|
-
sense_distance!: any
|
|
45
|
+
sense_distance!: any;*/
|
|
48
46
|
|
|
49
47
|
// Config
|
|
50
48
|
set_minLux!: number;
|
|
@@ -126,19 +124,14 @@ export class Motion {
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
// Battery Service
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.batteryService.
|
|
135
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
136
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
137
|
-
}
|
|
138
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
139
|
-
} else {
|
|
140
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
127
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
128
|
+
`${accessory.displayName} Battery`;
|
|
129
|
+
|
|
130
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
131
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
132
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
141
133
|
}
|
|
134
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
142
135
|
|
|
143
136
|
// Retrieve initial values and updateHomekit
|
|
144
137
|
this.updateHomeKitCharacteristics();
|
|
@@ -172,7 +165,7 @@ export class Motion {
|
|
|
172
165
|
async BLEparseStatus(): Promise<void> {
|
|
173
166
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
174
167
|
// Movement
|
|
175
|
-
this.MotionDetected = this.
|
|
168
|
+
this.MotionDetected = this.BLE_MotionDetected!;
|
|
176
169
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
177
170
|
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
178
171
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
@@ -181,7 +174,7 @@ export class Motion {
|
|
|
181
174
|
if (!this.device.motion?.hide_lightsensor) {
|
|
182
175
|
this.set_minLux = this.minLux();
|
|
183
176
|
this.set_maxLux = this.maxLux();
|
|
184
|
-
switch (this.
|
|
177
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
185
178
|
case 'dark':
|
|
186
179
|
case 1:
|
|
187
180
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
@@ -190,7 +183,7 @@ export class Motion {
|
|
|
190
183
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
191
184
|
}
|
|
192
185
|
this.debugLog(
|
|
193
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
186
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
194
187
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
195
188
|
);
|
|
196
189
|
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
@@ -198,10 +191,10 @@ export class Motion {
|
|
|
198
191
|
}
|
|
199
192
|
}
|
|
200
193
|
// Battery
|
|
201
|
-
if (this.
|
|
202
|
-
this.
|
|
194
|
+
if (this.BLE_BatteryLevel === undefined) {
|
|
195
|
+
this.BLE_BatteryLevel = 100;
|
|
203
196
|
}
|
|
204
|
-
this.BatteryLevel = this.
|
|
197
|
+
this.BatteryLevel = this.BLE_BatteryLevel!;
|
|
205
198
|
if (this.BatteryLevel < 10) {
|
|
206
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
207
200
|
} else {
|
|
@@ -215,13 +208,13 @@ export class Motion {
|
|
|
215
208
|
async openAPIparseStatus(): Promise<void> {
|
|
216
209
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
217
210
|
// Motion State
|
|
218
|
-
this.MotionDetected = this.
|
|
211
|
+
this.MotionDetected = this.OpenAPI_MotionDetected!;
|
|
219
212
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
220
213
|
// Light Level
|
|
221
214
|
if (!this.device.motion?.hide_lightsensor) {
|
|
222
215
|
this.set_minLux = this.minLux();
|
|
223
216
|
this.set_maxLux = this.maxLux();
|
|
224
|
-
switch (this.
|
|
217
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
225
218
|
case 'dim':
|
|
226
219
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
227
220
|
break;
|
|
@@ -232,10 +225,10 @@ export class Motion {
|
|
|
232
225
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
233
226
|
}
|
|
234
227
|
// Battery
|
|
235
|
-
if (this.
|
|
236
|
-
this.
|
|
228
|
+
if (this.OpenAPI_BatteryLevel === undefined) {
|
|
229
|
+
this.OpenAPI_BatteryLevel = 100;
|
|
237
230
|
}
|
|
238
|
-
this.BatteryLevel = this.
|
|
231
|
+
this.BatteryLevel = this.OpenAPI_BatteryLevel!;
|
|
239
232
|
if (this.BatteryLevel < 10) {
|
|
240
233
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
241
234
|
} else {
|
|
@@ -290,37 +283,30 @@ export class Motion {
|
|
|
290
283
|
fn: async () => {
|
|
291
284
|
// Set an event hander
|
|
292
285
|
this.scanning = true;
|
|
293
|
-
switchbot.onadvertisement = async (ad:
|
|
294
|
-
this.address = ad.address;
|
|
286
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
295
287
|
this.debugLog(
|
|
296
288
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
297
|
-
` BLE Address Found: ${
|
|
289
|
+
` BLE Address Found: ${ad.address}`,
|
|
298
290
|
);
|
|
299
|
-
this.
|
|
300
|
-
this.
|
|
301
|
-
this.
|
|
302
|
-
this.battery = ad.serviceData.battery;
|
|
303
|
-
this.led = ad.serviceData.led;
|
|
304
|
-
this.iot = ad.serviceData.led;
|
|
305
|
-
this.sense_distance = ad.serviceData.sense_distance;
|
|
306
|
-
this.lightLevel = ad.serviceData.lightLevel;
|
|
307
|
-
this.is_light = ad.serviceData.is_light;
|
|
291
|
+
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
292
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
293
|
+
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
308
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
309
295
|
this.debugLog(
|
|
310
|
-
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}
|
|
311
|
-
|
|
296
|
+
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement},`
|
|
297
|
+
+ ` lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
312
298
|
);
|
|
313
299
|
|
|
314
|
-
if (
|
|
315
|
-
this.
|
|
316
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
300
|
+
if (ad.serviceData) {
|
|
301
|
+
this.BLE_IsConnected = true;
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
317
303
|
this.debugErrorLog('1');
|
|
318
304
|
await this.stopScanning(switchbot);
|
|
319
305
|
this.scanning = false;
|
|
320
306
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
|
|
321
307
|
} else {
|
|
322
|
-
this.
|
|
323
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
308
|
+
this.BLE_IsConnected = false;
|
|
309
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
324
310
|
}
|
|
325
311
|
};
|
|
326
312
|
// Wait
|
|
@@ -362,10 +348,10 @@ export class Motion {
|
|
|
362
348
|
this.statusCode(statusCode);
|
|
363
349
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
364
350
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
365
|
-
this.
|
|
366
|
-
this.
|
|
367
|
-
this.
|
|
368
|
-
this.
|
|
351
|
+
this.OpenAPI_MotionDetected = deviceStatus.body.moveDetected;
|
|
352
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
353
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
354
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
369
355
|
this.openAPIparseStatus();
|
|
370
356
|
this.updateHomeKitCharacteristics();
|
|
371
357
|
} catch (e: any) {
|
|
@@ -414,11 +400,21 @@ export class Motion {
|
|
|
414
400
|
);
|
|
415
401
|
}
|
|
416
402
|
}
|
|
403
|
+
// FirmwareRevision
|
|
404
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
405
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
406
|
+
} else {
|
|
407
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
408
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
409
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
410
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
411
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
412
|
+
}
|
|
417
413
|
}
|
|
418
414
|
|
|
419
415
|
async stopScanning(switchbot: any) {
|
|
420
416
|
await switchbot.stopScan();
|
|
421
|
-
if (this.
|
|
417
|
+
if (this.BLE_IsConnected) {
|
|
422
418
|
await this.BLEparseStatus();
|
|
423
419
|
await this.updateHomeKitCharacteristics();
|
|
424
420
|
} else {
|
package/src/device/plug.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
export class Plug {
|
|
11
11
|
// Services
|
|
@@ -15,22 +15,12 @@ export class Plug {
|
|
|
15
15
|
On!: CharacteristicValue;
|
|
16
16
|
|
|
17
17
|
// OpenAPI Others
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
18
|
+
OpenAPI_On: deviceStatus['power'];
|
|
19
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
21
20
|
|
|
22
21
|
// BLE Others
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
address!: ad['address'];
|
|
26
|
-
serviceData!: serviceData;
|
|
27
|
-
state: serviceData['state'];
|
|
28
|
-
delay: serviceData['delay'];
|
|
29
|
-
timer: serviceData['timer'];
|
|
30
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
31
|
-
overload: serviceData['overload'];
|
|
32
|
-
syncUtcTime: serviceData['syncUtcTime'];
|
|
33
|
-
currentPower: serviceData['currentPower'];
|
|
22
|
+
BLE_IsConnected?: boolean;
|
|
23
|
+
BLE_On: serviceData['state'];
|
|
34
24
|
|
|
35
25
|
// Config
|
|
36
26
|
scanDuration!: number;
|
|
@@ -149,7 +139,7 @@ export class Plug {
|
|
|
149
139
|
async BLEparseStatus(): Promise<void> {
|
|
150
140
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
151
141
|
// State
|
|
152
|
-
switch (this.
|
|
142
|
+
switch (this.BLE_On) {
|
|
153
143
|
case 'on':
|
|
154
144
|
this.On = true;
|
|
155
145
|
break;
|
|
@@ -161,7 +151,7 @@ export class Plug {
|
|
|
161
151
|
|
|
162
152
|
async openAPIparseStatus() {
|
|
163
153
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
164
|
-
switch (this.
|
|
154
|
+
switch (this.OpenAPI_On) {
|
|
165
155
|
case 'on':
|
|
166
156
|
this.On = true;
|
|
167
157
|
break;
|
|
@@ -209,20 +199,12 @@ export class Plug {
|
|
|
209
199
|
})
|
|
210
200
|
.then(async () => {
|
|
211
201
|
// Set an event hander
|
|
212
|
-
switchbot.onadvertisement = async (ad:
|
|
213
|
-
this.address = ad.address;
|
|
202
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
214
203
|
this.debugLog(
|
|
215
204
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
216
|
-
` BLE Address Found: ${
|
|
205
|
+
` BLE Address Found: ${ad.address}`,
|
|
217
206
|
);
|
|
218
|
-
this.
|
|
219
|
-
this.state = ad.serviceData.state;
|
|
220
|
-
this.delay = ad.serviceData.delay;
|
|
221
|
-
this.timer = ad.serviceData.timer;
|
|
222
|
-
this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
223
|
-
this.wifiRssi = ad.serviceData.wifiRssi;
|
|
224
|
-
this.overload = ad.serviceData.overload;
|
|
225
|
-
this.currentPower = ad.serviceData.currentPower;
|
|
207
|
+
this.BLE_On = ad.serviceData.state;
|
|
226
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
227
209
|
this.debugLog(
|
|
228
210
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -230,13 +212,13 @@ export class Plug {
|
|
|
230
212
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
231
213
|
);
|
|
232
214
|
|
|
233
|
-
if (
|
|
234
|
-
this.
|
|
235
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
215
|
+
if (ad.serviceData) {
|
|
216
|
+
this.BLE_IsConnected = true;
|
|
217
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
236
218
|
await this.stopScanning(switchbot);
|
|
237
219
|
} else {
|
|
238
|
-
this.
|
|
239
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
220
|
+
this.BLE_IsConnected = false;
|
|
221
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
240
222
|
}
|
|
241
223
|
};
|
|
242
224
|
// Wait
|
|
@@ -270,7 +252,7 @@ export class Plug {
|
|
|
270
252
|
this.statusCode(statusCode);
|
|
271
253
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
272
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
273
|
-
this.
|
|
255
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
274
256
|
this.openAPIparseStatus();
|
|
275
257
|
this.updateHomeKitCharacteristics();
|
|
276
258
|
} catch (e: any) {
|
|
@@ -425,11 +407,21 @@ export class Plug {
|
|
|
425
407
|
this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
426
408
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
427
409
|
}
|
|
410
|
+
// FirmwareRevision
|
|
411
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
413
|
+
} else {
|
|
414
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
415
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
416
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
417
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
418
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
419
|
+
}
|
|
428
420
|
}
|
|
429
421
|
|
|
430
422
|
async stopScanning(switchbot: any) {
|
|
431
423
|
await switchbot.stopScan();
|
|
432
|
-
if (this.
|
|
424
|
+
if (this.BLE_IsConnected) {
|
|
433
425
|
await this.BLEparseStatus();
|
|
434
426
|
await this.updateHomeKitCharacteristics();
|
|
435
427
|
} else {
|