@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
|
@@ -5,7 +5,7 @@ import { sleep } from '../utils';
|
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
|
-
import { device, devicesConfig, deviceStatus,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -24,22 +24,20 @@ export class CeilingLight {
|
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
ColorTemperature?: CharacteristicValue;
|
|
26
26
|
|
|
27
|
-
// OpenAPI
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// OpenAPI Status
|
|
28
|
+
OpenAPI_On: deviceStatus['power'];
|
|
29
|
+
OpenAPI_RGB: deviceStatus['color'];
|
|
30
|
+
OpenAPI_Brightness: deviceStatus['brightness'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
|
|
33
|
+
|
|
34
|
+
// BLE Status
|
|
35
|
+
BLE_Delay: serviceData['delay'];
|
|
36
|
+
BLE_On: serviceData['state'];
|
|
37
|
+
BLE_WifiRssi: serviceData['wifiRssi'];
|
|
34
38
|
|
|
35
39
|
// BLE Others
|
|
36
|
-
|
|
37
|
-
switchbot!: switchbot;
|
|
38
|
-
address!: ad['address'];
|
|
39
|
-
serviceData!: serviceData;
|
|
40
|
-
state: serviceData['state'];
|
|
41
|
-
delay: serviceData['delay'];
|
|
42
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
40
|
+
BLE_IsConnected?: boolean;
|
|
43
41
|
|
|
44
42
|
// Config
|
|
45
43
|
set_minStep?: number;
|
|
@@ -252,7 +250,7 @@ export class CeilingLight {
|
|
|
252
250
|
async BLEparseStatus(): Promise<void> {
|
|
253
251
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
254
252
|
// State
|
|
255
|
-
switch (this.
|
|
253
|
+
switch (this.BLE_On) {
|
|
256
254
|
case 'on':
|
|
257
255
|
this.On = true;
|
|
258
256
|
break;
|
|
@@ -264,7 +262,7 @@ export class CeilingLight {
|
|
|
264
262
|
|
|
265
263
|
async openAPIparseStatus() {
|
|
266
264
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
267
|
-
switch (this.
|
|
265
|
+
switch (this.OpenAPI_On) {
|
|
268
266
|
case 'on':
|
|
269
267
|
this.On = true;
|
|
270
268
|
break;
|
|
@@ -274,13 +272,13 @@ export class CeilingLight {
|
|
|
274
272
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
275
273
|
|
|
276
274
|
// Brightness
|
|
277
|
-
this.Brightness = Number(this.
|
|
275
|
+
this.Brightness = Number(this.OpenAPI_Brightness);
|
|
278
276
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
279
277
|
|
|
280
278
|
// Color, Hue & Brightness
|
|
281
|
-
if (this.
|
|
282
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
283
|
-
const [red, green, blue] = this.
|
|
279
|
+
if (this.OpenAPI_RGB) {
|
|
280
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
|
|
281
|
+
const [red, green, blue] = this.OpenAPI_RGB!.split(':');
|
|
284
282
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
285
283
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
286
284
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -300,9 +298,9 @@ export class CeilingLight {
|
|
|
300
298
|
}
|
|
301
299
|
|
|
302
300
|
// ColorTemperature
|
|
303
|
-
if (!Number.isNaN(this.
|
|
304
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.
|
|
305
|
-
const mired = Math.round(1000000 / this.
|
|
301
|
+
if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
|
|
303
|
+
const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
|
|
306
304
|
|
|
307
305
|
this.ColorTemperature = Number(mired);
|
|
308
306
|
|
|
@@ -349,15 +347,13 @@ export class CeilingLight {
|
|
|
349
347
|
})
|
|
350
348
|
.then(async () => {
|
|
351
349
|
// Set an event hander
|
|
352
|
-
switchbot.onadvertisement = async (ad:
|
|
353
|
-
this.address = ad.address;
|
|
350
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
354
351
|
this.debugLog(
|
|
355
352
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
356
|
-
` BLE Address Found: ${
|
|
353
|
+
` BLE Address Found: ${ad.address}`,
|
|
357
354
|
);
|
|
358
355
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
359
|
-
this.
|
|
360
|
-
//this.state = ad.serviceData.state;
|
|
356
|
+
this.BLE_On = ad.serviceData.state;
|
|
361
357
|
//this.delay = ad.serviceData.delay;
|
|
362
358
|
//this.timer = ad.serviceData.timer;
|
|
363
359
|
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
@@ -371,13 +367,13 @@ export class CeilingLight {
|
|
|
371
367
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
372
368
|
);*/
|
|
373
369
|
|
|
374
|
-
if (
|
|
375
|
-
this.
|
|
376
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
370
|
+
if (ad.serviceData) {
|
|
371
|
+
this.BLE_IsConnected = true;
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
377
373
|
await this.stopScanning(switchbot);
|
|
378
374
|
} else {
|
|
379
|
-
this.
|
|
380
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
375
|
+
this.BLE_IsConnected = false;
|
|
376
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
381
377
|
}
|
|
382
378
|
};
|
|
383
379
|
// Wait
|
|
@@ -411,10 +407,11 @@ export class CeilingLight {
|
|
|
411
407
|
this.statusCode(statusCode);
|
|
412
408
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
413
409
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
414
|
-
this.
|
|
415
|
-
this.
|
|
416
|
-
this.
|
|
417
|
-
this.
|
|
410
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
411
|
+
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
412
|
+
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
413
|
+
this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
|
|
414
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
418
415
|
this.openAPIparseStatus();
|
|
419
416
|
this.updateHomeKitCharacteristics();
|
|
420
417
|
} catch (e: any) {
|
|
@@ -802,6 +799,16 @@ export class CeilingLight {
|
|
|
802
799
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
803
800
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
804
801
|
}
|
|
802
|
+
// FirmwareRevision
|
|
803
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
804
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
805
|
+
} else {
|
|
806
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
807
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
808
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
809
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
810
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
811
|
+
}
|
|
805
812
|
}
|
|
806
813
|
|
|
807
814
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
@@ -816,7 +823,7 @@ export class CeilingLight {
|
|
|
816
823
|
|
|
817
824
|
async stopScanning(switchbot: any) {
|
|
818
825
|
await switchbot.stopScan();
|
|
819
|
-
if (this.
|
|
826
|
+
if (this.BLE_IsConnected) {
|
|
820
827
|
await this.BLEparseStatus();
|
|
821
828
|
await this.updateHomeKitCharacteristics();
|
|
822
829
|
} else {
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { sleep } from '../utils';
|
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
|
-
import { device, devicesConfig, deviceStatus,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -24,32 +24,26 @@ export class ColorBulb {
|
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
ColorTemperature?: CharacteristicValue;
|
|
26
26
|
|
|
27
|
-
// OpenAPI
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// OpenAPI Status
|
|
28
|
+
OpenAPI_On: deviceStatus['power'];
|
|
29
|
+
OpenAPI_RGB: deviceStatus['color'];
|
|
30
|
+
OpenAPI_Brightness: deviceStatus['brightness'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
|
|
33
|
+
|
|
34
|
+
// BLE Status
|
|
35
|
+
BLE_Red: serviceData['red'];
|
|
36
|
+
BLE_On: serviceData['state'];
|
|
37
|
+
BLE_Blue: serviceData['blue'];
|
|
38
|
+
BLE_Power: serviceData['power'];
|
|
39
|
+
BLE_Green: serviceData['green'];
|
|
40
|
+
BLE_Delay: serviceData['delay'];
|
|
41
|
+
BLE_WifiRssi: serviceData['wifiRssi'];
|
|
42
|
+
BLE_Brightness: serviceData['brightness'];
|
|
43
|
+
BLE_ColorTemperature: serviceData['color_temperature'];
|
|
34
44
|
|
|
35
45
|
// BLE Others
|
|
36
|
-
|
|
37
|
-
switchbot!: switchbot;
|
|
38
|
-
address!: ad['address'];
|
|
39
|
-
serviceData!: serviceData;
|
|
40
|
-
powerState: serviceData['power'];
|
|
41
|
-
state: serviceData['state'];
|
|
42
|
-
red: serviceData['red'];
|
|
43
|
-
green: serviceData['green'];
|
|
44
|
-
blue: serviceData['blue'];
|
|
45
|
-
delay: serviceData['delay'];
|
|
46
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
47
|
-
brightnessBLE: serviceData['brightness'];
|
|
48
|
-
color_temperature: serviceData['color_temperature'];
|
|
49
|
-
preset: any; //serviceData['preset'];
|
|
50
|
-
color_mode: any; //serviceData['color_mode'];
|
|
51
|
-
speed: any; //serviceData['speed'];
|
|
52
|
-
loop_index: any; //serviceData['loop_index'];
|
|
46
|
+
BLE_IsConnected?: boolean;
|
|
53
47
|
|
|
54
48
|
// Config
|
|
55
49
|
set_minStep?: number;
|
|
@@ -250,7 +244,7 @@ export class ColorBulb {
|
|
|
250
244
|
async BLEparseStatus(): Promise<void> {
|
|
251
245
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
252
246
|
// State
|
|
253
|
-
switch (this.
|
|
247
|
+
switch (this.BLE_On) {
|
|
254
248
|
case true:
|
|
255
249
|
this.On = true;
|
|
256
250
|
break;
|
|
@@ -260,18 +254,18 @@ export class ColorBulb {
|
|
|
260
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
261
255
|
|
|
262
256
|
// Brightness
|
|
263
|
-
this.Brightness = Number(this.
|
|
257
|
+
this.Brightness = Number(this.BLE_Brightness);
|
|
264
258
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
265
259
|
|
|
266
260
|
// Color, Hue & Brightness
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.
|
|
268
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.
|
|
269
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.
|
|
261
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.BLE_Red}`);
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.BLE_Green}`);
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.BLE_Blue}`);
|
|
270
264
|
|
|
271
|
-
const [hue, saturation] = rgb2hs(Number(this.
|
|
265
|
+
const [hue, saturation] = rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue));
|
|
272
266
|
this.debugLog(
|
|
273
267
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
274
|
-
` hs: ${JSON.stringify(rgb2hs(Number(this.
|
|
268
|
+
` hs: ${JSON.stringify(rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue)))}`,
|
|
275
269
|
);
|
|
276
270
|
|
|
277
271
|
// Hue
|
|
@@ -283,9 +277,9 @@ export class ColorBulb {
|
|
|
283
277
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
284
278
|
|
|
285
279
|
// ColorTemperature
|
|
286
|
-
if (this.
|
|
287
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.
|
|
288
|
-
this.ColorTemperature = this.
|
|
280
|
+
if (this.BLE_ColorTemperature) {
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.BLE_ColorTemperature}`);
|
|
282
|
+
this.ColorTemperature = this.BLE_ColorTemperature!;
|
|
289
283
|
|
|
290
284
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
291
285
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
@@ -294,7 +288,7 @@ export class ColorBulb {
|
|
|
294
288
|
|
|
295
289
|
async openAPIparseStatus() {
|
|
296
290
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
297
|
-
switch (this.
|
|
291
|
+
switch (this.OpenAPI_On) {
|
|
298
292
|
case 'on':
|
|
299
293
|
this.On = true;
|
|
300
294
|
break;
|
|
@@ -304,13 +298,13 @@ export class ColorBulb {
|
|
|
304
298
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
305
299
|
|
|
306
300
|
// Brightness
|
|
307
|
-
this.Brightness = Number(this.
|
|
301
|
+
this.Brightness = Number(this.OpenAPI_Brightness);
|
|
308
302
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
309
303
|
|
|
310
304
|
// Color, Hue & Brightness
|
|
311
|
-
if (this.
|
|
312
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
313
|
-
const [red, green, blue] = this.
|
|
305
|
+
if (this.OpenAPI_RGB) {
|
|
306
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
|
|
307
|
+
const [red, green, blue] = this.OpenAPI_RGB!.split(':');
|
|
314
308
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
315
309
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
316
310
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -330,9 +324,9 @@ export class ColorBulb {
|
|
|
330
324
|
}
|
|
331
325
|
|
|
332
326
|
// ColorTemperature
|
|
333
|
-
if (!Number.isNaN(this.
|
|
334
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.
|
|
335
|
-
const mired = Math.round(1000000 / this.
|
|
327
|
+
if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
|
|
328
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
|
|
329
|
+
const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
|
|
336
330
|
|
|
337
331
|
this.ColorTemperature = Number(mired);
|
|
338
332
|
|
|
@@ -379,26 +373,20 @@ export class ColorBulb {
|
|
|
379
373
|
})
|
|
380
374
|
.then(async () => {
|
|
381
375
|
// Set an event hander
|
|
382
|
-
switchbot.onadvertisement = async (ad:
|
|
383
|
-
this.address = ad.address;
|
|
376
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
384
377
|
this.debugLog(
|
|
385
378
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
386
|
-
` BLE Address Found: ${
|
|
379
|
+
` BLE Address Found: ${ad.address}`,
|
|
387
380
|
);
|
|
388
381
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
this.
|
|
397
|
-
this.delay = ad.serviceData.delay;
|
|
398
|
-
this.preset = ad.serviceData.preset;
|
|
399
|
-
this.color_mode = ad.serviceData.color_mode;
|
|
400
|
-
this.speed = ad.serviceData.speed;
|
|
401
|
-
this.loop_index = ad.serviceData.loop_index;
|
|
382
|
+
this.BLE_Power = ad.serviceData.power;
|
|
383
|
+
this.BLE_On = ad.serviceData.state;
|
|
384
|
+
this.BLE_Red = ad.serviceData.red;
|
|
385
|
+
this.BLE_Green = ad.serviceData.green;
|
|
386
|
+
this.BLE_Blue = ad.serviceData.blue;
|
|
387
|
+
this.BLE_ColorTemperature = ad.serviceData.color_temperature;
|
|
388
|
+
this.BLE_Brightness = ad.serviceData.brightness;
|
|
389
|
+
this.BLE_Delay = ad.serviceData.delay;
|
|
402
390
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
403
391
|
/*this.debugLog(
|
|
404
392
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -406,13 +394,13 @@ export class ColorBulb {
|
|
|
406
394
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
407
395
|
);*/
|
|
408
396
|
|
|
409
|
-
if (
|
|
410
|
-
this.
|
|
411
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
397
|
+
if (ad.serviceData) {
|
|
398
|
+
this.BLE_IsConnected = true;
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
412
400
|
await this.stopScanning(switchbot);
|
|
413
401
|
} else {
|
|
414
|
-
this.
|
|
415
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
402
|
+
this.BLE_IsConnected = false;
|
|
403
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
416
404
|
}
|
|
417
405
|
};
|
|
418
406
|
// Wait
|
|
@@ -446,10 +434,11 @@ export class ColorBulb {
|
|
|
446
434
|
this.statusCode(statusCode);
|
|
447
435
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
448
436
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
449
|
-
this.
|
|
450
|
-
this.
|
|
451
|
-
this.
|
|
452
|
-
this.
|
|
437
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
438
|
+
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
439
|
+
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
440
|
+
this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
|
|
441
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
453
442
|
this.openAPIparseStatus();
|
|
454
443
|
this.updateHomeKitCharacteristics();
|
|
455
444
|
} catch (e: any) {
|
|
@@ -973,6 +962,16 @@ export class ColorBulb {
|
|
|
973
962
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
974
963
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
975
964
|
}
|
|
965
|
+
// FirmwareRevision
|
|
966
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
967
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
968
|
+
} else {
|
|
969
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
970
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
971
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
972
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
973
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
974
|
+
}
|
|
976
975
|
}
|
|
977
976
|
|
|
978
977
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
@@ -987,7 +986,7 @@ export class ColorBulb {
|
|
|
987
986
|
|
|
988
987
|
async stopScanning(switchbot: any) {
|
|
989
988
|
await switchbot.stopScan();
|
|
990
|
-
if (this.
|
|
989
|
+
if (this.BLE_IsConnected) {
|
|
991
990
|
await this.BLEparseStatus();
|
|
992
991
|
await this.updateHomeKitCharacteristics();
|
|
993
992
|
} else {
|