@switchbot/homebridge-switchbot 2.8.0 → 2.8.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script.js +81 -0
- package/dist/device/blindtilt.d.ts +21 -23
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +71 -73
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -15
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +38 -34
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -14
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +33 -23
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -24
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +49 -43
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -24
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +49 -51
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -26
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +49 -47
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +42 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -10
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +27 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -21
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +8 -13
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +28 -25
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -21
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +75 -26
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +16 -21
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +40 -37
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +16 -21
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +40 -37
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -21
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +44 -46
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +5 -15
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +22 -19
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -13
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +30 -28
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +4 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/fan.d.ts +3 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/other.d.ts +2 -2
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/device/blindtilt.ts +96 -95
- package/src/device/bot.ts +54 -54
- package/src/device/ceilinglight.ts +46 -39
- package/src/device/colorbulb.ts +68 -69
- package/src/device/contact.ts +69 -77
- package/src/device/curtain.ts +75 -74
- package/src/device/hub.ts +53 -38
- package/src/device/humidifier.ts +33 -26
- package/src/device/iosensor.ts +53 -48
- package/src/device/lightstrip.ts +39 -40
- package/src/device/lock.ts +94 -49
- package/src/device/meter.ts +59 -59
- package/src/device/meterplus.ts +59 -60
- package/src/device/motion.ts +61 -65
- package/src/device/plug.ts +27 -35
- package/src/device/robotvacuumcleaner.ts +43 -43
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +3 -6
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/settings.ts +5 -1
package/src/device/hub.ts
CHANGED
|
@@ -8,19 +8,22 @@ import { sleep } from '../utils';
|
|
|
8
8
|
|
|
9
9
|
export class Hub {
|
|
10
10
|
// Services
|
|
11
|
-
hubTemperatureSensor: Service;
|
|
12
|
-
hubHumiditySensor: Service;
|
|
13
11
|
hubLightSensor: Service;
|
|
12
|
+
hubHumiditySensor: Service;
|
|
13
|
+
hubTemperatureSensor: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
CurrentAmbientLightLevel!:
|
|
16
|
+
CurrentTemperature!: CharacteristicValue;
|
|
17
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
18
|
+
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
19
|
+
|
|
20
|
+
// OpenAPI Status
|
|
21
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
22
|
+
OpenAPI_CurrentTemperature: deviceStatus['temperature'];
|
|
23
|
+
OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
|
|
24
|
+
OpenAPI_CurrentAmbientLightLevel!: deviceStatus['brightness'];
|
|
19
25
|
|
|
20
26
|
// OpenAPI Others
|
|
21
|
-
Version: deviceStatus['version'];
|
|
22
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
23
|
-
lightLevel!: number;
|
|
24
27
|
spaceBetweenLevels!: number;
|
|
25
28
|
|
|
26
29
|
// Config
|
|
@@ -174,10 +177,11 @@ export class Hub {
|
|
|
174
177
|
|
|
175
178
|
async openAPIparseStatus(): Promise<void> {
|
|
176
179
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
// Temperature
|
|
181
|
+
this.CurrentTemperature = Number(this.OpenAPI_CurrentTemperature);
|
|
182
|
+
|
|
183
|
+
// Humidity
|
|
184
|
+
this.CurrentRelativeHumidity = Number(this.OpenAPI_CurrentRelativeHumidity);
|
|
181
185
|
|
|
182
186
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
183
187
|
this.set_minLux = this.minLux();
|
|
@@ -185,85 +189,85 @@ export class Hub {
|
|
|
185
189
|
this.spaceBetweenLevels = 19;
|
|
186
190
|
|
|
187
191
|
// Brightness
|
|
188
|
-
switch (this.
|
|
192
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
189
193
|
case 1:
|
|
190
194
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
191
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
192
196
|
break;
|
|
193
197
|
case 2:
|
|
194
198
|
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
195
199
|
this.debugLog(
|
|
196
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
200
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
197
201
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
198
202
|
);
|
|
199
203
|
break;
|
|
200
204
|
case 3:
|
|
201
205
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
202
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
206
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
203
207
|
break;
|
|
204
208
|
case 4:
|
|
205
209
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
206
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
207
211
|
break;
|
|
208
212
|
case 5:
|
|
209
213
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
210
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
211
215
|
break;
|
|
212
216
|
case 6:
|
|
213
217
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
214
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
215
219
|
break;
|
|
216
220
|
case 7:
|
|
217
221
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
218
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
219
223
|
break;
|
|
220
224
|
case 8:
|
|
221
225
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
222
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
223
227
|
break;
|
|
224
228
|
case 9:
|
|
225
229
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
226
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
227
231
|
break;
|
|
228
232
|
case 10:
|
|
229
233
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 9;
|
|
230
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
234
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
231
235
|
break;
|
|
232
236
|
case 11:
|
|
233
237
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 10;
|
|
234
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
235
239
|
break;
|
|
236
240
|
case 12:
|
|
237
241
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 11;
|
|
238
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
242
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
239
243
|
break;
|
|
240
244
|
case 13:
|
|
241
245
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 12;
|
|
242
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
243
247
|
break;
|
|
244
248
|
case 14:
|
|
245
249
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 13;
|
|
246
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
247
251
|
break;
|
|
248
252
|
case 15:
|
|
249
253
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 14;
|
|
250
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
251
255
|
break;
|
|
252
256
|
case 16:
|
|
253
257
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 15;
|
|
254
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
255
259
|
break;
|
|
256
260
|
case 17:
|
|
257
261
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 16;
|
|
258
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
259
263
|
break;
|
|
260
264
|
case 18:
|
|
261
265
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 17;
|
|
262
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
266
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
263
267
|
break;
|
|
264
268
|
case 19:
|
|
265
269
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 18;
|
|
266
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
270
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel}`);
|
|
267
271
|
break;
|
|
268
272
|
case 20:
|
|
269
273
|
default:
|
|
@@ -271,7 +275,7 @@ export class Hub {
|
|
|
271
275
|
this.debugLog();
|
|
272
276
|
}
|
|
273
277
|
this.debugLog(
|
|
274
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
278
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.OpenAPI_CurrentAmbientLightLevel},` +
|
|
275
279
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
276
280
|
);
|
|
277
281
|
}
|
|
@@ -299,9 +303,10 @@ export class Hub {
|
|
|
299
303
|
this.statusCode(statusCode);
|
|
300
304
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
301
305
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
302
|
-
this.
|
|
303
|
-
this.
|
|
304
|
-
this.
|
|
306
|
+
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
307
|
+
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
308
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.lightLevel;
|
|
309
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
305
310
|
this.openAPIparseStatus();
|
|
306
311
|
this.updateHomeKitCharacteristics();
|
|
307
312
|
} catch (e: any) {
|
|
@@ -360,10 +365,20 @@ export class Hub {
|
|
|
360
365
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
361
366
|
this.hubLightSensor?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
362
367
|
this.debugLog(
|
|
363
|
-
`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
364
|
-
`updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
368
|
+
`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
369
|
+
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
365
370
|
);
|
|
366
371
|
}
|
|
372
|
+
// FirmwareRevision
|
|
373
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
374
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
375
|
+
} else {
|
|
376
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
377
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
378
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
379
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
380
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
381
|
+
}
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
async statusCode(statusCode: number): Promise<void> {
|
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);
|
|
@@ -384,12 +380,13 @@ export class Humidifier {
|
|
|
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) {
|
|
@@ -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) {
|
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,34 +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
|
-
ChargingState?: CharacteristicValue;
|
|
29
|
-
StatusLowBattery?: CharacteristicValue;
|
|
28
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
30
29
|
|
|
31
|
-
// OpenAPI
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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'];
|
|
37
42
|
|
|
38
43
|
// BLE Others
|
|
39
|
-
|
|
40
|
-
switchbot!: switchbot;
|
|
41
|
-
serviceData!: serviceData;
|
|
42
|
-
address!: ad['address'];
|
|
43
|
-
temperature!: serviceData['temperature'];
|
|
44
|
-
celsius!: temperature['c'];
|
|
45
|
-
fahrenheit!: temperature['f'];
|
|
46
|
-
battery!: serviceData['battery'];
|
|
47
|
-
humidity!: serviceData['humidity'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
48
45
|
|
|
49
46
|
//MQTT stuff
|
|
50
47
|
mqttClient: MqttClient | null = null;
|
|
@@ -155,7 +152,7 @@ export class IOSensor {
|
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
// Battery Service
|
|
158
|
-
(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)),
|
|
159
156
|
`${accessory.displayName} Battery`;
|
|
160
157
|
|
|
161
158
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
@@ -197,7 +194,7 @@ export class IOSensor {
|
|
|
197
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
198
195
|
|
|
199
196
|
// Battery
|
|
200
|
-
this.BatteryLevel = Number(this.
|
|
197
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
201
198
|
if (this.BatteryLevel < 15) {
|
|
202
199
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
203
200
|
} else {
|
|
@@ -207,14 +204,14 @@ export class IOSensor {
|
|
|
207
204
|
|
|
208
205
|
// Humidity
|
|
209
206
|
if (!this.device.meter?.hide_humidity) {
|
|
210
|
-
this.CurrentRelativeHumidity = this.
|
|
207
|
+
this.CurrentRelativeHumidity = this.BLE_CurrentRelativeHumidity!;
|
|
211
208
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
// Current Temperature
|
|
215
212
|
if (!this.device.meter?.hide_temperature) {
|
|
216
|
-
this.
|
|
217
|
-
this.CurrentTemperature = this.
|
|
213
|
+
this.BLE_Celsius < 0 ? 0 : this.BLE_Celsius > 100 ? 100 : this.BLE_Celsius;
|
|
214
|
+
this.CurrentTemperature = this.BLE_Celsius;
|
|
218
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
219
216
|
}
|
|
220
217
|
}
|
|
@@ -222,7 +219,7 @@ export class IOSensor {
|
|
|
222
219
|
async openAPIparseStatus(): Promise<void> {
|
|
223
220
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
224
221
|
// Battery
|
|
225
|
-
this.BatteryLevel = Number(this.
|
|
222
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
226
223
|
if (this.BatteryLevel < 15) {
|
|
227
224
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
228
225
|
} else {
|
|
@@ -232,13 +229,13 @@ export class IOSensor {
|
|
|
232
229
|
|
|
233
230
|
// Current Relative Humidity
|
|
234
231
|
if (!this.device.meter?.hide_humidity) {
|
|
235
|
-
this.CurrentRelativeHumidity = this.
|
|
232
|
+
this.CurrentRelativeHumidity = this.OpenAPI_CurrentRelativeHumidity!;
|
|
236
233
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
237
234
|
}
|
|
238
235
|
|
|
239
236
|
// Current Temperature
|
|
240
237
|
if (!this.device.meter?.hide_temperature) {
|
|
241
|
-
this.CurrentTemperature = this.
|
|
238
|
+
this.CurrentTemperature = this.OpenAPI_CurrentTemperature!;
|
|
242
239
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
243
240
|
}
|
|
244
241
|
}
|
|
@@ -282,20 +279,18 @@ export class IOSensor {
|
|
|
282
279
|
.then(async () => {
|
|
283
280
|
// Set an event hander
|
|
284
281
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
285
|
-
this.address = ad.address;
|
|
286
282
|
this.debugLog(
|
|
287
283
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
288
|
-
` BLE Address Found: ${
|
|
284
|
+
` BLE Address Found: ${ad.address}`,
|
|
289
285
|
);
|
|
290
286
|
if (ad.serviceData.humidity! > 0) {
|
|
291
287
|
// reject unreliable data
|
|
292
|
-
this.
|
|
288
|
+
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
293
289
|
}
|
|
294
|
-
this.
|
|
295
|
-
this.
|
|
296
|
-
this.
|
|
297
|
-
this.
|
|
298
|
-
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;
|
|
299
294
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
300
295
|
this.debugLog(
|
|
301
296
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -303,13 +298,13 @@ export class IOSensor {
|
|
|
303
298
|
`battery: ${ad.serviceData.battery}`,
|
|
304
299
|
);
|
|
305
300
|
|
|
306
|
-
if (
|
|
307
|
-
this.
|
|
308
|
-
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}`);
|
|
309
304
|
await this.stopScanning(switchbot);
|
|
310
305
|
} else {
|
|
311
|
-
this.
|
|
312
|
-
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}`);
|
|
313
308
|
}
|
|
314
309
|
};
|
|
315
310
|
// Wait
|
|
@@ -343,10 +338,10 @@ export class IOSensor {
|
|
|
343
338
|
this.statusCode(statusCode);
|
|
344
339
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
345
340
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
346
|
-
this.
|
|
347
|
-
this.
|
|
348
|
-
this.
|
|
349
|
-
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;
|
|
350
345
|
this.openAPIparseStatus();
|
|
351
346
|
this.updateHomeKitCharacteristics();
|
|
352
347
|
} catch (e: any) {
|
|
@@ -426,6 +421,16 @@ export class IOSensor {
|
|
|
426
421
|
this.historyService?.addEntry(entry);
|
|
427
422
|
}
|
|
428
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
|
+
}
|
|
429
434
|
}
|
|
430
435
|
|
|
431
436
|
/*
|
|
@@ -479,7 +484,7 @@ export class IOSensor {
|
|
|
479
484
|
|
|
480
485
|
async stopScanning(switchbot: any) {
|
|
481
486
|
await switchbot.stopScan();
|
|
482
|
-
if (this.
|
|
487
|
+
if (this.BLE_IsConnected) {
|
|
483
488
|
await this.BLEparseStatus();
|
|
484
489
|
await this.updateHomeKitCharacteristics();
|
|
485
490
|
} else {
|