@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/contact.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
|
|
@@ -14,40 +14,34 @@ import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, Device
|
|
|
14
14
|
*/
|
|
15
15
|
export class Contact {
|
|
16
16
|
// Services
|
|
17
|
-
contactSensorservice: Service;
|
|
18
17
|
motionService?: Service;
|
|
18
|
+
batteryService: Service;
|
|
19
19
|
lightSensorService?: Service;
|
|
20
|
-
|
|
20
|
+
contactSensorservice: Service;
|
|
21
21
|
|
|
22
22
|
// Characteristic Values
|
|
23
|
-
ContactSensorState!: CharacteristicValue;
|
|
24
|
-
MotionDetected!: CharacteristicValue;
|
|
25
|
-
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
26
23
|
BatteryLevel!: CharacteristicValue;
|
|
24
|
+
MotionDetected!: CharacteristicValue;
|
|
27
25
|
StatusLowBattery!: CharacteristicValue;
|
|
26
|
+
ContactSensorState!: CharacteristicValue;
|
|
27
|
+
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
28
|
+
|
|
29
|
+
// OpenAPI Status
|
|
30
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
OpenAPI_MotionDetected: deviceStatus['moveDetected'];
|
|
33
|
+
OpenAPI_ContactSensorState: deviceStatus['openState'];
|
|
34
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
28
35
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
brightness: deviceStatus['brightness'];
|
|
35
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
36
|
+
// BLE Status
|
|
37
|
+
BLE_BateryLevel!: serviceData['battery'];
|
|
38
|
+
BLE_MotionDetected!: serviceData['movement'];
|
|
39
|
+
BLE_ContactSensorState!: serviceData['doorState'];
|
|
40
|
+
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
36
41
|
|
|
37
42
|
// BLE Others
|
|
38
|
-
tested!: any;
|
|
39
|
-
contact_open!: any;
|
|
40
|
-
button_count!: any;
|
|
41
43
|
scanning!: boolean;
|
|
42
|
-
|
|
43
|
-
contact_timeout!: any;
|
|
44
|
-
switchbot!: switchbot;
|
|
45
|
-
serviceData!: serviceData;
|
|
46
|
-
address!: ad['address'];
|
|
47
|
-
battery!: serviceData['battery'];
|
|
48
|
-
movement!: serviceData['movement'];
|
|
49
|
-
doorState!: serviceData['doorState'];
|
|
50
|
-
is_light!: any; //serviceData['lightLevel'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
51
45
|
|
|
52
46
|
// Config
|
|
53
47
|
set_minLux!: number;
|
|
@@ -147,19 +141,14 @@ export class Contact {
|
|
|
147
141
|
}
|
|
148
142
|
|
|
149
143
|
// Battery Service
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.batteryService.
|
|
156
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
157
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
158
|
-
}
|
|
159
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
160
|
-
} else {
|
|
161
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
144
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
145
|
+
`${accessory.displayName} Battery`;
|
|
146
|
+
|
|
147
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
148
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
149
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
162
150
|
}
|
|
151
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
163
152
|
|
|
164
153
|
// Retrieve initial values and updateHomekit
|
|
165
154
|
this.updateHomeKitCharacteristics();
|
|
@@ -193,7 +182,7 @@ export class Contact {
|
|
|
193
182
|
async BLEparseStatus(): Promise<void> {
|
|
194
183
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
195
184
|
// Door State
|
|
196
|
-
switch (this.
|
|
185
|
+
switch (this.BLE_ContactSensorState) {
|
|
197
186
|
case 'open':
|
|
198
187
|
case 1:
|
|
199
188
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
@@ -203,7 +192,7 @@ export class Contact {
|
|
|
203
192
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
204
193
|
break;
|
|
205
194
|
default:
|
|
206
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.
|
|
195
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.BLE_ContactSensorState}`);
|
|
207
196
|
}
|
|
208
197
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
209
198
|
if (
|
|
@@ -214,7 +203,7 @@ export class Contact {
|
|
|
214
203
|
}
|
|
215
204
|
// Movement
|
|
216
205
|
if (!this.device.contact?.hide_motionsensor) {
|
|
217
|
-
this.MotionDetected = Boolean(this.
|
|
206
|
+
this.MotionDetected = Boolean(this.BLE_MotionDetected);
|
|
218
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
219
208
|
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
220
209
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
@@ -224,7 +213,7 @@ export class Contact {
|
|
|
224
213
|
if (!this.device.contact?.hide_lightsensor) {
|
|
225
214
|
this.set_minLux = this.minLux();
|
|
226
215
|
this.set_maxLux = this.maxLux();
|
|
227
|
-
switch (this.
|
|
216
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
228
217
|
case true:
|
|
229
218
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
230
219
|
break;
|
|
@@ -232,7 +221,7 @@ export class Contact {
|
|
|
232
221
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
233
222
|
}
|
|
234
223
|
this.debugLog(
|
|
235
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
224
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
236
225
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
237
226
|
);
|
|
238
227
|
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
@@ -240,10 +229,10 @@ export class Contact {
|
|
|
240
229
|
}
|
|
241
230
|
}
|
|
242
231
|
// Battery
|
|
243
|
-
if (this.
|
|
244
|
-
this.
|
|
232
|
+
if (this.BLE_BateryLevel === undefined) {
|
|
233
|
+
this.BLE_BateryLevel === 100;
|
|
245
234
|
}
|
|
246
|
-
this.BatteryLevel = Number(this.
|
|
235
|
+
this.BatteryLevel = Number(this.BLE_BateryLevel);
|
|
247
236
|
if (this.BatteryLevel < 10) {
|
|
248
237
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
249
238
|
} else {
|
|
@@ -257,25 +246,25 @@ export class Contact {
|
|
|
257
246
|
async openAPIparseStatus(): Promise<void> {
|
|
258
247
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
259
248
|
// Contact State
|
|
260
|
-
if (this.
|
|
249
|
+
if (this.OpenAPI_ContactSensorState === 'open') {
|
|
261
250
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
262
251
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
263
|
-
} else if (this.
|
|
252
|
+
} else if (this.OpenAPI_ContactSensorState === 'close') {
|
|
264
253
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
265
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
266
255
|
} else {
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.
|
|
256
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.OpenAPI_ContactSensorState}`);
|
|
268
257
|
}
|
|
269
258
|
// Motion State
|
|
270
259
|
if (!this.device.contact?.hide_motionsensor) {
|
|
271
|
-
this.MotionDetected = this.
|
|
260
|
+
this.MotionDetected = this.OpenAPI_MotionDetected!;
|
|
272
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
273
262
|
}
|
|
274
263
|
// Light Level
|
|
275
264
|
if (!this.device.contact?.hide_lightsensor) {
|
|
276
265
|
this.set_minLux = this.minLux();
|
|
277
266
|
this.set_maxLux = this.maxLux();
|
|
278
|
-
switch (this.
|
|
267
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
279
268
|
case 'dim':
|
|
280
269
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
281
270
|
break;
|
|
@@ -286,10 +275,10 @@ export class Contact {
|
|
|
286
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
287
276
|
}
|
|
288
277
|
// Battery
|
|
289
|
-
if (this.
|
|
290
|
-
this.
|
|
278
|
+
if (this.OpenAPI_BatteryLevel === undefined) {
|
|
279
|
+
this.OpenAPI_BatteryLevel === 100;
|
|
291
280
|
}
|
|
292
|
-
this.BatteryLevel = Number(this.
|
|
281
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
293
282
|
if (this.BatteryLevel < 10) {
|
|
294
283
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
295
284
|
} else {
|
|
@@ -341,35 +330,28 @@ export class Contact {
|
|
|
341
330
|
.then(async () => {
|
|
342
331
|
// Set an event hander
|
|
343
332
|
this.scanning = true;
|
|
344
|
-
switchbot.onadvertisement = async (ad:
|
|
345
|
-
this.address = ad.address;
|
|
333
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
346
334
|
this.debugLog(
|
|
347
335
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
348
|
-
` BLE Address Found: ${
|
|
336
|
+
` BLE Address Found: ${ad.address}`,
|
|
349
337
|
);
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.battery = ad.serviceData.battery;
|
|
354
|
-
this.contact_open = ad.serviceData.contact_open;
|
|
355
|
-
this.contact_timeout = ad.serviceData.contact_timeout;
|
|
356
|
-
this.is_light = ad.serviceData.is_light;
|
|
357
|
-
this.button_count = ad.serviceData.button_count;
|
|
358
|
-
this.doorState = ad.serviceData.doorState;
|
|
338
|
+
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
339
|
+
this.BLE_BateryLevel = ad.serviceData.battery;
|
|
340
|
+
this.BLE_ContactSensorState = ad.serviceData.doorState;
|
|
359
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
360
342
|
this.debugLog(
|
|
361
343
|
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
362
|
-
`${ad.serviceData.doorState},
|
|
344
|
+
`${ad.serviceData.doorState}, battery: ${ad.serviceData.battery}`,
|
|
363
345
|
);
|
|
364
346
|
|
|
365
|
-
if (
|
|
366
|
-
this.
|
|
367
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
347
|
+
if (ad.serviceData) {
|
|
348
|
+
this.BLE_IsConnected = true;
|
|
349
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
368
350
|
await this.stopScanning(switchbot);
|
|
369
351
|
this.scanning = false;
|
|
370
352
|
} else {
|
|
371
|
-
this.
|
|
372
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
353
|
+
this.BLE_IsConnected = false;
|
|
354
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
373
355
|
}
|
|
374
356
|
};
|
|
375
357
|
// Wait
|
|
@@ -405,11 +387,11 @@ export class Contact {
|
|
|
405
387
|
this.statusCode(statusCode);
|
|
406
388
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
407
389
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
408
|
-
this.
|
|
409
|
-
this.
|
|
410
|
-
this.
|
|
411
|
-
this.
|
|
412
|
-
this.
|
|
390
|
+
this.OpenAPI_ContactSensorState = deviceStatus.body.openState;
|
|
391
|
+
this.OpenAPI_MotionDetected = deviceStatus.body.moveDetected;
|
|
392
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
393
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
394
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
413
395
|
this.openAPIparseStatus();
|
|
414
396
|
this.updateHomeKitCharacteristics();
|
|
415
397
|
} catch (e: any) {
|
|
@@ -467,11 +449,21 @@ export class Contact {
|
|
|
467
449
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
468
450
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
469
451
|
}
|
|
452
|
+
// FirmwareRevision
|
|
453
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
454
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
455
|
+
} else {
|
|
456
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
457
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
458
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
459
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
460
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
461
|
+
}
|
|
470
462
|
}
|
|
471
463
|
|
|
472
464
|
async stopScanning(switchbot: any) {
|
|
473
465
|
await switchbot.stopScan();
|
|
474
|
-
if (this.
|
|
466
|
+
if (this.BLE_IsConnected) {
|
|
475
467
|
await this.BLEparseStatus();
|
|
476
468
|
await this.updateHomeKitCharacteristics();
|
|
477
469
|
} else {
|
package/src/device/curtain.ts
CHANGED
|
@@ -7,45 +7,44 @@ import { connectAsync } from 'async-mqtt';
|
|
|
7
7
|
import { SwitchBotPlatform } from '../platform';
|
|
8
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue, CharacteristicChange } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, serviceData,
|
|
10
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
11
11
|
import { hostname } from 'os';
|
|
12
12
|
|
|
13
13
|
export class Curtain {
|
|
14
14
|
// Services
|
|
15
|
-
|
|
15
|
+
batteryService: Service;
|
|
16
16
|
lightSensorService?: Service;
|
|
17
|
-
|
|
17
|
+
windowCoveringService: Service;
|
|
18
18
|
|
|
19
19
|
// Characteristic Values
|
|
20
|
-
|
|
20
|
+
BatteryLevel!: CharacteristicValue;
|
|
21
21
|
PositionState!: CharacteristicValue;
|
|
22
22
|
TargetPosition!: CharacteristicValue;
|
|
23
|
+
CurrentPosition!: CharacteristicValue;
|
|
24
|
+
StatusLowBattery!: CharacteristicValue;
|
|
23
25
|
CurrentAmbientLightLevel?: CharacteristicValue;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
// OpenAPI Status
|
|
28
|
+
OpenAPI_InMotion: deviceStatus['moving'];
|
|
29
|
+
OpenAPI_BatterLevel: deviceStatus['battery'];
|
|
30
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
31
|
+
OpenAPI_CurrentPosition: deviceStatus['slidePosition'];
|
|
32
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
27
33
|
|
|
28
34
|
// OpenAPI Others
|
|
29
|
-
Version: deviceStatus['version'];
|
|
30
|
-
Battery: deviceStatus['battery'];
|
|
31
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
32
|
-
slidePosition: deviceStatus['slidePosition'];
|
|
33
|
-
moving: deviceStatus['moving'];
|
|
34
|
-
brightness: deviceStatus['brightness'];
|
|
35
|
-
setPositionMode?: string | number;
|
|
36
35
|
Mode!: string;
|
|
36
|
+
setPositionMode?: string | number;
|
|
37
|
+
|
|
38
|
+
// BLE Status
|
|
39
|
+
BLE_Battery: serviceData['battery'];
|
|
40
|
+
BLE_InMotion: serviceData['inMotion'];
|
|
41
|
+
BLE_Calibration: serviceData['calibration'];
|
|
42
|
+
BLE_CurrentPosition: serviceData['position'];
|
|
43
|
+
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
37
44
|
|
|
38
45
|
// BLE Others
|
|
39
|
-
|
|
40
|
-
switchbot!: switchbot;
|
|
41
|
-
serviceData!: serviceData;
|
|
46
|
+
BLE_IsConnected?: boolean;
|
|
42
47
|
spaceBetweenLevels!: number;
|
|
43
|
-
address!: ad['address'];
|
|
44
|
-
calibration: serviceData['calibration'];
|
|
45
|
-
battery: serviceData['battery'];
|
|
46
|
-
position: serviceData['position'];
|
|
47
|
-
inMotion: serviceData['inMotion'];
|
|
48
|
-
lightLevel: serviceData['lightLevel'];
|
|
49
48
|
|
|
50
49
|
// Target
|
|
51
50
|
setNewTarget!: boolean;
|
|
@@ -55,15 +54,15 @@ export class Curtain {
|
|
|
55
54
|
mqttClient: MqttClient | null = null;
|
|
56
55
|
|
|
57
56
|
// Config
|
|
58
|
-
set_minStep!: number;
|
|
59
57
|
updateRate!: number;
|
|
60
58
|
set_minLux!: number;
|
|
61
59
|
set_maxLux!: number;
|
|
60
|
+
set_minStep!: number;
|
|
61
|
+
setOpenMode!: string;
|
|
62
|
+
setCloseMode!: string;
|
|
62
63
|
scanDuration!: number;
|
|
63
64
|
deviceLogging!: string;
|
|
64
65
|
deviceRefreshRate!: number;
|
|
65
|
-
setCloseMode!: string;
|
|
66
|
-
setOpenMode!: string;
|
|
67
66
|
|
|
68
67
|
// Updates
|
|
69
68
|
curtainUpdateInProgress!: boolean;
|
|
@@ -172,18 +171,12 @@ export class Curtain {
|
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
// Battery Service
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.batteryService.
|
|
181
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
182
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
183
|
-
}
|
|
184
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
185
|
-
} else {
|
|
186
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
174
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
175
|
+
`${accessory.displayName} Battery`;
|
|
176
|
+
|
|
177
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
178
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
179
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
187
180
|
}
|
|
188
181
|
|
|
189
182
|
// Update Homekit
|
|
@@ -314,7 +307,7 @@ export class Curtain {
|
|
|
314
307
|
async BLEparseStatus(): Promise<void> {
|
|
315
308
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
316
309
|
// CurrentPosition
|
|
317
|
-
this.CurrentPosition = 100 - Number(this.
|
|
310
|
+
this.CurrentPosition = 100 - Number(this.BLE_CurrentPosition);
|
|
318
311
|
await this.setMinMax();
|
|
319
312
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
320
313
|
if (this.setNewTarget) {
|
|
@@ -353,45 +346,45 @@ export class Curtain {
|
|
|
353
346
|
this.spaceBetweenLevels = 9;
|
|
354
347
|
|
|
355
348
|
// Brightness
|
|
356
|
-
switch (this.
|
|
349
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
357
350
|
case 1:
|
|
358
351
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
359
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
352
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
360
353
|
break;
|
|
361
354
|
case 2:
|
|
362
355
|
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
363
356
|
this.debugLog(
|
|
364
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
357
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
365
358
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
366
359
|
);
|
|
367
360
|
break;
|
|
368
361
|
case 3:
|
|
369
362
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
370
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
363
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
371
364
|
break;
|
|
372
365
|
case 4:
|
|
373
366
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
374
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
367
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
375
368
|
break;
|
|
376
369
|
case 5:
|
|
377
370
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
378
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
379
372
|
break;
|
|
380
373
|
case 6:
|
|
381
374
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
382
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
375
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
383
376
|
break;
|
|
384
377
|
case 7:
|
|
385
378
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
386
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
379
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
387
380
|
break;
|
|
388
381
|
case 8:
|
|
389
382
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
390
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
383
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
391
384
|
break;
|
|
392
385
|
case 9:
|
|
393
386
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
394
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
395
388
|
break;
|
|
396
389
|
case 10:
|
|
397
390
|
default:
|
|
@@ -399,12 +392,12 @@ export class Curtain {
|
|
|
399
392
|
this.debugLog();
|
|
400
393
|
}
|
|
401
394
|
this.debugLog(
|
|
402
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
395
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
403
396
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
404
397
|
);
|
|
405
398
|
}
|
|
406
399
|
// Battery
|
|
407
|
-
this.BatteryLevel = Number(this.
|
|
400
|
+
this.BatteryLevel = Number(this.BLE_Battery);
|
|
408
401
|
if (this.BatteryLevel < 10) {
|
|
409
402
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
410
403
|
} else {
|
|
@@ -418,14 +411,14 @@ export class Curtain {
|
|
|
418
411
|
async openAPIparseStatus(): Promise<void> {
|
|
419
412
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
420
413
|
// CurrentPosition
|
|
421
|
-
this.CurrentPosition = 100 - Number(this.
|
|
414
|
+
this.CurrentPosition = 100 - Number(this.OpenAPI_CurrentPosition);
|
|
422
415
|
await this.setMinMax();
|
|
423
416
|
this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
424
417
|
if (this.setNewTarget) {
|
|
425
418
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
426
419
|
}
|
|
427
420
|
|
|
428
|
-
if (this.setNewTarget && this.
|
|
421
|
+
if (this.setNewTarget && this.OpenAPI_InMotion) {
|
|
429
422
|
await this.setMinMax();
|
|
430
423
|
if (Number(this.TargetPosition) > this.CurrentPosition) {
|
|
431
424
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
@@ -458,7 +451,7 @@ export class Curtain {
|
|
|
458
451
|
this.set_minLux = this.minLux();
|
|
459
452
|
this.set_maxLux = this.maxLux();
|
|
460
453
|
// Brightness
|
|
461
|
-
switch (this.
|
|
454
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
462
455
|
case 'dim':
|
|
463
456
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
464
457
|
break;
|
|
@@ -505,18 +498,16 @@ export class Curtain {
|
|
|
505
498
|
})
|
|
506
499
|
.then(async () => {
|
|
507
500
|
// Set an event hander
|
|
508
|
-
switchbot.onadvertisement = async (ad:
|
|
509
|
-
this.address = ad.address;
|
|
501
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
510
502
|
this.debugLog(
|
|
511
503
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
512
|
-
` BLE Address Found: ${
|
|
504
|
+
` BLE Address Found: ${ad.address}`,
|
|
513
505
|
);
|
|
514
|
-
this.
|
|
515
|
-
this.
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
519
|
-
this.lightLevel = ad.serviceData.lightLevel;
|
|
506
|
+
this.BLE_Calibration = ad.serviceData.calibration;
|
|
507
|
+
this.BLE_Battery = ad.serviceData.battery;
|
|
508
|
+
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
509
|
+
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
510
|
+
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
520
511
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
521
512
|
this.debugLog(
|
|
522
513
|
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
@@ -524,13 +515,13 @@ export class Curtain {
|
|
|
524
515
|
`inMotion: ${ad.serviceData.inMotion}`,
|
|
525
516
|
);
|
|
526
517
|
|
|
527
|
-
if (
|
|
528
|
-
this.
|
|
529
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
518
|
+
if (ad.serviceData) {
|
|
519
|
+
this.BLE_IsConnected = true;
|
|
520
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
530
521
|
await this.stopScanning(switchbot);
|
|
531
522
|
} else {
|
|
532
|
-
this.
|
|
533
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
523
|
+
this.BLE_IsConnected = false;
|
|
524
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
534
525
|
}
|
|
535
526
|
};
|
|
536
527
|
// Wait
|
|
@@ -564,11 +555,11 @@ export class Curtain {
|
|
|
564
555
|
this.statusCode(statusCode);
|
|
565
556
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
566
557
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
567
|
-
this.
|
|
568
|
-
this.
|
|
569
|
-
this.
|
|
570
|
-
this.
|
|
571
|
-
this.
|
|
558
|
+
this.OpenAPI_CurrentPosition = deviceStatus.body.slidePosition;
|
|
559
|
+
this.OpenAPI_InMotion = deviceStatus.body.moving;
|
|
560
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
561
|
+
this.OpenAPI_BatterLevel = deviceStatus.body.battery;
|
|
562
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
572
563
|
this.openAPIparseStatus();
|
|
573
564
|
this.updateHomeKitCharacteristics();
|
|
574
565
|
} catch (e: any) {
|
|
@@ -844,6 +835,16 @@ export class Curtain {
|
|
|
844
835
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
845
836
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
846
837
|
}
|
|
838
|
+
// FirmwareRevision
|
|
839
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
840
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
841
|
+
} else {
|
|
842
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
843
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
844
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
845
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
846
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
847
|
+
}
|
|
847
848
|
}
|
|
848
849
|
|
|
849
850
|
/*
|
|
@@ -880,7 +881,7 @@ export class Curtain {
|
|
|
880
881
|
|
|
881
882
|
async stopScanning(switchbot: any) {
|
|
882
883
|
await switchbot.stopScan();
|
|
883
|
-
if (this.
|
|
884
|
+
if (this.BLE_IsConnected) {
|
|
884
885
|
await this.BLEparseStatus();
|
|
885
886
|
await this.updateHomeKitCharacteristics();
|
|
886
887
|
} else {
|