@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-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/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +58 -65
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +52 -55
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +68 -68
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +76 -75
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +67 -59
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +81 -94
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +197 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +58 -62
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +28 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +68 -67
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +51 -47
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +75 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -74
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +66 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +39 -39
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -53
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -66
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +32 -34
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -23
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +30 -32
- 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/light.js +26 -29
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +22 -23
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +47 -50
- 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/vacuumcleaner.js +20 -23
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +22 -23
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -44
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +114 -78
- package/src/device/bot.ts +102 -63
- package/src/device/ceilinglight.ts +113 -73
- package/src/device/colorbulb.ts +144 -87
- package/src/device/contact.ts +98 -63
- package/src/device/curtain.ts +160 -134
- package/src/device/hub.ts +228 -39
- package/src/device/humidifier.ts +136 -85
- package/src/device/iosensor.ts +52 -32
- package/src/device/lightstrip.ts +118 -72
- package/src/device/lock.ts +85 -50
- package/src/device/meter.ts +104 -80
- package/src/device/meterplus.ts +103 -80
- package/src/device/motion.ts +95 -59
- package/src/device/plug.ts +70 -44
- package/src/device/robotvacuumcleaner.ts +107 -56
- package/src/irdevice/airconditioner.ts +116 -86
- package/src/irdevice/airpurifier.ts +60 -39
- package/src/irdevice/camera.ts +40 -28
- package/src/irdevice/fan.ts +52 -38
- package/src/irdevice/light.ts +48 -34
- package/src/irdevice/other.ts +44 -28
- package/src/irdevice/tv.ts +70 -56
- package/src/irdevice/vacuumcleaner.ts +40 -28
- package/src/irdevice/waterheater.ts +48 -32
- package/src/platform.ts +87 -56
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/curtain.ts
CHANGED
|
@@ -26,6 +26,8 @@ export class Curtain {
|
|
|
26
26
|
lastActivation?: number;
|
|
27
27
|
|
|
28
28
|
// OpenAPI Others
|
|
29
|
+
Version: deviceStatus['version'];
|
|
30
|
+
Battery: deviceStatus['battery'];
|
|
29
31
|
deviceStatus!: any; //deviceStatusResponse;
|
|
30
32
|
slidePosition: deviceStatus['slidePosition'];
|
|
31
33
|
moving: deviceStatus['moving'];
|
|
@@ -68,20 +70,24 @@ export class Curtain {
|
|
|
68
70
|
doCurtainUpdate!: Subject<void>;
|
|
69
71
|
|
|
70
72
|
// Connection
|
|
71
|
-
private readonly BLE =
|
|
72
|
-
private readonly OpenAPI =
|
|
73
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
74
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
73
75
|
|
|
74
76
|
// EVE history service handler
|
|
75
77
|
historyService: any = null;
|
|
76
78
|
|
|
77
|
-
constructor(
|
|
79
|
+
constructor(
|
|
80
|
+
private readonly platform: SwitchBotPlatform,
|
|
81
|
+
private accessory: PlatformAccessory,
|
|
82
|
+
public device: device & devicesConfig,
|
|
83
|
+
) {
|
|
78
84
|
// default placeholders
|
|
79
85
|
this.logs(device);
|
|
80
86
|
this.refreshRate(device);
|
|
81
87
|
this.scan(device);
|
|
82
|
-
this.config(device);
|
|
83
88
|
this.setupMqtt(device);
|
|
84
89
|
this.context();
|
|
90
|
+
this.config(device);
|
|
85
91
|
|
|
86
92
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
87
93
|
this.doCurtainUpdate = new Subject();
|
|
@@ -166,11 +172,7 @@ export class Curtain {
|
|
|
166
172
|
}
|
|
167
173
|
|
|
168
174
|
// Battery Service
|
|
169
|
-
if (!this.
|
|
170
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
171
|
-
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
172
|
-
accessory.removeService(this.batteryService!);
|
|
173
|
-
} else if (this.BLE && !this.batteryService) {
|
|
175
|
+
if (!this.batteryService) {
|
|
174
176
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
175
177
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
176
178
|
`${accessory.displayName} Battery`;
|
|
@@ -179,6 +181,7 @@ export class Curtain {
|
|
|
179
181
|
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
180
182
|
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
181
183
|
}
|
|
184
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
182
185
|
} else {
|
|
183
186
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
184
187
|
}
|
|
@@ -218,8 +221,10 @@ export class Curtain {
|
|
|
218
221
|
await this.pushChanges();
|
|
219
222
|
} catch (e: any) {
|
|
220
223
|
this.apiError(e);
|
|
221
|
-
this.errorLog(
|
|
222
|
-
|
|
224
|
+
this.errorLog(
|
|
225
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
226
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
227
|
+
);
|
|
223
228
|
}
|
|
224
229
|
this.curtainUpdateInProgress = false;
|
|
225
230
|
});
|
|
@@ -229,66 +234,65 @@ export class Curtain {
|
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
/*
|
|
232
|
-
* Setup EVE history features for curtain devices.
|
|
237
|
+
* Setup EVE history features for curtain devices.
|
|
233
238
|
*/
|
|
234
239
|
async setupHistoryService(device: device & devicesConfig): Promise<void> {
|
|
235
240
|
if (device.history !== true) {
|
|
236
241
|
return;
|
|
237
242
|
}
|
|
238
|
-
|
|
243
|
+
|
|
239
244
|
const mac = this.device
|
|
240
245
|
.deviceId!.match(/.{1,2}/g)!
|
|
241
246
|
.join(':')
|
|
242
247
|
.toLowerCase();
|
|
243
|
-
this.historyService =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
});
|
|
248
|
+
this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
|
|
249
|
+
log: this.platform.log,
|
|
250
|
+
storage: 'fs',
|
|
251
|
+
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
252
|
+
});
|
|
249
253
|
const motion: Service =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`${this.accessory.displayName} Motion`);
|
|
254
|
+
this.accessory.getService(this.platform.Service.MotionSensor) ||
|
|
255
|
+
this.accessory.addService(this.platform.Service.MotionSensor, `${this.accessory.displayName} Motion`);
|
|
253
256
|
motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation);
|
|
254
|
-
motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
257
|
+
motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
|
|
258
|
+
const lastActivation = this.accessory.context.lastActivation
|
|
259
|
+
? Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime())
|
|
260
|
+
: 0;
|
|
261
|
+
return lastActivation;
|
|
262
|
+
});
|
|
261
263
|
await this.setMinMax();
|
|
262
|
-
motion.getCharacteristic(this.platform.Characteristic.MotionDetected)
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
264
|
+
motion.getCharacteristic(this.platform.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
|
|
265
|
+
if (event.newValue !== event.oldValue) {
|
|
266
|
+
const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
|
|
267
|
+
const entry = {
|
|
268
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
269
|
+
motion: event.newValue,
|
|
270
|
+
};
|
|
271
|
+
this.accessory.context.lastActivation = entry.time;
|
|
272
|
+
sensor?.updateCharacteristic(
|
|
273
|
+
this.platform.eve.Characteristics.LastActivation,
|
|
274
|
+
Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime()),
|
|
275
|
+
);
|
|
276
|
+
this.historyService.addEntry(entry);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
278
279
|
this.updateHistory();
|
|
279
280
|
}
|
|
280
281
|
|
|
281
|
-
async updateHistory()
|
|
282
|
+
async updateHistory(): Promise<void> {
|
|
282
283
|
const motion = Number(this.CurrentPosition) > 0 ? 1 : 0;
|
|
283
|
-
this.historyService.addEntry
|
|
284
|
-
time: Math.round(new Date().valueOf()/1000),
|
|
285
|
-
motion: motion
|
|
284
|
+
this.historyService.addEntry({
|
|
285
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
286
|
+
motion: motion,
|
|
286
287
|
});
|
|
287
|
-
setTimeout(
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
setTimeout(
|
|
289
|
+
() => {
|
|
290
|
+
this.updateHistory();
|
|
291
|
+
},
|
|
292
|
+
10 * 60 * 1000,
|
|
293
|
+
);
|
|
290
294
|
}
|
|
291
|
-
|
|
295
|
+
|
|
292
296
|
/**
|
|
293
297
|
* Parse the device status from the SwitchBot api
|
|
294
298
|
*/
|
|
@@ -301,8 +305,9 @@ export class Curtain {
|
|
|
301
305
|
await this.openAPIparseStatus();
|
|
302
306
|
} else {
|
|
303
307
|
await this.offlineOff();
|
|
304
|
-
this.debugWarnLog(
|
|
305
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
308
|
+
this.debugWarnLog(
|
|
309
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
310
|
+
);
|
|
306
311
|
}
|
|
307
312
|
}
|
|
308
313
|
|
|
@@ -394,8 +399,8 @@ export class Curtain {
|
|
|
394
399
|
this.debugLog();
|
|
395
400
|
}
|
|
396
401
|
this.debugLog(
|
|
397
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
398
|
-
|
|
402
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
403
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
399
404
|
);
|
|
400
405
|
}
|
|
401
406
|
// Battery
|
|
@@ -405,8 +410,9 @@ export class Curtain {
|
|
|
405
410
|
} else {
|
|
406
411
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
407
412
|
}
|
|
408
|
-
this.debugLog(
|
|
409
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}
|
|
413
|
+
this.debugLog(
|
|
414
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
|
|
415
|
+
);
|
|
410
416
|
}
|
|
411
417
|
|
|
412
418
|
async openAPIparseStatus(): Promise<void> {
|
|
@@ -473,8 +479,10 @@ export class Curtain {
|
|
|
473
479
|
await this.openAPIRefreshStatus();
|
|
474
480
|
} else {
|
|
475
481
|
await this.offlineOff();
|
|
476
|
-
this.debugWarnLog(
|
|
477
|
-
|
|
482
|
+
this.debugWarnLog(
|
|
483
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
484
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
485
|
+
);
|
|
478
486
|
}
|
|
479
487
|
}
|
|
480
488
|
|
|
@@ -499,8 +507,10 @@ export class Curtain {
|
|
|
499
507
|
// Set an event hander
|
|
500
508
|
switchbot.onadvertisement = async (ad: any) => {
|
|
501
509
|
this.address = ad.address;
|
|
502
|
-
this.debugLog(
|
|
503
|
-
|
|
510
|
+
this.debugLog(
|
|
511
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
512
|
+
` BLE Address Found: ${this.address}`,
|
|
513
|
+
);
|
|
504
514
|
this.serviceData = ad.serviceData;
|
|
505
515
|
this.calibration = ad.serviceData.calibration;
|
|
506
516
|
this.battery = ad.serviceData.battery;
|
|
@@ -511,7 +521,8 @@ export class Curtain {
|
|
|
511
521
|
this.debugLog(
|
|
512
522
|
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
513
523
|
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
514
|
-
`inMotion: ${ad.serviceData.inMotion}
|
|
524
|
+
`inMotion: ${ad.serviceData.inMotion}`,
|
|
525
|
+
);
|
|
515
526
|
|
|
516
527
|
if (this.serviceData) {
|
|
517
528
|
this.connected = true;
|
|
@@ -531,8 +542,10 @@ export class Curtain {
|
|
|
531
542
|
})
|
|
532
543
|
.catch(async (e: any) => {
|
|
533
544
|
this.apiError(e);
|
|
534
|
-
this.errorLog(
|
|
535
|
-
|
|
545
|
+
this.errorLog(
|
|
546
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
547
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
548
|
+
);
|
|
536
549
|
await this.BLERefreshConnection(switchbot);
|
|
537
550
|
});
|
|
538
551
|
} else {
|
|
@@ -550,10 +563,7 @@ export class Curtain {
|
|
|
550
563
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
551
564
|
this.statusCode(statusCode);
|
|
552
565
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
553
|
-
this.debugLog(
|
|
554
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
555
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
556
|
-
);
|
|
566
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
557
567
|
this.slidePosition = deviceStatus.body.slidePosition;
|
|
558
568
|
this.moving = deviceStatus.body.moving;
|
|
559
569
|
this.brightness = deviceStatus.body.brightness;
|
|
@@ -561,8 +571,10 @@ export class Curtain {
|
|
|
561
571
|
this.updateHomeKitCharacteristics();
|
|
562
572
|
} catch (e: any) {
|
|
563
573
|
this.apiError(e);
|
|
564
|
-
this.errorLog(
|
|
565
|
-
|
|
574
|
+
this.errorLog(
|
|
575
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
576
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
577
|
+
);
|
|
566
578
|
}
|
|
567
579
|
}
|
|
568
580
|
|
|
@@ -575,8 +587,9 @@ export class Curtain {
|
|
|
575
587
|
await this.openAPIpushChanges();
|
|
576
588
|
} else {
|
|
577
589
|
await this.offlineOff();
|
|
578
|
-
this.debugWarnLog(
|
|
579
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen
|
|
590
|
+
this.debugWarnLog(
|
|
591
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
592
|
+
);
|
|
580
593
|
}
|
|
581
594
|
// Refresh the status from the API
|
|
582
595
|
interval(15000)
|
|
@@ -618,8 +631,10 @@ export class Curtain {
|
|
|
618
631
|
})
|
|
619
632
|
.catch(async (e: any) => {
|
|
620
633
|
this.apiError(e);
|
|
621
|
-
this.errorLog(
|
|
622
|
-
|
|
634
|
+
this.errorLog(
|
|
635
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
636
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
637
|
+
);
|
|
623
638
|
await this.BLEPushConnection();
|
|
624
639
|
throw new Error('Connection error');
|
|
625
640
|
});
|
|
@@ -630,7 +645,8 @@ export class Curtain {
|
|
|
630
645
|
await this.BLEPushConnection();
|
|
631
646
|
}
|
|
632
647
|
} else {
|
|
633
|
-
this.debugLog(
|
|
648
|
+
this.debugLog(
|
|
649
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
|
|
634
650
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
635
651
|
);
|
|
636
652
|
}
|
|
@@ -658,7 +674,7 @@ export class Curtain {
|
|
|
658
674
|
|
|
659
675
|
async openAPIpushChanges(): Promise<void> {
|
|
660
676
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
661
|
-
if (
|
|
677
|
+
if (this.TargetPosition !== this.CurrentPosition || this.device.disableCaching) {
|
|
662
678
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition}`);
|
|
663
679
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
664
680
|
if (Number(this.TargetPosition) > 50) {
|
|
@@ -676,9 +692,9 @@ export class Curtain {
|
|
|
676
692
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
677
693
|
const adjustedMode = this.setPositionMode || 'ff';
|
|
678
694
|
const bodyChange = JSON.stringify({
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
695
|
+
command: 'setPosition',
|
|
696
|
+
parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
697
|
+
commandType: 'command',
|
|
682
698
|
});
|
|
683
699
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
684
700
|
try {
|
|
@@ -693,13 +709,16 @@ export class Curtain {
|
|
|
693
709
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
694
710
|
} catch (e: any) {
|
|
695
711
|
this.apiError(e);
|
|
696
|
-
this.errorLog(
|
|
697
|
-
|
|
712
|
+
this.errorLog(
|
|
713
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
714
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
698
715
|
);
|
|
699
716
|
}
|
|
700
717
|
} else {
|
|
701
|
-
this.debugLog(
|
|
702
|
-
|
|
718
|
+
this.debugLog(
|
|
719
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
720
|
+
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
721
|
+
);
|
|
703
722
|
}
|
|
704
723
|
}
|
|
705
724
|
|
|
@@ -791,37 +810,37 @@ export class Curtain {
|
|
|
791
810
|
}
|
|
792
811
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
793
812
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
794
|
-
this.debugLog(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
813
|
+
this.debugLog(
|
|
814
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
815
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
816
|
+
);
|
|
817
|
+
if (this.device.history) {
|
|
818
|
+
this.historyService?.addEntry({
|
|
819
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
820
|
+
lux: this.CurrentAmbientLightLevel,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
802
823
|
}
|
|
803
824
|
}
|
|
804
|
-
if (this.
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
810
|
-
}
|
|
811
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
812
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
813
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
825
|
+
if (this.BatteryLevel === undefined) {
|
|
826
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
827
|
+
} else {
|
|
828
|
+
if (this.device.mqttURL) {
|
|
829
|
+
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
814
830
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
this.
|
|
831
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
832
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
833
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
834
|
+
}
|
|
835
|
+
if (this.StatusLowBattery === undefined) {
|
|
836
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
837
|
+
} else {
|
|
838
|
+
if (this.device.mqttURL) {
|
|
839
|
+
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
824
840
|
}
|
|
841
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
842
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
843
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
825
844
|
}
|
|
826
845
|
}
|
|
827
846
|
|
|
@@ -970,8 +989,10 @@ export class Curtain {
|
|
|
970
989
|
if (this.updateRate > device.scanDuration) {
|
|
971
990
|
this.scanDuration = this.updateRate;
|
|
972
991
|
if (this.BLE) {
|
|
973
|
-
this.warnLog(
|
|
974
|
-
|
|
992
|
+
this.warnLog(
|
|
993
|
+
`${this.device.deviceType}: ` +
|
|
994
|
+
`${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`,
|
|
995
|
+
);
|
|
975
996
|
}
|
|
976
997
|
} else {
|
|
977
998
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
@@ -1007,8 +1028,10 @@ export class Curtain {
|
|
|
1007
1028
|
this.offlineOff();
|
|
1008
1029
|
break;
|
|
1009
1030
|
case 171:
|
|
1010
|
-
this.errorLog(
|
|
1011
|
-
|
|
1031
|
+
this.errorLog(
|
|
1032
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1033
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
1034
|
+
);
|
|
1012
1035
|
this.offlineOff();
|
|
1013
1036
|
break;
|
|
1014
1037
|
case 190:
|
|
@@ -1024,8 +1047,10 @@ export class Curtain {
|
|
|
1024
1047
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1025
1048
|
break;
|
|
1026
1049
|
default:
|
|
1027
|
-
this.infoLog(
|
|
1028
|
-
|
|
1050
|
+
this.infoLog(
|
|
1051
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1052
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
1053
|
+
);
|
|
1029
1054
|
}
|
|
1030
1055
|
}
|
|
1031
1056
|
|
|
@@ -1043,23 +1068,24 @@ export class Curtain {
|
|
|
1043
1068
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
1044
1069
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
1045
1070
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
1049
|
-
}
|
|
1071
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
1072
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
1050
1073
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
1051
1074
|
}
|
|
1052
1075
|
|
|
1053
1076
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1054
1077
|
let FirmwareRevision: string;
|
|
1055
|
-
this.debugLog(
|
|
1056
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
1078
|
+
this.debugLog(
|
|
1079
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
1080
|
+
);
|
|
1057
1081
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1058
1082
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1059
|
-
if (
|
|
1060
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1061
|
-
} else if (device.firmware) {
|
|
1083
|
+
if (device.firmware) {
|
|
1062
1084
|
FirmwareRevision = device.firmware;
|
|
1085
|
+
} else if (device.version) {
|
|
1086
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
1087
|
+
} if (accessory.context.FirmwareRevision) {
|
|
1088
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1063
1089
|
} else {
|
|
1064
1090
|
FirmwareRevision = this.platform.version;
|
|
1065
1091
|
}
|
|
@@ -1087,23 +1113,23 @@ export class Curtain {
|
|
|
1087
1113
|
|
|
1088
1114
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
1089
1115
|
if (this.accessory.context.CurrentAmbientLightLevel !== undefined) {
|
|
1090
|
-
|
|
1116
|
+
this.CurrentAmbientLightLevel = this.accessory.context.CurrentAmbientLightLevel;
|
|
1091
1117
|
}
|
|
1092
1118
|
}
|
|
1093
1119
|
|
|
1094
1120
|
if (this.BLE) {
|
|
1095
1121
|
if (this.accessory.context.BatteryLevel === undefined) {
|
|
1096
|
-
|
|
1122
|
+
this.BatteryLevel = 100;
|
|
1097
1123
|
} else {
|
|
1098
|
-
|
|
1124
|
+
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
1099
1125
|
}
|
|
1100
1126
|
if (this.accessory.context.StatusLowBattery === undefined) {
|
|
1101
|
-
|
|
1127
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
1102
1128
|
} else {
|
|
1103
|
-
|
|
1129
|
+
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
1104
1130
|
}
|
|
1105
1131
|
}
|
|
1106
|
-
|
|
1132
|
+
|
|
1107
1133
|
if (this.device.history === true) {
|
|
1108
1134
|
// initialize when this accessory is newly created.
|
|
1109
1135
|
this.accessory.context.lastActivation = this.accessory.context.lastActivation ?? 0;
|
|
@@ -1159,7 +1185,7 @@ export class Curtain {
|
|
|
1159
1185
|
config['maxRetry'] = device.maxRetry;
|
|
1160
1186
|
}
|
|
1161
1187
|
if (Object.entries(config).length !== 0) {
|
|
1162
|
-
this.
|
|
1188
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1163
1189
|
}
|
|
1164
1190
|
}
|
|
1165
1191
|
|