@switchbot/homebridge-switchbot 2.8.1-beta.0 → 2.8.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +13 -19
- package/dist/device/hub.js.map +1 -1
- package/dist/device/lightstrip.d.ts +7 -8
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +26 -21
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +16 -5
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -13
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +32 -21
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +12 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +32 -21
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +8 -13
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +34 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +4 -10
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +20 -15
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +23 -12
- 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 -3
- package/dist/irdevice/fan.d.ts.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 -1
- package/dist/irdevice/tv.d.ts.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/platform.d.ts.map +1 -1
- package/dist/platform.js +27 -15
- package/dist/platform.js.map +1 -1
- package/package.json +4 -4
- package/src/device/hub.ts +13 -21
- package/src/device/lightstrip.ts +35 -30
- package/src/device/lock.ts +18 -8
- package/src/device/meter.ts +47 -35
- package/src/device/meterplus.ts +46 -34
- package/src/device/motion.ts +45 -33
- package/src/device/plug.ts +23 -25
- package/src/device/robotvacuumcleaner.ts +31 -19
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +3 -3
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +1 -1
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +32 -21
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Homebridge SwitchBot",
|
|
3
3
|
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
-
"version": "2.8.1-beta.
|
|
4
|
+
"version": "2.8.1-beta.10",
|
|
5
5
|
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
|
|
6
6
|
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
7
7
|
"license": "ISC",
|
|
@@ -71,14 +71,14 @@
|
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/crypto-js": "^4.1.1",
|
|
73
73
|
"@types/node": "^20.5.1",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.4.
|
|
75
|
-
"@typescript-eslint/parser": "^6.4.
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
75
|
+
"@typescript-eslint/parser": "^6.4.1",
|
|
76
76
|
"eslint": "^8.47.0",
|
|
77
77
|
"eslint-config-prettier": "9.0.0",
|
|
78
78
|
"eslint-plugin-prettier": "5.0.0",
|
|
79
79
|
"homebridge": "^1.6.1",
|
|
80
80
|
"nodemon": "^3.0.1",
|
|
81
|
-
"npm-check-updates": "^16.12.
|
|
81
|
+
"npm-check-updates": "^16.12.3",
|
|
82
82
|
"prettier": "3.0.2",
|
|
83
83
|
"rimraf": "^5.0.1",
|
|
84
84
|
"ts-node": "^10.9.1",
|
package/src/device/hub.ts
CHANGED
|
@@ -83,21 +83,7 @@ export class Hub {
|
|
|
83
83
|
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.WindowCovering, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
84
84
|
|
|
85
85
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
86
|
-
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method
|
|
87
|
-
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
88
|
-
if (!this.hubTemperatureSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
89
|
-
this.hubTemperatureSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
93
|
-
if (!this.hubHumiditySensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
94
|
-
this.hubHumiditySensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
98
|
-
if (!this.hubLightSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
99
|
-
this.hubLightSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
100
|
-
}
|
|
86
|
+
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method
|
|
101
87
|
|
|
102
88
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
103
89
|
// see https://developers.homebridge.io/#/service/WindowCovering
|
|
@@ -113,8 +99,10 @@ export class Hub {
|
|
|
113
99
|
accessory.getService(this.platform.Service.TemperatureSensor) || accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
114
100
|
`${device.deviceName} ${device.deviceType}`;
|
|
115
101
|
|
|
116
|
-
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name,
|
|
117
|
-
this.hubTemperatureSensor.
|
|
102
|
+
this.hubTemperatureSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
103
|
+
if (!this.hubTemperatureSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
104
|
+
this.hubTemperatureSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
105
|
+
}
|
|
118
106
|
} else {
|
|
119
107
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
120
108
|
}
|
|
@@ -130,8 +118,10 @@ export class Hub {
|
|
|
130
118
|
accessory.getService(this.platform.Service.HumiditySensor) || accessory.addService(this.platform.Service.HumiditySensor)),
|
|
131
119
|
`${device.deviceName} ${device.deviceType}`;
|
|
132
120
|
|
|
133
|
-
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name,
|
|
134
|
-
this.hubHumiditySensor.
|
|
121
|
+
this.hubHumiditySensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
122
|
+
if (!this.hubHumiditySensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
123
|
+
this.hubHumiditySensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
124
|
+
}
|
|
135
125
|
} else {
|
|
136
126
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
137
127
|
}
|
|
@@ -146,8 +136,10 @@ export class Hub {
|
|
|
146
136
|
(this.hubLightSensor = accessory.getService(this.platform.Service.LightSensor) || accessory.addService(this.platform.Service.LightSensor)),
|
|
147
137
|
`${device.deviceName} ${device.deviceType}`;
|
|
148
138
|
|
|
149
|
-
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name,
|
|
150
|
-
this.hubLightSensor.
|
|
139
|
+
this.hubLightSensor.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
140
|
+
if (!this.hubLightSensor.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
141
|
+
this.hubLightSensor.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
142
|
+
}
|
|
151
143
|
} else {
|
|
152
144
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
153
145
|
}
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -24,17 +24,18 @@ export class StripLight {
|
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
ColorTemperature?: CharacteristicValue;
|
|
26
26
|
|
|
27
|
-
// OpenAPI
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// OpenAPI Status
|
|
28
|
+
OpenAPI_On: deviceStatus['power'];
|
|
29
|
+
OpenAPI_RGB: deviceStatus['color'];
|
|
30
|
+
OpenAPI_Brightness: deviceStatus['brightness'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
|
|
33
|
+
// BLE Status
|
|
34
|
+
BLE_On: serviceData['state'];
|
|
35
|
+
BLE_Brightness: serviceData['brightness'];
|
|
32
36
|
|
|
33
37
|
// BLE Others
|
|
34
|
-
|
|
35
|
-
state: serviceData['state'];
|
|
36
|
-
delay: serviceData['delay'];
|
|
37
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
38
|
+
BLE_IsConnected?: boolean;
|
|
38
39
|
|
|
39
40
|
// Config
|
|
40
41
|
set_minStep?: number;
|
|
@@ -234,7 +235,7 @@ export class StripLight {
|
|
|
234
235
|
async BLEparseStatus(): Promise<void> {
|
|
235
236
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
236
237
|
// State
|
|
237
|
-
switch (this.
|
|
238
|
+
switch (this.BLE_On) {
|
|
238
239
|
case 'on':
|
|
239
240
|
this.On = true;
|
|
240
241
|
break;
|
|
@@ -246,7 +247,7 @@ export class StripLight {
|
|
|
246
247
|
|
|
247
248
|
async openAPIparseStatus(): Promise<void> {
|
|
248
249
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
249
|
-
switch (this.
|
|
250
|
+
switch (this.OpenAPI_On) {
|
|
250
251
|
case 'on':
|
|
251
252
|
this.On = true;
|
|
252
253
|
break;
|
|
@@ -256,13 +257,13 @@ export class StripLight {
|
|
|
256
257
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
257
258
|
|
|
258
259
|
// Brightness
|
|
259
|
-
this.Brightness = Number(this.
|
|
260
|
+
this.Brightness = Number(this.OpenAPI_Brightness);
|
|
260
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
261
262
|
|
|
262
263
|
// Color, Hue & Brightness
|
|
263
|
-
if (this.
|
|
264
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
265
|
-
const [red, green, blue] = this.
|
|
264
|
+
if (this.OpenAPI_RGB) {
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
|
|
266
|
+
const [red, green, blue] = this.OpenAPI_RGB!.split(':');
|
|
266
267
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
267
268
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
268
269
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -326,13 +327,6 @@ export class StripLight {
|
|
|
326
327
|
` BLE Address Found: ${ad.address}`,
|
|
327
328
|
);
|
|
328
329
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
329
|
-
//this.state = ad.serviceData.state;
|
|
330
|
-
//this.delay = ad.serviceData.delay;
|
|
331
|
-
//this.timer = ad.serviceData.timer;
|
|
332
|
-
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
333
|
-
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
334
|
-
//this.overload = ad.serviceData.overload;
|
|
335
|
-
//this.currentPower = ad.serviceData.currentPower;
|
|
336
330
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
337
331
|
/*this.debugLog(
|
|
338
332
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -341,12 +335,12 @@ export class StripLight {
|
|
|
341
335
|
);*/
|
|
342
336
|
|
|
343
337
|
if (ad.serviceData) {
|
|
344
|
-
this.
|
|
345
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
338
|
+
this.BLE_IsConnected = true;
|
|
339
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
346
340
|
await this.stopScanning(switchbot);
|
|
347
341
|
} else {
|
|
348
|
-
this.
|
|
349
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
342
|
+
this.BLE_IsConnected = false;
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
350
344
|
}
|
|
351
345
|
};
|
|
352
346
|
// Wait
|
|
@@ -380,9 +374,10 @@ export class StripLight {
|
|
|
380
374
|
this.statusCode(statusCode);
|
|
381
375
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
382
376
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
383
|
-
this.
|
|
384
|
-
this.
|
|
385
|
-
this.
|
|
377
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
378
|
+
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
379
|
+
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
380
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
386
381
|
this.openAPIparseStatus();
|
|
387
382
|
this.updateHomeKitCharacteristics();
|
|
388
383
|
} catch (e: any) {
|
|
@@ -823,11 +818,21 @@ export class StripLight {
|
|
|
823
818
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
824
819
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
825
820
|
}
|
|
821
|
+
// FirmwareRevision
|
|
822
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
823
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
824
|
+
} else {
|
|
825
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
826
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
827
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
828
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
829
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
830
|
+
}
|
|
826
831
|
}
|
|
827
832
|
|
|
828
833
|
async stopScanning(switchbot: any) {
|
|
829
834
|
await switchbot.stopScan();
|
|
830
|
-
if (this.
|
|
835
|
+
if (this.BLE_IsConnected) {
|
|
831
836
|
await this.BLEparseStatus();
|
|
832
837
|
await this.updateHomeKitCharacteristics();
|
|
833
838
|
} else {
|
package/src/device/lock.ts
CHANGED
|
@@ -22,13 +22,13 @@ export class Lock {
|
|
|
22
22
|
ContactSensorState!: CharacteristicValue;
|
|
23
23
|
|
|
24
24
|
// OpenAPI Status
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
26
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
27
27
|
OpenAPI_LockCurrentState!: deviceStatus['lockState'];
|
|
28
28
|
OpenAPI_ContactSensorState!: deviceStatus['doorState'];
|
|
29
29
|
|
|
30
30
|
// BLE Status
|
|
31
|
-
|
|
31
|
+
BLE_BatteryLevel: serviceData['battery'];
|
|
32
32
|
BLE_LockCurrentState: serviceData['state'];
|
|
33
33
|
BLE_Calibration: serviceData['calibration'];
|
|
34
34
|
BLE_ContactSensorState: serviceData['door_open'];
|
|
@@ -200,7 +200,7 @@ export class Lock {
|
|
|
200
200
|
}
|
|
201
201
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
202
202
|
// Battery
|
|
203
|
-
this.BatteryLevel = Number(this.
|
|
203
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
204
204
|
if (this.BatteryLevel < 10) {
|
|
205
205
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
206
206
|
} else {
|
|
@@ -232,7 +232,7 @@ export class Lock {
|
|
|
232
232
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
233
233
|
|
|
234
234
|
// Battery
|
|
235
|
-
this.BatteryLevel = Number(this.
|
|
235
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
236
236
|
if (this.BatteryLevel < 10) {
|
|
237
237
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
238
238
|
} else {
|
|
@@ -287,7 +287,7 @@ export class Lock {
|
|
|
287
287
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
288
288
|
` BLE Address Found: ${ad.address}`,
|
|
289
289
|
);
|
|
290
|
-
this.
|
|
290
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
291
291
|
this.BLE_Calibration = ad.serviceData.calibration;
|
|
292
292
|
this.BLE_LockCurrentState = ad.serviceData.status;
|
|
293
293
|
this.BLE_ContactSensorState = ad.serviceData.door_open;
|
|
@@ -340,8 +340,8 @@ export class Lock {
|
|
|
340
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
341
341
|
this.OpenAPI_LockCurrentState = deviceStatus.body.lockState;
|
|
342
342
|
this.OpenAPI_ContactSensorState = deviceStatus.body.doorState;
|
|
343
|
-
this.
|
|
344
|
-
this.
|
|
343
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
344
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
345
345
|
this.openAPIparseStatus();
|
|
346
346
|
this.updateHomeKitCharacteristics();
|
|
347
347
|
} catch (e: any) {
|
|
@@ -514,6 +514,16 @@ export class Lock {
|
|
|
514
514
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
515
515
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
516
516
|
}
|
|
517
|
+
// FirmwareRevision
|
|
518
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
519
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
520
|
+
} else {
|
|
521
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
522
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
523
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
524
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
525
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
526
|
+
}
|
|
517
527
|
}
|
|
518
528
|
|
|
519
529
|
async stopScanning(switchbot: any) {
|
package/src/device/meter.ts
CHANGED
|
@@ -18,28 +18,30 @@ import { sleep } from '../utils';
|
|
|
18
18
|
export class Meter {
|
|
19
19
|
// Services
|
|
20
20
|
batteryService: Service;
|
|
21
|
-
temperatureservice?: Service;
|
|
22
21
|
humidityservice?: Service;
|
|
22
|
+
temperatureservice?: Service;
|
|
23
23
|
|
|
24
24
|
// Characteristic Values
|
|
25
|
-
CurrentRelativeHumidity!: CharacteristicValue;
|
|
26
|
-
CurrentTemperature?: CharacteristicValue;
|
|
27
25
|
BatteryLevel!: CharacteristicValue;
|
|
28
26
|
StatusLowBattery!: CharacteristicValue;
|
|
27
|
+
CurrentTemperature?: CharacteristicValue;
|
|
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'];
|
|
29
35
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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'];
|
|
35
42
|
|
|
36
43
|
// BLE Others
|
|
37
|
-
|
|
38
|
-
temperature!: serviceData['temperature'];
|
|
39
|
-
celsius!: temperature['c'];
|
|
40
|
-
fahrenheit!: temperature['f'];
|
|
41
|
-
battery!: serviceData['battery'];
|
|
42
|
-
humidity!: serviceData['humidity'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
43
45
|
|
|
44
46
|
//MQTT stuff
|
|
45
47
|
mqttClient: MqttClient | null = null;
|
|
@@ -192,7 +194,7 @@ export class Meter {
|
|
|
192
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
193
195
|
|
|
194
196
|
// Battery
|
|
195
|
-
this.BatteryLevel = Number(this.
|
|
197
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
196
198
|
if (this.BatteryLevel < 15) {
|
|
197
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
198
200
|
} else {
|
|
@@ -202,14 +204,14 @@ export class Meter {
|
|
|
202
204
|
|
|
203
205
|
// Humidity
|
|
204
206
|
if (!this.device.meter?.hide_humidity) {
|
|
205
|
-
this.CurrentRelativeHumidity = this.
|
|
207
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
206
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
// Current Temperature
|
|
210
212
|
if (!this.device.meter?.hide_temperature) {
|
|
211
|
-
this.
|
|
212
|
-
this.CurrentTemperature = this.
|
|
213
|
+
this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
|
|
214
|
+
this.CurrentTemperature = this.BLE_Celsius;
|
|
213
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
214
216
|
}
|
|
215
217
|
}
|
|
@@ -218,7 +220,7 @@ export class Meter {
|
|
|
218
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
219
221
|
|
|
220
222
|
// Battery
|
|
221
|
-
this.BatteryLevel = Number(this.
|
|
223
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
222
224
|
if (this.BatteryLevel < 15) {
|
|
223
225
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
224
226
|
} else {
|
|
@@ -228,13 +230,13 @@ export class Meter {
|
|
|
228
230
|
|
|
229
231
|
// Current Relative Humidity
|
|
230
232
|
if (!this.device.meter?.hide_humidity) {
|
|
231
|
-
this.CurrentRelativeHumidity = this.
|
|
233
|
+
this.CurrentRelativeHumidity = this.OpenAPI_CurrentRelativeHumidity!;
|
|
232
234
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
// Current Temperature
|
|
236
238
|
if (!this.device.meter?.hide_temperature) {
|
|
237
|
-
this.CurrentTemperature = this.
|
|
239
|
+
this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
|
|
238
240
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
@@ -284,12 +286,12 @@ export class Meter {
|
|
|
284
286
|
);
|
|
285
287
|
if (ad.serviceData.humidity! > 0) {
|
|
286
288
|
// reject unreliable data
|
|
287
|
-
this.
|
|
289
|
+
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
288
290
|
}
|
|
289
|
-
this.
|
|
290
|
-
this.
|
|
291
|
-
this.
|
|
292
|
-
this.
|
|
291
|
+
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
292
|
+
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
293
|
+
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
294
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
293
295
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
294
296
|
this.debugLog(
|
|
295
297
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -298,12 +300,12 @@ export class Meter {
|
|
|
298
300
|
);
|
|
299
301
|
|
|
300
302
|
if (ad.serviceData) {
|
|
301
|
-
this.
|
|
302
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
303
|
+
this.BLE_IsConnected = true;
|
|
304
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
303
305
|
await this.stopScanning(switchbot);
|
|
304
306
|
} else {
|
|
305
|
-
this.
|
|
306
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
307
|
+
this.BLE_IsConnected = false;
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
307
309
|
}
|
|
308
310
|
};
|
|
309
311
|
// Wait
|
|
@@ -337,10 +339,10 @@ export class Meter {
|
|
|
337
339
|
this.statusCode(statusCode);
|
|
338
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
339
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
342
|
-
this.
|
|
343
|
-
this.
|
|
342
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity!;
|
|
343
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
|
|
344
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
345
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
344
346
|
this.openAPIparseStatus();
|
|
345
347
|
this.updateHomeKitCharacteristics();
|
|
346
348
|
} catch (e: any) {
|
|
@@ -422,6 +424,16 @@ export class Meter {
|
|
|
422
424
|
this.historyService?.addEntry(entry);
|
|
423
425
|
}
|
|
424
426
|
}
|
|
427
|
+
// FirmwareRevision
|
|
428
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
430
|
+
} else {
|
|
431
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
432
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
433
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
434
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
435
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
436
|
+
}
|
|
425
437
|
}
|
|
426
438
|
|
|
427
439
|
/*
|
|
@@ -475,7 +487,7 @@ export class Meter {
|
|
|
475
487
|
|
|
476
488
|
async stopScanning(switchbot: any) {
|
|
477
489
|
await switchbot.stopScan();
|
|
478
|
-
if (this.
|
|
490
|
+
if (this.BLE_IsConnected) {
|
|
479
491
|
await this.BLEparseStatus();
|
|
480
492
|
await this.updateHomeKitCharacteristics();
|
|
481
493
|
} else {
|
package/src/device/meterplus.ts
CHANGED
|
@@ -22,24 +22,26 @@ export class MeterPlus {
|
|
|
22
22
|
temperatureservice?: Service;
|
|
23
23
|
|
|
24
24
|
// Characteristic Values
|
|
25
|
-
CurrentRelativeHumidity!: CharacteristicValue;
|
|
26
|
-
CurrentTemperature?: CharacteristicValue;
|
|
27
25
|
BatteryLevel!: CharacteristicValue;
|
|
28
26
|
StatusLowBattery!: CharacteristicValue;
|
|
27
|
+
CurrentTemperature?: CharacteristicValue;
|
|
28
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
29
29
|
|
|
30
|
-
// OpenAPI
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// OpenAPI Status
|
|
31
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
32
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
33
|
+
OpenAPI_CurrentTemperature: deviceStatus['temperature'];
|
|
34
|
+
OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
|
|
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'];
|
|
35
42
|
|
|
36
43
|
// BLE Others
|
|
37
|
-
|
|
38
|
-
temperature!: serviceData['temperature'];
|
|
39
|
-
celsius!: temperature['c'];
|
|
40
|
-
fahrenheit!: temperature['f'];
|
|
41
|
-
battery!: serviceData['battery'];
|
|
42
|
-
humidity!: serviceData['humidity'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
43
45
|
|
|
44
46
|
//MQTT stuff
|
|
45
47
|
mqttClient: MqttClient | null = null;
|
|
@@ -192,7 +194,7 @@ export class MeterPlus {
|
|
|
192
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
193
195
|
|
|
194
196
|
// Battery
|
|
195
|
-
this.BatteryLevel = Number(this.
|
|
197
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
196
198
|
if (this.BatteryLevel < 15) {
|
|
197
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
198
200
|
} else {
|
|
@@ -202,14 +204,14 @@ export class MeterPlus {
|
|
|
202
204
|
|
|
203
205
|
// Humidity
|
|
204
206
|
if (!this.device.meter?.hide_humidity) {
|
|
205
|
-
this.CurrentRelativeHumidity = this.
|
|
207
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
206
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
// Current Temperature
|
|
210
212
|
if (!this.device.meter?.hide_temperature) {
|
|
211
|
-
this.
|
|
212
|
-
this.CurrentTemperature = this.
|
|
213
|
+
this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
|
|
214
|
+
this.CurrentTemperature = this.BLE_Celsius;
|
|
213
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
214
216
|
}
|
|
215
217
|
}
|
|
@@ -218,7 +220,7 @@ export class MeterPlus {
|
|
|
218
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
219
221
|
|
|
220
222
|
// Battery
|
|
221
|
-
this.BatteryLevel = Number(this.
|
|
223
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
222
224
|
if (this.BatteryLevel < 15) {
|
|
223
225
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
224
226
|
} else {
|
|
@@ -228,13 +230,13 @@ export class MeterPlus {
|
|
|
228
230
|
|
|
229
231
|
// Current Relative Humidity
|
|
230
232
|
if (!this.device.meter?.hide_humidity) {
|
|
231
|
-
this.CurrentRelativeHumidity = this.
|
|
233
|
+
this.CurrentRelativeHumidity = this.OpenAPI_CurrentRelativeHumidity!;
|
|
232
234
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
// Current Temperature
|
|
236
238
|
if (!this.device.meter?.hide_temperature) {
|
|
237
|
-
this.CurrentTemperature = this.
|
|
239
|
+
this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
|
|
238
240
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
@@ -284,12 +286,12 @@ export class MeterPlus {
|
|
|
284
286
|
);
|
|
285
287
|
if (ad.serviceData.humidity! > 0) {
|
|
286
288
|
// reject unreliable data
|
|
287
|
-
this.
|
|
289
|
+
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
288
290
|
}
|
|
289
|
-
this.
|
|
290
|
-
this.
|
|
291
|
-
this.
|
|
292
|
-
this.
|
|
291
|
+
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
292
|
+
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
293
|
+
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
294
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
293
295
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
294
296
|
this.debugLog(
|
|
295
297
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -298,12 +300,12 @@ export class MeterPlus {
|
|
|
298
300
|
);
|
|
299
301
|
|
|
300
302
|
if (ad.serviceData) {
|
|
301
|
-
this.
|
|
302
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
303
|
+
this.BLE_IsConnected = true;
|
|
304
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
303
305
|
await this.stopScanning(switchbot);
|
|
304
306
|
} else {
|
|
305
|
-
this.
|
|
306
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
307
|
+
this.BLE_IsConnected = false;
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
307
309
|
}
|
|
308
310
|
};
|
|
309
311
|
// Wait
|
|
@@ -337,10 +339,10 @@ export class MeterPlus {
|
|
|
337
339
|
this.statusCode(statusCode);
|
|
338
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
339
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
342
|
-
this.
|
|
343
|
-
this.
|
|
342
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity!;
|
|
343
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
|
|
344
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
345
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
344
346
|
this.openAPIparseStatus();
|
|
345
347
|
this.updateHomeKitCharacteristics();
|
|
346
348
|
} catch (e: any) {
|
|
@@ -422,6 +424,16 @@ export class MeterPlus {
|
|
|
422
424
|
this.historyService?.addEntry(entry);
|
|
423
425
|
}
|
|
424
426
|
}
|
|
427
|
+
// FirmwareRevision
|
|
428
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
430
|
+
} else {
|
|
431
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
432
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
433
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
434
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
435
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
436
|
+
}
|
|
425
437
|
}
|
|
426
438
|
|
|
427
439
|
/*
|
|
@@ -475,7 +487,7 @@ export class MeterPlus {
|
|
|
475
487
|
|
|
476
488
|
async stopScanning(switchbot: any) {
|
|
477
489
|
await switchbot.stopScan();
|
|
478
|
-
if (this.
|
|
490
|
+
if (this.BLE_IsConnected) {
|
|
479
491
|
await this.BLEparseStatus();
|
|
480
492
|
await this.updateHomeKitCharacteristics();
|
|
481
493
|
} else {
|