@switchbot/homebridge-switchbot 4.1.1-beta.0 → 4.1.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/CHANGELOG.md +14 -0
- package/config.schema.json +2 -2
- package/dist/device/blindtilt.js +104 -104
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +86 -86
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +95 -93
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -13
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +46 -46
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +85 -87
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +54 -56
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +93 -93
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/docs/functions/default.html +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +104 -104
- package/src/device/bot.ts +86 -86
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +95 -93
- package/src/device/device.ts +46 -46
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +85 -87
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +44 -44
- package/src/device/plug.ts +62 -62
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +54 -55
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +93 -93
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
+
## [4.1.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v4.1.0) (2024-10-21)
|
|
6
|
+
|
|
7
|
+
### What's Changed
|
|
8
|
+
- Remove unneeded light level check [#1096](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1096), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
9
|
+
- Remove unneeded async [#1089](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1089), [#1094](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1094), & [#1097](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1097) ; Thanks [@dnicolson](https://github.com/dnicolson)
|
|
10
|
+
- Fix characteristic warning [#1093](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1093), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
11
|
+
- Fix light level [#1092](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1092), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
12
|
+
- Fix device types [#1091](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1091), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
13
|
+
- Fix curtain light sensor [#1090](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1090), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
14
|
+
- Fix max retry [#1088](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/1088), Thanks [@dnicolson](https://github.com/dnicolson)
|
|
15
|
+
- Housekeeping and updated dependencies.
|
|
16
|
+
|
|
17
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v4.0.0...v4.1.0
|
|
18
|
+
|
|
5
19
|
## [4.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v4.1.0) (2024-10-21)
|
|
6
20
|
|
|
7
21
|
### What's Changed
|
package/config.schema.json
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"configDeviceName": {
|
|
58
58
|
"title": "Device Name",
|
|
59
59
|
"type": "string",
|
|
60
|
-
"pattern": "^[
|
|
60
|
+
"pattern": "^[a-zA-Z0-9]+([a-zA-Z0-9 ]*[a-zA-Z0-9]+)?$",
|
|
61
61
|
"placeholder": "SwitchBot",
|
|
62
62
|
"condition": {
|
|
63
63
|
"functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId);"
|
|
@@ -7699,7 +7699,7 @@
|
|
|
7699
7699
|
"title": "Device Name",
|
|
7700
7700
|
"type": "string",
|
|
7701
7701
|
"placeholder": "SwitchBot",
|
|
7702
|
-
"pattern": "^[
|
|
7702
|
+
"pattern": "^[a-zA-Z0-9]+([a-zA-Z0-9 ]*[a-zA-Z0-9]+)?$",
|
|
7703
7703
|
"condition": {
|
|
7704
7704
|
"functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId);"
|
|
7705
7705
|
}
|
package/dist/device/blindtilt.js
CHANGED
|
@@ -224,7 +224,7 @@ export class BlindTilt extends deviceBase {
|
|
|
224
224
|
}
|
|
225
225
|
catch (e) {
|
|
226
226
|
await this.apiError(e);
|
|
227
|
-
|
|
227
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
228
228
|
}
|
|
229
229
|
this.blindTiltUpdateInProgress = false;
|
|
230
230
|
});
|
|
@@ -233,62 +233,62 @@ export class BlindTilt extends deviceBase {
|
|
|
233
233
|
* Parse the device status from the SwitchBotBLE API
|
|
234
234
|
*/
|
|
235
235
|
async BLEparseStatus() {
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
this.debugLog('BLEparseStatus');
|
|
237
|
+
this.debugLog(`(direction, slidePosition, battery, version) = BLE:(${this.serviceData.tilt}, ${this.serviceData.tilt}, ${this.serviceData.battery}, ${this.accessory.context.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
|
|
238
238
|
// CurrentPosition
|
|
239
239
|
this.WindowCovering.CurrentPosition = 100 - Number(this.serviceData.tilt);
|
|
240
240
|
await this.setMinMax();
|
|
241
|
-
|
|
241
|
+
this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
242
242
|
if (this.setNewTarget) {
|
|
243
|
-
|
|
243
|
+
this.infoLog('Checking Status ...');
|
|
244
244
|
}
|
|
245
245
|
if (this.setNewTarget && this.serviceData.inMotion) {
|
|
246
246
|
this.blindTiltMoving = true;
|
|
247
247
|
await this.setMinMax();
|
|
248
248
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
249
|
-
|
|
249
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
250
250
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
251
251
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
252
|
-
|
|
252
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
253
253
|
}
|
|
254
254
|
else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
255
|
-
|
|
255
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
256
256
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
257
257
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
258
|
-
|
|
258
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
259
259
|
}
|
|
260
260
|
else {
|
|
261
|
-
|
|
261
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
262
262
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
263
263
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
264
|
-
|
|
264
|
+
this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
else {
|
|
268
268
|
this.blindTiltMoving = false;
|
|
269
|
-
|
|
269
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
270
270
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
271
271
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
272
|
-
|
|
272
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
273
273
|
}
|
|
274
|
-
|
|
274
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`);
|
|
275
275
|
// CurrentAmbientLightLevel
|
|
276
276
|
if (!this.device.hide_lightsensor && this.LightSensor?.Service) {
|
|
277
277
|
const set_minLux = this.device.set_minLux ?? 1;
|
|
278
278
|
const set_maxLux = this.device.set_maxLux ?? 6001;
|
|
279
279
|
const spaceBetweenLevels = 9;
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
this.getLightLevel(this.serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels);
|
|
281
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
282
282
|
}
|
|
283
283
|
// BatteryLevel
|
|
284
284
|
if (this.serviceData?.battery) {
|
|
285
285
|
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
286
|
-
|
|
286
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
287
287
|
// StatusLowBattery
|
|
288
288
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
289
289
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
290
290
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
291
|
-
|
|
291
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
;
|
|
@@ -296,28 +296,28 @@ export class BlindTilt extends deviceBase {
|
|
|
296
296
|
* Parse the device status from the SwitchBot OpenAPI
|
|
297
297
|
*/
|
|
298
298
|
async openAPIparseStatus() {
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
this.debugLog('openAPIparseStatus');
|
|
300
|
+
this.debugLog(`(direction, slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.direction}, ${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
|
|
301
301
|
// CurrentPosition
|
|
302
302
|
await this.getCurrentPosttionDirection(this.deviceStatus.direction, this.deviceStatus.slidePosition);
|
|
303
303
|
if (!this.device.hide_lightsensor && this.LightSensor?.Service) {
|
|
304
304
|
const set_minLux = this.device.set_minLux ?? 1;
|
|
305
305
|
const set_maxLux = this.device.set_maxLux ?? 6001;
|
|
306
306
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
307
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
308
|
-
|
|
307
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
308
|
+
this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
309
309
|
}
|
|
310
310
|
// BatteryLevel
|
|
311
311
|
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
312
|
-
|
|
312
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
313
313
|
// StatusLowBattery
|
|
314
314
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
315
315
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
316
316
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
317
|
-
|
|
317
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
318
318
|
// Firmware Version
|
|
319
319
|
const version = this.deviceStatus.version.toString();
|
|
320
|
-
|
|
320
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
321
321
|
let deviceVersion;
|
|
322
322
|
if (version?.includes('.') === false) {
|
|
323
323
|
const replace = version?.replace(/^V|-.*$/g, '');
|
|
@@ -335,21 +335,21 @@ export class BlindTilt extends deviceBase {
|
|
|
335
335
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
336
336
|
.updateValue(deviceVersion);
|
|
337
337
|
this.accessory.context.version = deviceVersion;
|
|
338
|
-
|
|
338
|
+
this.debugLog(`version: ${this.accessory.context.version}`);
|
|
339
339
|
}
|
|
340
340
|
async parseStatusWebhook() {
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
this.debugLog('parseStatusWebhook');
|
|
342
|
+
this.debugLog(`(slidePosition, battery, version) = Webhook:(${this.webhookContext.direction}, ${this.webhookContext.slidePosition}, ${this.webhookContext.battery}, ${this.webhookContext.version}, current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`);
|
|
343
343
|
// CurrentPosition and CurrentHorizontalTiltAngle
|
|
344
344
|
await this.getCurrentPosttionDirection(this.webhookContext.direction, this.webhookContext.slidePosition);
|
|
345
345
|
// BatteryLevel
|
|
346
346
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
347
|
-
|
|
347
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
348
348
|
// StatusLowBattery
|
|
349
349
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
350
350
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
351
351
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
352
|
-
|
|
352
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
353
353
|
// Firmware Version
|
|
354
354
|
const deviceVersion = this.webhookContext.version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
355
355
|
this.accessory
|
|
@@ -359,14 +359,14 @@ export class BlindTilt extends deviceBase {
|
|
|
359
359
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
360
360
|
.updateValue(deviceVersion);
|
|
361
361
|
this.accessory.context.version = deviceVersion;
|
|
362
|
-
|
|
362
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
365
365
|
* Asks the SwitchBot API for the latest device information
|
|
366
366
|
*/
|
|
367
367
|
async refreshStatus() {
|
|
368
368
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
369
|
-
|
|
369
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
370
370
|
}
|
|
371
371
|
else if (this.BLE) {
|
|
372
372
|
await this.BLERefreshStatus();
|
|
@@ -376,11 +376,11 @@ export class BlindTilt extends deviceBase {
|
|
|
376
376
|
}
|
|
377
377
|
else {
|
|
378
378
|
await this.offlineOff();
|
|
379
|
-
|
|
379
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
async BLERefreshStatus() {
|
|
383
|
-
|
|
383
|
+
this.debugLog('BLERefreshStatus');
|
|
384
384
|
const switchBotBLE = await this.switchbotBLE();
|
|
385
385
|
if (switchBotBLE === undefined) {
|
|
386
386
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -397,84 +397,84 @@ export class BlindTilt extends deviceBase {
|
|
|
397
397
|
await this.updateHomeKitCharacteristics();
|
|
398
398
|
}
|
|
399
399
|
else {
|
|
400
|
-
|
|
400
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
401
401
|
await this.BLERefreshConnection(switchBotBLE);
|
|
402
402
|
}
|
|
403
403
|
})();
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
async registerPlatformBLE() {
|
|
407
|
-
|
|
407
|
+
this.debugLog('registerPlatformBLE');
|
|
408
408
|
if (this.config.options?.BLE) {
|
|
409
|
-
|
|
409
|
+
this.debugLog('is listening to Platform BLE.');
|
|
410
410
|
try {
|
|
411
411
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
412
412
|
this.device.bleMac = formattedDeviceId;
|
|
413
|
-
|
|
413
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
414
414
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
415
415
|
try {
|
|
416
|
-
|
|
416
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
417
417
|
this.serviceData = context;
|
|
418
418
|
await this.BLEparseStatus();
|
|
419
419
|
await this.updateHomeKitCharacteristics();
|
|
420
420
|
}
|
|
421
421
|
catch (e) {
|
|
422
|
-
|
|
422
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
423
423
|
}
|
|
424
424
|
};
|
|
425
425
|
}
|
|
426
426
|
catch (error) {
|
|
427
|
-
|
|
427
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
else {
|
|
431
|
-
|
|
431
|
+
this.debugLog('is not listening to Platform BLE');
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
async openAPIRefreshStatus() {
|
|
435
|
-
|
|
435
|
+
this.debugLog('openAPIRefreshStatus');
|
|
436
436
|
try {
|
|
437
|
-
const
|
|
438
|
-
const deviceStatus =
|
|
439
|
-
|
|
437
|
+
const response = await this.deviceRefreshStatus();
|
|
438
|
+
const deviceStatus = response.body;
|
|
439
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
440
440
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
441
|
-
|
|
441
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
442
442
|
this.deviceStatus = deviceStatus.body;
|
|
443
443
|
await this.openAPIparseStatus();
|
|
444
444
|
await this.updateHomeKitCharacteristics();
|
|
445
445
|
}
|
|
446
446
|
else {
|
|
447
|
-
|
|
448
|
-
|
|
447
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
448
|
+
this.debugWarnLog(deviceStatus);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
catch (e) {
|
|
452
452
|
await this.apiError(e);
|
|
453
|
-
|
|
453
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
async registerWebhook() {
|
|
457
457
|
if (this.device.webhook) {
|
|
458
|
-
|
|
458
|
+
this.debugLog('is listening webhook.');
|
|
459
459
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
460
460
|
try {
|
|
461
|
-
|
|
461
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
462
462
|
this.webhookContext = context;
|
|
463
463
|
await this.parseStatusWebhook();
|
|
464
464
|
await this.updateHomeKitCharacteristics();
|
|
465
465
|
}
|
|
466
466
|
catch (e) {
|
|
467
|
-
|
|
467
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
468
468
|
}
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
471
|
else {
|
|
472
|
-
|
|
472
|
+
this.debugLog('is not listening webhook.');
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
async pushChanges() {
|
|
476
476
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
477
|
-
|
|
477
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
478
478
|
}
|
|
479
479
|
else if (this.BLE) {
|
|
480
480
|
await this.BLEpushChanges();
|
|
@@ -484,7 +484,7 @@ export class BlindTilt extends deviceBase {
|
|
|
484
484
|
}
|
|
485
485
|
else {
|
|
486
486
|
await this.offlineOff();
|
|
487
|
-
|
|
487
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
488
488
|
}
|
|
489
489
|
// Refresh the status from the API
|
|
490
490
|
interval(15000)
|
|
@@ -495,61 +495,61 @@ export class BlindTilt extends deviceBase {
|
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
497
|
async BLEpushChanges() {
|
|
498
|
-
|
|
498
|
+
this.debugLog('BLEpushChanges');
|
|
499
499
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
500
|
-
|
|
500
|
+
this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`);
|
|
501
501
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
502
502
|
try {
|
|
503
503
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
504
504
|
this.device.bleMac = formattedDeviceId;
|
|
505
|
-
|
|
505
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
506
506
|
const { setPositionMode, Mode } = await this.setPerformance();
|
|
507
|
-
|
|
507
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
508
508
|
if (switchBotBLE !== false) {
|
|
509
509
|
switchBotBLE
|
|
510
510
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
511
511
|
.then(async (device_list) => {
|
|
512
512
|
const deviceList = device_list;
|
|
513
513
|
return await this.retryBLE({
|
|
514
|
-
max:
|
|
514
|
+
max: this.maxRetryBLE(),
|
|
515
515
|
fn: async () => {
|
|
516
516
|
return await deviceList[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode);
|
|
517
517
|
},
|
|
518
518
|
});
|
|
519
519
|
})
|
|
520
520
|
.then(async () => {
|
|
521
|
-
|
|
521
|
+
this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
|
|
522
522
|
await this.updateHomeKitCharacteristics();
|
|
523
523
|
})
|
|
524
524
|
.catch(async (e) => {
|
|
525
525
|
await this.apiError(e);
|
|
526
|
-
|
|
526
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
527
527
|
await this.BLEPushConnection();
|
|
528
528
|
});
|
|
529
529
|
}
|
|
530
530
|
else {
|
|
531
|
-
|
|
531
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
532
532
|
await this.BLEPushConnection();
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
catch (error) {
|
|
536
|
-
|
|
536
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
else {
|
|
540
|
-
|
|
540
|
+
this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
async openAPIpushChanges() {
|
|
544
|
-
|
|
544
|
+
this.debugLog('openAPIpushChanges');
|
|
545
545
|
const hasDifferentAndRelevantHorizontalTiltAngle = this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
546
546
|
&& this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
547
547
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition
|
|
548
548
|
|| hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
|
|
549
549
|
const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition), Number(this.WindowCovering.TargetHorizontalTiltAngle));
|
|
550
550
|
const { Mode, setPositionMode } = await this.setPerformance();
|
|
551
|
-
|
|
552
|
-
|
|
551
|
+
this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`);
|
|
552
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
553
553
|
let bodyChange;
|
|
554
554
|
if (position === 100) {
|
|
555
555
|
bodyChange = {
|
|
@@ -572,13 +572,13 @@ export class BlindTilt extends deviceBase {
|
|
|
572
572
|
commandType: 'command',
|
|
573
573
|
};
|
|
574
574
|
}
|
|
575
|
-
|
|
575
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
576
576
|
try {
|
|
577
|
-
const
|
|
578
|
-
const deviceStatus =
|
|
579
|
-
|
|
577
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
578
|
+
const deviceStatus = response.body;
|
|
579
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
580
580
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
581
|
-
|
|
581
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
582
582
|
await this.updateHomeKitCharacteristics();
|
|
583
583
|
}
|
|
584
584
|
else {
|
|
@@ -587,12 +587,12 @@ export class BlindTilt extends deviceBase {
|
|
|
587
587
|
}
|
|
588
588
|
catch (e) {
|
|
589
589
|
await this.apiError(e);
|
|
590
|
-
|
|
590
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
else {
|
|
594
|
-
|
|
595
|
-
|
|
594
|
+
this.debugLog(`No changes (openAPIpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
595
|
+
this.debugLog(`No changes (openAPIpushChanges), TargetHorizontalTiltAngle: ${this.WindowCovering.TargetHorizontalTiltAngle}, CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
598
|
/**
|
|
@@ -600,10 +600,10 @@ export class BlindTilt extends deviceBase {
|
|
|
600
600
|
*/
|
|
601
601
|
async TargetHorizontalTiltAngleSet(value) {
|
|
602
602
|
if (this.WindowCovering.TargetHorizontalTiltAngle !== this.accessory.context.TargetHorizontalTiltAngle) {
|
|
603
|
-
|
|
603
|
+
this.debugLog(`Set TargetHorizontalTiltAngle: ${value}`);
|
|
604
604
|
}
|
|
605
605
|
else {
|
|
606
|
-
|
|
606
|
+
this.debugLog(`No changes, TargetHorizontalTiltAngle: ${value}`);
|
|
607
607
|
}
|
|
608
608
|
// value = value < 0 ? -90 : 90;
|
|
609
609
|
this.WindowCovering.TargetHorizontalTiltAngle = value;
|
|
@@ -615,10 +615,10 @@ export class BlindTilt extends deviceBase {
|
|
|
615
615
|
*/
|
|
616
616
|
async TargetPositionSet(value) {
|
|
617
617
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
618
|
-
|
|
618
|
+
this.debugLog(`Set TargetPosition: ${value}`);
|
|
619
619
|
}
|
|
620
620
|
else {
|
|
621
|
-
|
|
621
|
+
this.debugLog(`No changes, TargetPosition: ${value}`);
|
|
622
622
|
}
|
|
623
623
|
this.WindowCovering.TargetPosition = value;
|
|
624
624
|
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
|
|
@@ -626,22 +626,22 @@ export class BlindTilt extends deviceBase {
|
|
|
626
626
|
}
|
|
627
627
|
async startUpdatingBlindTiltIfNeeded() {
|
|
628
628
|
await this.setMinMax();
|
|
629
|
-
|
|
629
|
+
this.debugLog('setMinMax');
|
|
630
630
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
631
631
|
|| this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
|
|
632
632
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
633
633
|
this.setNewTarget = true;
|
|
634
|
-
|
|
634
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
635
635
|
}
|
|
636
636
|
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
637
637
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
638
638
|
this.setNewTarget = true;
|
|
639
|
-
|
|
639
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
640
640
|
}
|
|
641
641
|
else {
|
|
642
642
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
643
643
|
this.setNewTarget = false;
|
|
644
|
-
|
|
644
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
645
645
|
}
|
|
646
646
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
647
647
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
@@ -650,10 +650,10 @@ export class BlindTilt extends deviceBase {
|
|
|
650
650
|
* The minimum time depends on the network control latency.
|
|
651
651
|
*/
|
|
652
652
|
clearTimeout(this.setNewTargetTimer);
|
|
653
|
-
|
|
653
|
+
this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
|
|
654
654
|
if (this.setNewTarget) {
|
|
655
655
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
656
|
-
|
|
656
|
+
this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
|
|
657
657
|
this.setNewTarget = false;
|
|
658
658
|
}, this.deviceUpdateRate * 1000);
|
|
659
659
|
}
|
|
@@ -707,14 +707,14 @@ export class BlindTilt extends deviceBase {
|
|
|
707
707
|
}
|
|
708
708
|
async BLEPushConnection() {
|
|
709
709
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
710
|
-
|
|
710
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
711
711
|
await this.openAPIpushChanges();
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
714
|
async BLERefreshConnection(switchbot) {
|
|
715
|
-
|
|
715
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
716
716
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
717
|
-
|
|
717
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
718
718
|
await this.openAPIRefreshStatus();
|
|
719
719
|
}
|
|
720
720
|
}
|
|
@@ -796,50 +796,50 @@ export class BlindTilt extends deviceBase {
|
|
|
796
796
|
}
|
|
797
797
|
async getCurrentPosttionDirection(direction, slidePosition) {
|
|
798
798
|
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(slidePosition), String(direction));
|
|
799
|
-
|
|
800
|
-
|
|
799
|
+
this.debugLog(`Slide Position: ${slidePosition}`);
|
|
800
|
+
this.debugLog(`Homekit Position: ${homekitPosition}`);
|
|
801
801
|
this.WindowCovering.CurrentPosition = homekitPosition;
|
|
802
802
|
await this.setMinMax();
|
|
803
|
-
|
|
803
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
804
804
|
if (homekitTiltAngle) {
|
|
805
805
|
this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle;
|
|
806
|
-
|
|
806
|
+
this.debugLog(`CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
807
807
|
}
|
|
808
808
|
if (this.setNewTarget) {
|
|
809
809
|
this.blindTiltMoving = true;
|
|
810
|
-
|
|
810
|
+
this.infoLog('Checking Status ...');
|
|
811
811
|
await this.setMinMax();
|
|
812
812
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
813
813
|
|| (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
814
|
-
|
|
814
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
815
815
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
816
816
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
817
|
-
|
|
817
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
818
818
|
}
|
|
819
819
|
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
820
|
-
|
|
820
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
821
821
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
822
822
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
823
|
-
|
|
823
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
824
824
|
}
|
|
825
825
|
else {
|
|
826
|
-
|
|
826
|
+
this.debugLog(`Standby because reached position, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
827
827
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
828
828
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
829
|
-
|
|
829
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
832
|
else {
|
|
833
833
|
this.blindTiltMoving = false;
|
|
834
|
-
|
|
834
|
+
this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
835
835
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
836
836
|
if (homekitTiltAngle) {
|
|
837
837
|
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
838
838
|
}
|
|
839
839
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
840
|
-
|
|
840
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
841
841
|
}
|
|
842
|
-
|
|
842
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`);
|
|
843
843
|
}
|
|
844
844
|
/**
|
|
845
845
|
* Maps device values to homekit values
|