@switchbot/homebridge-switchbot 2.8.0-beta.9 → 2.8.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -2
- package/README.md +1 -1
- package/dist/device/blindtilt.d.ts +21 -22
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +78 -77
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -13
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +93 -75
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +40 -27
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -23
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +55 -46
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -22
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +82 -73
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -24
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +76 -77
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +10 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +50 -35
- 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 +34 -21
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -20
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +42 -29
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +2 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +9 -8
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -19
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +71 -28
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -9
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +16 -20
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -10
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +16 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +49 -47
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +9 -8
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -8
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +20 -4
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -86
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +0 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +0 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +64 -63
- package/dist/platform.js.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 +12 -12
- package/src/device/blindtilt.ts +103 -100
- package/src/device/bot.ts +105 -89
- package/src/device/ceilinglight.ts +56 -46
- package/src/device/colorbulb.ts +78 -76
- package/src/device/contact.ts +100 -94
- package/src/device/curtain.ts +101 -101
- package/src/device/hub.ts +61 -43
- package/src/device/humidifier.ts +42 -33
- package/src/device/iosensor.ts +59 -50
- package/src/device/lightstrip.ts +14 -17
- package/src/device/lock.ts +91 -50
- package/src/device/meter.ts +22 -30
- package/src/device/meterplus.ts +23 -32
- package/src/device/motion.ts +55 -53
- package/src/device/plug.ts +12 -15
- package/src/device/robotvacuumcleaner.ts +33 -16
- package/src/irdevice/airconditioner.ts +80 -94
- package/src/irdevice/airpurifier.ts +1 -1
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +1 -4
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +73 -73
- package/src/settings.ts +6 -2
package/src/device/humidifier.ts
CHANGED
|
@@ -28,18 +28,16 @@ export class Humidifier {
|
|
|
28
28
|
WaterLevel!: CharacteristicValue;
|
|
29
29
|
|
|
30
30
|
// OpenAPI
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
deviceStatus
|
|
31
|
+
OpenAPI_Active: deviceStatus['power'];
|
|
32
|
+
OpenAPI_WaterLevel: deviceStatus['lackWater'];
|
|
33
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
34
|
+
OpenAPI_CurrentTemperature: deviceStatus['temperature'];
|
|
35
|
+
OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
|
|
36
|
+
OpenAPI_CurrentHumidifierDehumidifierState: deviceStatus['auto'];
|
|
37
|
+
OpenAPI_RelativeHumidityHumidifierThreshold: deviceStatus['nebulizationEfficiency'];
|
|
38
38
|
|
|
39
39
|
// BLE Others
|
|
40
40
|
connected?: boolean;
|
|
41
|
-
serviceData!: serviceData;
|
|
42
|
-
address!: ad['address'];
|
|
43
41
|
onState!: serviceData['onState'];
|
|
44
42
|
autoMode!: serviceData['autoMode'];
|
|
45
43
|
percentage!: serviceData['percentage'];
|
|
@@ -233,15 +231,15 @@ export class Humidifier {
|
|
|
233
231
|
async openAPIparseStatus(): Promise<void> {
|
|
234
232
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
235
233
|
// Current Relative Humidity
|
|
236
|
-
this.CurrentRelativeHumidity = this.
|
|
234
|
+
this.CurrentRelativeHumidity = this.OpenAPI_CurrentTemperature!;
|
|
237
235
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
238
236
|
// Current Temperature
|
|
239
237
|
if (!this.device.humidifier?.hide_temperature) {
|
|
240
|
-
this.CurrentTemperature = this.
|
|
238
|
+
this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
|
|
241
239
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
242
240
|
}
|
|
243
241
|
// Target Humidifier Dehumidifier State
|
|
244
|
-
switch (this.
|
|
242
|
+
switch (this.OpenAPI_CurrentHumidifierDehumidifierState) {
|
|
245
243
|
case true:
|
|
246
244
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
247
245
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
@@ -249,10 +247,10 @@ export class Humidifier {
|
|
|
249
247
|
break;
|
|
250
248
|
default:
|
|
251
249
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
252
|
-
if (this.
|
|
250
|
+
if (this.OpenAPI_RelativeHumidityHumidifierThreshold! > 100) {
|
|
253
251
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
254
252
|
} else {
|
|
255
|
-
this.RelativeHumidityHumidifierThreshold = this.
|
|
253
|
+
this.RelativeHumidityHumidifierThreshold = this.OpenAPI_RelativeHumidityHumidifierThreshold!;
|
|
256
254
|
}
|
|
257
255
|
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
258
256
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
@@ -273,7 +271,7 @@ export class Humidifier {
|
|
|
273
271
|
`${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
274
272
|
);
|
|
275
273
|
// Active
|
|
276
|
-
switch (this.
|
|
274
|
+
switch (this.OpenAPI_Active) {
|
|
277
275
|
case 'on':
|
|
278
276
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
279
277
|
break;
|
|
@@ -282,7 +280,7 @@ export class Humidifier {
|
|
|
282
280
|
}
|
|
283
281
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
284
282
|
// Water Level
|
|
285
|
-
if (this.
|
|
283
|
+
if (this.OpenAPI_WaterLevel) {
|
|
286
284
|
this.WaterLevel = 0;
|
|
287
285
|
} else {
|
|
288
286
|
this.WaterLevel = 100;
|
|
@@ -329,12 +327,10 @@ export class Humidifier {
|
|
|
329
327
|
.then(async () => {
|
|
330
328
|
// Set an event hander
|
|
331
329
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
332
|
-
this.address = ad.address;
|
|
333
330
|
this.debugLog(
|
|
334
331
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
335
|
-
` BLE Address Found: ${
|
|
332
|
+
` BLE Address Found: ${ad.address}`,
|
|
336
333
|
);
|
|
337
|
-
this.serviceData = ad.serviceData;
|
|
338
334
|
this.autoMode = ad.serviceData.autoMode;
|
|
339
335
|
this.onState = ad.serviceData.onState;
|
|
340
336
|
this.percentage = ad.serviceData.percentage;
|
|
@@ -344,7 +340,7 @@ export class Humidifier {
|
|
|
344
340
|
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
345
341
|
);
|
|
346
342
|
|
|
347
|
-
if (
|
|
343
|
+
if (ad.serviceData) {
|
|
348
344
|
this.connected = true;
|
|
349
345
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
350
346
|
await this.stopScanning(switchbot);
|
|
@@ -379,17 +375,18 @@ export class Humidifier {
|
|
|
379
375
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
380
376
|
headers: this.platform.generateHeaders(),
|
|
381
377
|
});
|
|
382
|
-
const deviceStatus = await body.json();
|
|
378
|
+
const deviceStatus: any = await body.json();
|
|
383
379
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
384
380
|
this.statusCode(statusCode);
|
|
385
381
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
386
382
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
387
|
-
this.
|
|
388
|
-
this.
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
383
|
+
this.OpenAPI_CurrentHumidifierDehumidifierState = deviceStatus.body.auto;
|
|
384
|
+
this.OpenAPI_Active = deviceStatus.body.power;
|
|
385
|
+
this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
|
|
386
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
387
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
388
|
+
this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
389
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
393
390
|
this.openAPIparseStatus();
|
|
394
391
|
this.updateHomeKitCharacteristics();
|
|
395
392
|
} catch (e: any) {
|
|
@@ -475,7 +472,7 @@ export class Humidifier {
|
|
|
475
472
|
method: 'POST',
|
|
476
473
|
headers: this.platform.generateHeaders(),
|
|
477
474
|
});
|
|
478
|
-
const deviceStatus = await body.json();
|
|
475
|
+
const deviceStatus: any = await body.json();
|
|
479
476
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
480
477
|
this.statusCode(statusCode);
|
|
481
478
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -518,7 +515,7 @@ export class Humidifier {
|
|
|
518
515
|
method: 'POST',
|
|
519
516
|
headers: this.platform.generateHeaders(),
|
|
520
517
|
});
|
|
521
|
-
const deviceStatus = await body.json();
|
|
518
|
+
const deviceStatus: any = await body.json();
|
|
522
519
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
523
520
|
this.statusCode(statusCode);
|
|
524
521
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -556,7 +553,7 @@ export class Humidifier {
|
|
|
556
553
|
method: 'POST',
|
|
557
554
|
headers: this.platform.generateHeaders(),
|
|
558
555
|
});
|
|
559
|
-
const deviceStatus = await body.json();
|
|
556
|
+
const deviceStatus: any = await body.json();
|
|
560
557
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
561
558
|
this.statusCode(statusCode);
|
|
562
559
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -703,6 +700,16 @@ export class Humidifier {
|
|
|
703
700
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
704
701
|
}
|
|
705
702
|
}
|
|
703
|
+
// FirmwareRevision
|
|
704
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
705
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
706
|
+
} else {
|
|
707
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
708
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
709
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
710
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
711
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
712
|
+
}
|
|
706
713
|
}
|
|
707
714
|
|
|
708
715
|
async stopScanning(switchbot: any) {
|
|
@@ -845,10 +852,12 @@ export class Humidifier {
|
|
|
845
852
|
);
|
|
846
853
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
847
854
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
848
|
-
if (
|
|
849
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
850
|
-
} else if (device.firmware) {
|
|
855
|
+
if (device.firmware) {
|
|
851
856
|
FirmwareRevision = device.firmware;
|
|
857
|
+
} else if (device.version) {
|
|
858
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
859
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
860
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
852
861
|
} else {
|
|
853
862
|
FirmwareRevision = this.platform.version;
|
|
854
863
|
}
|
package/src/device/iosensor.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
8
8
|
import { skipWhile } from 'rxjs/operators';
|
|
9
9
|
import { SwitchBotPlatform } from '../platform';
|
|
10
10
|
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
11
|
-
import { device, devicesConfig, serviceData, ad,
|
|
11
|
+
import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devices } from '../settings';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Platform Accessory
|
|
@@ -17,33 +17,31 @@ import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceS
|
|
|
17
17
|
*/
|
|
18
18
|
export class IOSensor {
|
|
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
|
+
// 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'];
|
|
36
42
|
|
|
37
43
|
// BLE Others
|
|
38
|
-
|
|
39
|
-
switchbot!: switchbot;
|
|
40
|
-
serviceData!: serviceData;
|
|
41
|
-
address!: ad['address'];
|
|
42
|
-
temperature!: serviceData['temperature'];
|
|
43
|
-
celsius!: temperature['c'];
|
|
44
|
-
fahrenheit!: temperature['f'];
|
|
45
|
-
battery!: serviceData['battery'];
|
|
46
|
-
humidity!: serviceData['humidity'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
47
45
|
|
|
48
46
|
//MQTT stuff
|
|
49
47
|
mqttClient: MqttClient | null = null;
|
|
@@ -154,7 +152,7 @@ export class IOSensor {
|
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
// Battery Service
|
|
157
|
-
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) ||
|
|
155
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
158
156
|
`${accessory.displayName} Battery`;
|
|
159
157
|
|
|
160
158
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
@@ -196,7 +194,7 @@ export class IOSensor {
|
|
|
196
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
197
195
|
|
|
198
196
|
// Battery
|
|
199
|
-
this.BatteryLevel = Number(this.
|
|
197
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
200
198
|
if (this.BatteryLevel < 15) {
|
|
201
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
202
200
|
} else {
|
|
@@ -206,14 +204,14 @@ export class IOSensor {
|
|
|
206
204
|
|
|
207
205
|
// Humidity
|
|
208
206
|
if (!this.device.meter?.hide_humidity) {
|
|
209
|
-
this.CurrentRelativeHumidity = this.
|
|
207
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
210
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
// Current Temperature
|
|
214
212
|
if (!this.device.meter?.hide_temperature) {
|
|
215
|
-
this.
|
|
216
|
-
this.CurrentTemperature = this.
|
|
213
|
+
this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
|
|
214
|
+
this.CurrentTemperature = this.BLE_Celsius;
|
|
217
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
218
216
|
}
|
|
219
217
|
}
|
|
@@ -221,7 +219,7 @@ export class IOSensor {
|
|
|
221
219
|
async openAPIparseStatus(): Promise<void> {
|
|
222
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
223
221
|
// Battery
|
|
224
|
-
this.BatteryLevel = Number(this.
|
|
222
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
225
223
|
if (this.BatteryLevel < 15) {
|
|
226
224
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
227
225
|
} else {
|
|
@@ -231,13 +229,13 @@ export class IOSensor {
|
|
|
231
229
|
|
|
232
230
|
// Current Relative Humidity
|
|
233
231
|
if (!this.device.meter?.hide_humidity) {
|
|
234
|
-
this.CurrentRelativeHumidity = this.
|
|
232
|
+
this.CurrentRelativeHumidity = this.OpenAPI_CurrentRelativeHumidity!;
|
|
235
233
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
// Current Temperature
|
|
239
237
|
if (!this.device.meter?.hide_temperature) {
|
|
240
|
-
this.CurrentTemperature = this.
|
|
238
|
+
this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
|
|
241
239
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
242
240
|
}
|
|
243
241
|
}
|
|
@@ -281,20 +279,18 @@ export class IOSensor {
|
|
|
281
279
|
.then(async () => {
|
|
282
280
|
// Set an event hander
|
|
283
281
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
284
|
-
this.address = ad.address;
|
|
285
282
|
this.debugLog(
|
|
286
283
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
287
|
-
` BLE Address Found: ${
|
|
284
|
+
` BLE Address Found: ${ad.address}`,
|
|
288
285
|
);
|
|
289
286
|
if (ad.serviceData.humidity! > 0) {
|
|
290
287
|
// reject unreliable data
|
|
291
|
-
this.
|
|
288
|
+
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
292
289
|
}
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
295
|
-
this.
|
|
296
|
-
this.
|
|
297
|
-
this.battery = ad.serviceData.battery;
|
|
290
|
+
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
291
|
+
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
292
|
+
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
293
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
298
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
299
295
|
this.debugLog(
|
|
300
296
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -302,13 +298,13 @@ export class IOSensor {
|
|
|
302
298
|
`battery: ${ad.serviceData.battery}`,
|
|
303
299
|
);
|
|
304
300
|
|
|
305
|
-
if (
|
|
306
|
-
this.
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
301
|
+
if (ad.serviceData) {
|
|
302
|
+
this.BLE_IsConnected = true;
|
|
303
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
308
304
|
await this.stopScanning(switchbot);
|
|
309
305
|
} else {
|
|
310
|
-
this.
|
|
311
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
306
|
+
this.BLE_IsConnected = false;
|
|
307
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
312
308
|
}
|
|
313
309
|
};
|
|
314
310
|
// Wait
|
|
@@ -337,14 +333,15 @@ export class IOSensor {
|
|
|
337
333
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
338
334
|
headers: this.platform.generateHeaders(),
|
|
339
335
|
});
|
|
340
|
-
const deviceStatus = await body.json();
|
|
336
|
+
const deviceStatus: any = await body.json();
|
|
341
337
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
342
338
|
this.statusCode(statusCode);
|
|
343
339
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
344
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
345
|
-
this.
|
|
346
|
-
this.
|
|
347
|
-
this.
|
|
341
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity!;
|
|
342
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
|
|
343
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
344
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
348
345
|
this.openAPIparseStatus();
|
|
349
346
|
this.updateHomeKitCharacteristics();
|
|
350
347
|
} catch (e: any) {
|
|
@@ -424,6 +421,16 @@ export class IOSensor {
|
|
|
424
421
|
this.historyService?.addEntry(entry);
|
|
425
422
|
}
|
|
426
423
|
}
|
|
424
|
+
// FirmwareRevision
|
|
425
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
426
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
427
|
+
} else {
|
|
428
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
429
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
430
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
431
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
432
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
433
|
+
}
|
|
427
434
|
}
|
|
428
435
|
|
|
429
436
|
/*
|
|
@@ -477,7 +484,7 @@ export class IOSensor {
|
|
|
477
484
|
|
|
478
485
|
async stopScanning(switchbot: any) {
|
|
479
486
|
await switchbot.stopScan();
|
|
480
|
-
if (this.
|
|
487
|
+
if (this.BLE_IsConnected) {
|
|
481
488
|
await this.BLEparseStatus();
|
|
482
489
|
await this.updateHomeKitCharacteristics();
|
|
483
490
|
} else {
|
|
@@ -592,10 +599,12 @@ export class IOSensor {
|
|
|
592
599
|
);
|
|
593
600
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
594
601
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
595
|
-
if (
|
|
596
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
597
|
-
} else if (device.firmware) {
|
|
602
|
+
if (device.firmware) {
|
|
598
603
|
FirmwareRevision = device.firmware;
|
|
604
|
+
} else if (device.version) {
|
|
605
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
606
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
607
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
599
608
|
} else {
|
|
600
609
|
FirmwareRevision = this.platform.version;
|
|
601
610
|
}
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
8
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
9
|
-
import { device, devicesConfig,
|
|
9
|
+
import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m2hs, Devices } from '../settings';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Platform Accessory
|
|
@@ -25,16 +25,13 @@ export class StripLight {
|
|
|
25
25
|
ColorTemperature?: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI Others
|
|
28
|
+
Version: deviceStatus['version'];
|
|
28
29
|
power: deviceStatus['power'];
|
|
29
30
|
color: deviceStatus['color'];
|
|
30
31
|
brightness: deviceStatus['brightness'];
|
|
31
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
32
32
|
|
|
33
33
|
// BLE Others
|
|
34
34
|
connected?: boolean;
|
|
35
|
-
switchbot!: switchbot;
|
|
36
|
-
address!: ad['address'];
|
|
37
|
-
serviceData!: serviceData;
|
|
38
35
|
state: serviceData['state'];
|
|
39
36
|
delay: serviceData['delay'];
|
|
40
37
|
wifiRssi: serviceData['wifiRssi'];
|
|
@@ -323,14 +320,12 @@ export class StripLight {
|
|
|
323
320
|
})
|
|
324
321
|
.then(async () => {
|
|
325
322
|
// Set an event hander
|
|
326
|
-
switchbot.onadvertisement = async (ad:
|
|
327
|
-
this.address = ad.address;
|
|
323
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
328
324
|
this.debugLog(
|
|
329
325
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
330
|
-
` BLE Address Found: ${
|
|
326
|
+
` BLE Address Found: ${ad.address}`,
|
|
331
327
|
);
|
|
332
328
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
333
|
-
this.serviceData = ad.serviceData;
|
|
334
329
|
//this.state = ad.serviceData.state;
|
|
335
330
|
//this.delay = ad.serviceData.delay;
|
|
336
331
|
//this.timer = ad.serviceData.timer;
|
|
@@ -345,7 +340,7 @@ export class StripLight {
|
|
|
345
340
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
346
341
|
);*/
|
|
347
342
|
|
|
348
|
-
if (
|
|
343
|
+
if (ad.serviceData) {
|
|
349
344
|
this.connected = true;
|
|
350
345
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
351
346
|
await this.stopScanning(switchbot);
|
|
@@ -380,7 +375,7 @@ export class StripLight {
|
|
|
380
375
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
381
376
|
headers: this.platform.generateHeaders(),
|
|
382
377
|
});
|
|
383
|
-
const deviceStatus = await body.json();
|
|
378
|
+
const deviceStatus: any = await body.json();
|
|
384
379
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
385
380
|
this.statusCode(statusCode);
|
|
386
381
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -593,7 +588,7 @@ export class StripLight {
|
|
|
593
588
|
method: 'POST',
|
|
594
589
|
headers: this.platform.generateHeaders(),
|
|
595
590
|
});
|
|
596
|
-
const deviceStatus = await body.json();
|
|
591
|
+
const deviceStatus: any = await body.json();
|
|
597
592
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
598
593
|
this.statusCode(statusCode);
|
|
599
594
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -641,7 +636,7 @@ export class StripLight {
|
|
|
641
636
|
method: 'POST',
|
|
642
637
|
headers: this.platform.generateHeaders(),
|
|
643
638
|
});
|
|
644
|
-
const deviceStatus = await body.json();
|
|
639
|
+
const deviceStatus: any = await body.json();
|
|
645
640
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
646
641
|
this.statusCode(statusCode);
|
|
647
642
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -675,7 +670,7 @@ export class StripLight {
|
|
|
675
670
|
method: 'POST',
|
|
676
671
|
headers: this.platform.generateHeaders(),
|
|
677
672
|
});
|
|
678
|
-
const deviceStatus = await body.json();
|
|
673
|
+
const deviceStatus: any = await body.json();
|
|
679
674
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
680
675
|
this.statusCode(statusCode);
|
|
681
676
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -990,10 +985,12 @@ export class StripLight {
|
|
|
990
985
|
);
|
|
991
986
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
992
987
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
993
|
-
if (
|
|
994
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
995
|
-
} else if (device.firmware) {
|
|
988
|
+
if (device.firmware) {
|
|
996
989
|
FirmwareRevision = device.firmware;
|
|
990
|
+
} else if (device.version) {
|
|
991
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
992
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
993
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
997
994
|
} else {
|
|
998
995
|
FirmwareRevision = this.platform.version;
|
|
999
996
|
}
|