@switchbot/homebridge-switchbot 3.8.3 → 4.0.0-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.cjs +81 -0
- package/.github/workflows/beta-release.yml +12 -4
- package/CHANGELOG.md +15 -1
- package/config.schema.json +583 -937
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +68 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +63 -59
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +56 -65
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -4
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +73 -80
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +38 -38
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +60 -60
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -6
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +86 -20
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +50 -51
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +48 -48
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +53 -55
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -35
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +57 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -4
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +38 -39
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +35 -35
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +35 -35
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +27 -27
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +32 -32
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +39 -40
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +28 -28
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -32
- 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 +11 -12
- 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 +9 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -23
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +28 -14
- package/dist/irdevice/irdevice.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 +12 -13
- 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 +12 -15
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +27 -28
- 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 +9 -10
- 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 +9 -10
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +9 -22
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +154 -260
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -82
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -20
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -102
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +42 -0
- package/docs/assets/main.js +1 -1
- package/docs/functions/default.html +1 -1
- package/docs/index.html +61 -50
- package/docs/media/security-privacy-bluetooth.png +0 -0
- package/package.json +5 -7
- package/src/device/blindtilt.ts +74 -74
- package/src/device/bot.ts +68 -67
- package/src/device/ceilinglight.ts +59 -70
- package/src/device/colorbulb.ts +79 -88
- package/src/device/contact.ts +40 -43
- package/src/device/curtain.ts +66 -68
- package/src/device/device.ts +86 -40
- package/src/device/fan.ts +52 -56
- package/src/device/hub.ts +50 -53
- package/src/device/humidifier.ts +56 -61
- package/src/device/iosensor.ts +37 -40
- package/src/device/lightstrip.ts +62 -72
- package/src/device/lock.ts +41 -45
- package/src/device/meter.ts +37 -40
- package/src/device/meterplus.ts +37 -40
- package/src/device/motion.ts +29 -32
- package/src/device/plug.ts +34 -37
- package/src/device/robotvacuumcleaner.ts +41 -49
- package/src/device/waterdetector.ts +30 -33
- package/src/irdevice/airconditioner.ts +33 -35
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +24 -25
- package/src/irdevice/irdevice.ts +31 -27
- package/src/irdevice/light.ts +14 -15
- package/src/irdevice/other.ts +14 -17
- package/src/irdevice/tv.ts +28 -29
- package/src/irdevice/vacuumcleaner.ts +10 -11
- package/src/irdevice/waterheater.ts +10 -11
- package/src/platform.ts +178 -287
- package/src/settings.ts +67 -88
- package/src/utils.ts +2 -106
- package/dist/types/bledevicestatus.d.ts +0 -281
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -89
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -6
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -13
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -149
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -156
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/src/types/bledevicestatus.ts +0 -303
- package/src/types/devicelist.ts +0 -124
- package/src/types/deviceresponse.ts +0 -14
- package/src/types/devicestatus.ts +0 -178
- package/src/types/devicewebhookstatus.ts +0 -191
- package/src/types/irdevicelist.ts +0 -15
- package/src/types/pushbody.ts +0 -9
package/src/device/blindtilt.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* blindtilt.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { blindTiltServiceData, blindTiltStatus, blindTiltWebhookContext, bodyChange, device, SwitchbotDevice, WoBlindTilt } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { blindTiltServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { blindTiltStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { blindTiltWebhookContext } from '../types/devicewebhookstatus.js'
|
|
9
|
+
import type { blindTiltConfig, devicesConfig } from '../settings.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -88,7 +85,8 @@ export class BlindTilt extends deviceBase {
|
|
|
88
85
|
accessory.category = this.hap.Categories.WINDOW_COVERING
|
|
89
86
|
|
|
90
87
|
// default placeholders
|
|
91
|
-
|
|
88
|
+
|
|
89
|
+
this.mappingMode = ((device as blindTiltConfig).mode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp
|
|
92
90
|
this.debugLog(`Mapping mode: ${this.mappingMode}`)
|
|
93
91
|
|
|
94
92
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -112,7 +110,7 @@ export class BlindTilt extends deviceBase {
|
|
|
112
110
|
|
|
113
111
|
// Initialize WindowCovering Characteristics
|
|
114
112
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
|
|
115
|
-
minStep: device.
|
|
113
|
+
minStep: (device as blindTiltConfig).set_minStep ?? 1,
|
|
116
114
|
minValue: 0,
|
|
117
115
|
maxValue: 100,
|
|
118
116
|
validValueRanges: [0, 100],
|
|
@@ -122,7 +120,7 @@ export class BlindTilt extends deviceBase {
|
|
|
122
120
|
|
|
123
121
|
// Initialize WindowCovering CurrentPosition Characteristic
|
|
124
122
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.CurrentPosition).setProps({
|
|
125
|
-
minStep: device.
|
|
123
|
+
minStep: (device as blindTiltConfig).set_minStep ?? 1,
|
|
126
124
|
minValue: 0,
|
|
127
125
|
maxValue: 100,
|
|
128
126
|
validValueRanges: [0, 100],
|
|
@@ -165,7 +163,7 @@ export class BlindTilt extends deviceBase {
|
|
|
165
163
|
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
166
164
|
|
|
167
165
|
// Initialize LightSensor Service
|
|
168
|
-
if (device.
|
|
166
|
+
if ((device as blindTiltConfig).hide_lightsensor) {
|
|
169
167
|
if (this.LightSensor?.Service) {
|
|
170
168
|
this.debugLog('Removing Light Sensor Service')
|
|
171
169
|
this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor) as Service
|
|
@@ -190,7 +188,7 @@ export class BlindTilt extends deviceBase {
|
|
|
190
188
|
}
|
|
191
189
|
|
|
192
190
|
// Initialize Open Mode Switch Service
|
|
193
|
-
if (!device.
|
|
191
|
+
if (!(device as blindTiltConfig).silentModeSwitch) {
|
|
194
192
|
if (this.OpenModeSwitch?.Service) {
|
|
195
193
|
this.debugLog('Removing Open Mode Switch Service')
|
|
196
194
|
this.OpenModeSwitch.Service = this.accessory.getService(this.hap.Service.Switch) as Service
|
|
@@ -215,7 +213,7 @@ export class BlindTilt extends deviceBase {
|
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
// Initialize Close Mode Switch Service
|
|
218
|
-
if (!device.
|
|
216
|
+
if (!(device as blindTiltConfig).silentModeSwitch) {
|
|
219
217
|
if (this.CloseModeSwitch?.Service) {
|
|
220
218
|
this.debugLog('Removing Close Mode Switch Service')
|
|
221
219
|
this.CloseModeSwitch.Service = this.accessory.getService(this.hap.Service.Switch) as Service
|
|
@@ -244,7 +242,7 @@ export class BlindTilt extends deviceBase {
|
|
|
244
242
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
245
243
|
this.refreshStatus()
|
|
246
244
|
} catch (e: any) {
|
|
247
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
245
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
248
246
|
}
|
|
249
247
|
|
|
250
248
|
// regisiter webhook event handler if enabled
|
|
@@ -252,7 +250,7 @@ export class BlindTilt extends deviceBase {
|
|
|
252
250
|
this.debugLog('Registering Webhook Event Handler')
|
|
253
251
|
this.registerWebhook()
|
|
254
252
|
} catch (e: any) {
|
|
255
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
253
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
256
254
|
}
|
|
257
255
|
|
|
258
256
|
// regisiter platform BLE event handler if enabled
|
|
@@ -260,7 +258,7 @@ export class BlindTilt extends deviceBase {
|
|
|
260
258
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
261
259
|
this.registerPlatformBLE()
|
|
262
260
|
} catch (e: any) {
|
|
263
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
261
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
// Start an update interval
|
|
@@ -344,9 +342,9 @@ export class BlindTilt extends deviceBase {
|
|
|
344
342
|
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`)
|
|
345
343
|
|
|
346
344
|
// CurrentAmbientLightLevel
|
|
347
|
-
if (!this.device.
|
|
348
|
-
const set_minLux = this.device.
|
|
349
|
-
const set_maxLux = this.device.
|
|
345
|
+
if (!(this.device as blindTiltConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
346
|
+
const set_minLux = (this.device as blindTiltConfig).set_minLux ?? 1
|
|
347
|
+
const set_maxLux = (this.device as blindTiltConfig).set_maxLux ?? 6001
|
|
350
348
|
const spaceBetweenLevels = 9
|
|
351
349
|
|
|
352
350
|
await this.getLightLevel(this.serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels)
|
|
@@ -354,14 +352,16 @@ export class BlindTilt extends deviceBase {
|
|
|
354
352
|
}
|
|
355
353
|
|
|
356
354
|
// BatteryLevel
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
355
|
+
if (this.serviceData?.battery) {
|
|
356
|
+
this.Battery.BatteryLevel = this.serviceData.battery
|
|
357
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
358
|
+
|
|
359
|
+
// StatusLowBattery
|
|
360
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
361
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
362
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
363
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
364
|
+
}
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
/**
|
|
@@ -374,9 +374,9 @@ export class BlindTilt extends deviceBase {
|
|
|
374
374
|
// CurrentPosition
|
|
375
375
|
await this.getCurrentPosttionDirection(this.deviceStatus.direction, this.deviceStatus.slidePosition)
|
|
376
376
|
|
|
377
|
-
if (!this.device.
|
|
378
|
-
const set_minLux = this.device.
|
|
379
|
-
const set_maxLux = this.device.
|
|
377
|
+
if (!(this.device as blindTiltConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
378
|
+
const set_minLux = (this.device as blindTiltConfig).set_minLux ?? 1
|
|
379
|
+
const set_maxLux = (this.device as blindTiltConfig).set_maxLux ?? 6001
|
|
380
380
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
381
381
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
382
382
|
await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
@@ -457,22 +457,22 @@ export class BlindTilt extends deviceBase {
|
|
|
457
457
|
|
|
458
458
|
async BLERefreshStatus(): Promise<void> {
|
|
459
459
|
await this.debugLog('BLERefreshStatus')
|
|
460
|
-
const
|
|
461
|
-
if (
|
|
462
|
-
await this.BLERefreshConnection(
|
|
460
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
461
|
+
if (switchBotBLE === undefined) {
|
|
462
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
463
463
|
} else {
|
|
464
464
|
// Start to monitor advertisement packets
|
|
465
465
|
(async () => {
|
|
466
466
|
// Start to monitor advertisement packets
|
|
467
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
467
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as blindTiltServiceData
|
|
468
468
|
// Update HomeKit
|
|
469
469
|
if (serviceData.model === SwitchBotBLEModel.BlindTilt && serviceData.modelName === SwitchBotBLEModelName.BlindTilt) {
|
|
470
470
|
this.serviceData = serviceData
|
|
471
471
|
await this.BLEparseStatus()
|
|
472
472
|
await this.updateHomeKitCharacteristics()
|
|
473
473
|
} else {
|
|
474
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
475
|
-
await this.BLERefreshConnection(
|
|
474
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
475
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
476
476
|
}
|
|
477
477
|
})()
|
|
478
478
|
}
|
|
@@ -493,7 +493,7 @@ export class BlindTilt extends deviceBase {
|
|
|
493
493
|
await this.BLEparseStatus()
|
|
494
494
|
await this.updateHomeKitCharacteristics()
|
|
495
495
|
} catch (e: any) {
|
|
496
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
496
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
} catch (error) {
|
|
@@ -507,17 +507,17 @@ export class BlindTilt extends deviceBase {
|
|
|
507
507
|
async openAPIRefreshStatus(): Promise<void> {
|
|
508
508
|
await this.debugLog('openAPIRefreshStatus')
|
|
509
509
|
try {
|
|
510
|
-
const { body
|
|
511
|
-
const deviceStatus: any = await body
|
|
512
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
|
-
if (await this.successfulStatusCodes(
|
|
514
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
510
|
+
const { body } = await this.deviceRefreshStatus()
|
|
511
|
+
const deviceStatus: any = await body
|
|
512
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
514
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
515
515
|
this.deviceStatus = deviceStatus.body
|
|
516
516
|
await this.openAPIparseStatus()
|
|
517
517
|
await this.updateHomeKitCharacteristics()
|
|
518
518
|
} else {
|
|
519
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
520
|
-
await this.debugWarnLog(
|
|
519
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
520
|
+
await this.debugWarnLog(deviceStatus)
|
|
521
521
|
}
|
|
522
522
|
} catch (e: any) {
|
|
523
523
|
await this.apiError(e)
|
|
@@ -535,7 +535,7 @@ export class BlindTilt extends deviceBase {
|
|
|
535
535
|
await this.parseStatusWebhook()
|
|
536
536
|
await this.updateHomeKitCharacteristics()
|
|
537
537
|
} catch (e: any) {
|
|
538
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
538
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
} else {
|
|
@@ -567,21 +567,22 @@ export class BlindTilt extends deviceBase {
|
|
|
567
567
|
await this.debugLog('BLEpushChanges')
|
|
568
568
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
569
569
|
await this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`)
|
|
570
|
-
const
|
|
570
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
571
571
|
try {
|
|
572
572
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
573
573
|
this.device.bleMac = formattedDeviceId
|
|
574
574
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
575
575
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
576
576
|
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
577
|
-
if (
|
|
578
|
-
|
|
577
|
+
if (switchBotBLE !== false) {
|
|
578
|
+
switchBotBLE
|
|
579
579
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
580
|
-
.then(async (device_list:
|
|
580
|
+
.then(async (device_list: SwitchbotDevice[]) => {
|
|
581
|
+
const deviceList = device_list as unknown as WoBlindTilt[]
|
|
581
582
|
return await this.retryBLE({
|
|
582
583
|
max: await this.maxRetryBLE(),
|
|
583
584
|
fn: async () => {
|
|
584
|
-
return await
|
|
585
|
+
return await deviceList[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode)
|
|
585
586
|
},
|
|
586
587
|
})
|
|
587
588
|
})
|
|
@@ -595,7 +596,7 @@ export class BlindTilt extends deviceBase {
|
|
|
595
596
|
await this.BLEPushConnection()
|
|
596
597
|
})
|
|
597
598
|
} else {
|
|
598
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
599
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
599
600
|
await this.BLEPushConnection()
|
|
600
601
|
}
|
|
601
602
|
} catch (error) {
|
|
@@ -617,36 +618,35 @@ export class BlindTilt extends deviceBase {
|
|
|
617
618
|
const { Mode, setPositionMode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
618
619
|
await this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`)
|
|
619
620
|
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
620
|
-
let bodyChange:
|
|
621
|
+
let bodyChange: bodyChange
|
|
621
622
|
if (position === 100) {
|
|
622
|
-
bodyChange =
|
|
623
|
+
bodyChange = {
|
|
623
624
|
command: 'fullyOpen',
|
|
624
625
|
parameter: 'default',
|
|
625
626
|
commandType: 'command',
|
|
626
|
-
}
|
|
627
|
+
}
|
|
627
628
|
} else if (position === 0) {
|
|
628
|
-
bodyChange =
|
|
629
|
+
bodyChange = {
|
|
629
630
|
command: direction === 'up' ? 'closeUp' : 'closeDown',
|
|
630
631
|
parameter: 'default',
|
|
631
632
|
commandType: 'command',
|
|
632
|
-
}
|
|
633
|
+
}
|
|
633
634
|
} else {
|
|
634
|
-
bodyChange =
|
|
635
|
+
bodyChange = {
|
|
635
636
|
command: 'setPosition',
|
|
636
637
|
parameter: `${direction};${position}`,
|
|
637
638
|
commandType: 'command',
|
|
638
|
-
}
|
|
639
|
+
}
|
|
639
640
|
}
|
|
640
641
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
641
642
|
try {
|
|
642
|
-
const { body
|
|
643
|
-
const deviceStatus: any = await body
|
|
644
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
645
|
-
if (await this.successfulStatusCodes(
|
|
646
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
643
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
644
|
+
const deviceStatus: any = await body
|
|
645
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
646
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
647
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
647
648
|
await this.updateHomeKitCharacteristics()
|
|
648
649
|
} else {
|
|
649
|
-
await this.statusCode(statusCode)
|
|
650
650
|
await this.statusCode(deviceStatus.statusCode)
|
|
651
651
|
}
|
|
652
652
|
} catch (e: any) {
|
|
@@ -729,7 +729,7 @@ export class BlindTilt extends deviceBase {
|
|
|
729
729
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
730
730
|
*/
|
|
731
731
|
async OpenModeSwitchSet(value: CharacteristicValue): Promise<void> {
|
|
732
|
-
if (this.OpenModeSwitch && this.device.
|
|
732
|
+
if (this.OpenModeSwitch && (this.device as blindTiltConfig).silentModeSwitch) {
|
|
733
733
|
this.debugLog(`Silent Open Mode: ${value}`)
|
|
734
734
|
this.OpenModeSwitch.On = value
|
|
735
735
|
this.accessory.context.OpenModeSwitch.On = value
|
|
@@ -741,7 +741,7 @@ export class BlindTilt extends deviceBase {
|
|
|
741
741
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
742
742
|
*/
|
|
743
743
|
async CloseModeSwitchSet(value: CharacteristicValue): Promise<void> {
|
|
744
|
-
if (this.CloseModeSwitch && this.device.
|
|
744
|
+
if (this.CloseModeSwitch && (this.device as blindTiltConfig).silentModeSwitch) {
|
|
745
745
|
this.debugLog(`Silent Close Mode: ${value}`)
|
|
746
746
|
this.CloseModeSwitch.On = value
|
|
747
747
|
this.accessory.context.CloseModeSwitch.On = value
|
|
@@ -762,7 +762,7 @@ export class BlindTilt extends deviceBase {
|
|
|
762
762
|
// TargetPosition
|
|
763
763
|
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition, this.WindowCovering.TargetPosition, 'TargetPosition')
|
|
764
764
|
// CurrentAmbientLightLevel
|
|
765
|
-
if (!this.device.
|
|
765
|
+
if (!(this.device as blindTiltConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
766
766
|
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel }
|
|
767
767
|
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history)
|
|
768
768
|
}
|
|
@@ -793,10 +793,10 @@ export class BlindTilt extends deviceBase {
|
|
|
793
793
|
let setPositionMode: number
|
|
794
794
|
let Mode: string
|
|
795
795
|
if (Number(this.WindowCovering.TargetPosition) > 50) {
|
|
796
|
-
if (this.device.
|
|
796
|
+
if ((this.device as blindTiltConfig).setOpenMode === '1' || this.OpenModeSwitch?.On) {
|
|
797
797
|
setPositionMode = 1
|
|
798
798
|
Mode = 'Silent Mode'
|
|
799
|
-
} else if (this.device.
|
|
799
|
+
} else if ((this.device as blindTiltConfig).setOpenMode === '0' || !this.OpenModeSwitch?.On) {
|
|
800
800
|
setPositionMode = 0
|
|
801
801
|
Mode = 'Performance Mode'
|
|
802
802
|
} else {
|
|
@@ -804,10 +804,10 @@ export class BlindTilt extends deviceBase {
|
|
|
804
804
|
Mode = 'Default Mode'
|
|
805
805
|
}
|
|
806
806
|
} else {
|
|
807
|
-
if (this.device.
|
|
807
|
+
if ((this.device as blindTiltConfig).setCloseMode === '1' || this.CloseModeSwitch?.On) {
|
|
808
808
|
setPositionMode = 1
|
|
809
809
|
Mode = 'Silent Mode'
|
|
810
|
-
} else if (this.device.
|
|
810
|
+
} else if ((this.device as blindTiltConfig).setOpenMode === '0' || !this.CloseModeSwitch?.On) {
|
|
811
811
|
setPositionMode = 0
|
|
812
812
|
Mode = 'Performance Mode'
|
|
813
813
|
} else {
|
|
@@ -819,13 +819,13 @@ export class BlindTilt extends deviceBase {
|
|
|
819
819
|
}
|
|
820
820
|
|
|
821
821
|
async setMinMax(): Promise<void> {
|
|
822
|
-
if (this.device.
|
|
823
|
-
if (Number(this.WindowCovering.CurrentPosition) <= this.device.
|
|
822
|
+
if ((this.device as blindTiltConfig).set_min) {
|
|
823
|
+
if (Number(this.WindowCovering.CurrentPosition) <= (this.device as blindTiltConfig).set_min!) {
|
|
824
824
|
this.WindowCovering.CurrentPosition = 0
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
|
-
if (this.device.
|
|
828
|
-
if (Number(this.WindowCovering.CurrentPosition) >= this.device.
|
|
827
|
+
if ((this.device as blindTiltConfig).set_max) {
|
|
828
|
+
if (Number(this.WindowCovering.CurrentPosition) >= (this.device as blindTiltConfig).set_max!) {
|
|
829
829
|
this.WindowCovering.CurrentPosition = 100
|
|
830
830
|
}
|
|
831
831
|
}
|
|
@@ -859,7 +859,7 @@ export class BlindTilt extends deviceBase {
|
|
|
859
859
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
860
860
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
861
861
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e)
|
|
862
|
-
if (!this.device.
|
|
862
|
+
if (!(this.device as blindTiltConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
863
863
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
864
864
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
|
|
865
865
|
}
|