@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.60
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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +23 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +408 -779
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +26 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +696 -822
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -68
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +237 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +14 -75
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +279 -658
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +242 -544
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -88
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +402 -805
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +684 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +535 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +16 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +246 -613
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +232 -593
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +185 -600
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +11 -69
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +277 -586
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +16 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +241 -560
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +14 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +181 -593
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +14 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +170 -593
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +178 -531
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +92 -458
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +197 -521
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +10 -65
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +139 -495
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -49
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +100 -338
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +330 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +87 -357
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +19 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +310 -169
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +62 -19
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +19 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +442 -814
- package/src/device/bot.ts +754 -915
- package/src/device/ceilinglight.ts +255 -633
- package/src/device/colorbulb.ts +294 -685
- package/src/device/contact.ts +277 -571
- package/src/device/curtain.ts +431 -835
- package/src/device/device.ts +709 -0
- package/src/device/fan.ts +591 -0
- package/src/device/hub.ts +286 -644
- package/src/device/humidifier.ts +266 -646
- package/src/device/iosensor.ts +220 -625
- package/src/device/lightstrip.ts +305 -620
- package/src/device/lock.ts +280 -600
- package/src/device/meter.ts +216 -617
- package/src/device/meterplus.ts +205 -619
- package/src/device/motion.ts +206 -556
- package/src/device/plug.ts +107 -490
- package/src/device/robotvacuumcleaner.ts +223 -550
- package/src/device/waterdetector.ts +160 -519
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +333 -447
- package/src/irdevice/airpurifier.ts +92 -322
- package/src/irdevice/camera.ts +45 -294
- package/src/irdevice/fan.ts +115 -353
- package/src/irdevice/irdevice.ts +346 -0
- package/src/irdevice/light.ts +110 -385
- package/src/irdevice/other.ts +399 -616
- package/src/irdevice/tv.ts +103 -340
- package/src/irdevice/vacuumcleaner.ts +52 -306
- package/src/irdevice/waterheater.ts +53 -311
- package/src/platform.ts +355 -216
- package/src/settings.ts +116 -611
- package/src/utils.ts +642 -1
- package/src/device/waterdetector.json +0 -11
package/dist/device/blindtilt.js
CHANGED
|
@@ -1,149 +1,75 @@
|
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* blindtilt.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
1
5
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
6
|
+
import { Devices } from '../settings.js';
|
|
3
7
|
import { interval, Subject } from 'rxjs';
|
|
4
|
-
import
|
|
8
|
+
import { deviceBase } from './device.js';
|
|
9
|
+
import { BlindTiltMappingMode } from '../utils.js';
|
|
5
10
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
var BlindTiltMappingMode;
|
|
8
|
-
(function (BlindTiltMappingMode) {
|
|
9
|
-
BlindTiltMappingMode["OnlyUp"] = "only_up";
|
|
10
|
-
BlindTiltMappingMode["OnlyDown"] = "only_down";
|
|
11
|
-
BlindTiltMappingMode["DownAndUp"] = "down_and_up";
|
|
12
|
-
BlindTiltMappingMode["UpAndDown"] = "up_and_down";
|
|
13
|
-
BlindTiltMappingMode["UseTiltForDirection"] = "use_tilt_for_direction";
|
|
14
|
-
})(BlindTiltMappingMode || (BlindTiltMappingMode = {}));
|
|
15
|
-
export class BlindTilt {
|
|
11
|
+
export class BlindTilt extends deviceBase {
|
|
16
12
|
platform;
|
|
17
|
-
accessory;
|
|
18
|
-
device;
|
|
19
|
-
api;
|
|
20
|
-
log;
|
|
21
|
-
config;
|
|
22
|
-
hap;
|
|
23
13
|
// Services
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Characteristic Values
|
|
28
|
-
BatteryLevel;
|
|
29
|
-
PositionState;
|
|
30
|
-
TargetPosition;
|
|
31
|
-
CurrentPosition;
|
|
32
|
-
StatusLowBattery;
|
|
33
|
-
FirmwareRevision;
|
|
34
|
-
CurrentAmbientLightLevel;
|
|
35
|
-
TargetHorizontalTiltAngle;
|
|
36
|
-
CurrentHorizontalTiltAngle;
|
|
37
|
-
// OpenAPI Status
|
|
38
|
-
OpenAPI_InMotion;
|
|
39
|
-
OpenAPI_BatteryLevel;
|
|
40
|
-
OpenAPI_Direction;
|
|
41
|
-
OpenAPI_Calibration;
|
|
42
|
-
OpenAPI_CurrentPosition;
|
|
43
|
-
OpenAPI_FirmwareRevision;
|
|
44
|
-
OpenAPI_CurrentAmbientLightLevel;
|
|
14
|
+
WindowCovering;
|
|
15
|
+
Battery;
|
|
16
|
+
LightSensor;
|
|
45
17
|
// OpenAPI Others
|
|
46
|
-
Mode;
|
|
47
|
-
setPositionMode;
|
|
48
18
|
mappingMode = BlindTiltMappingMode.OnlyUp;
|
|
49
|
-
// BLE Status
|
|
50
|
-
BLE_InMotion;
|
|
51
|
-
BLE_BatteryLevel;
|
|
52
|
-
BLE_Calibration;
|
|
53
|
-
BLE_CurrentPosition;
|
|
54
|
-
BLE_CurrentAmbientLightLevel;
|
|
55
|
-
// BLE Others
|
|
56
|
-
BLE_IsConnected;
|
|
57
|
-
spaceBetweenLevels;
|
|
58
19
|
// Target
|
|
59
20
|
setNewTarget;
|
|
60
21
|
setNewTargetTimer;
|
|
61
|
-
//MQTT stuff
|
|
62
|
-
mqttClient = null;
|
|
63
|
-
// Config
|
|
64
|
-
set_minStep;
|
|
65
|
-
updateRate;
|
|
66
|
-
set_minLux;
|
|
67
|
-
set_maxLux;
|
|
68
|
-
scanDuration;
|
|
69
|
-
deviceLogging;
|
|
70
|
-
deviceRefreshRate;
|
|
71
|
-
setCloseMode;
|
|
72
|
-
setOpenMode;
|
|
73
22
|
// Updates
|
|
74
23
|
blindTiltUpdateInProgress;
|
|
75
24
|
doBlindTiltUpdate;
|
|
76
|
-
// Connection
|
|
77
|
-
OpenAPI;
|
|
78
|
-
BLE;
|
|
79
25
|
constructor(platform, accessory, device) {
|
|
26
|
+
super(platform, accessory, device);
|
|
80
27
|
this.platform = platform;
|
|
81
|
-
this.accessory = accessory;
|
|
82
|
-
this.device = device;
|
|
83
|
-
this.api = this.platform.api;
|
|
84
|
-
this.log = this.platform.log;
|
|
85
|
-
this.config = this.platform.config;
|
|
86
|
-
this.hap = this.api.hap;
|
|
87
|
-
// Connection
|
|
88
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
89
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
90
28
|
// default placeholders
|
|
91
|
-
this.deviceLogs(device);
|
|
92
|
-
this.refreshRate(device);
|
|
93
|
-
this.scan(device);
|
|
94
|
-
this.setupMqtt(device);
|
|
95
|
-
this.deviceContext();
|
|
96
|
-
this.deviceConfig(device);
|
|
97
29
|
this.mappingMode = device.blindTilt?.mode ?? BlindTiltMappingMode.OnlyUp;
|
|
98
30
|
this.debugLog(`Mapping mode: ${this.mappingMode}`);
|
|
99
31
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
100
32
|
this.doBlindTiltUpdate = new Subject();
|
|
101
33
|
this.blindTiltUpdateInProgress = false;
|
|
102
34
|
this.setNewTarget = false;
|
|
103
|
-
//
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
.
|
|
109
|
-
.
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|| accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
|
|
118
|
-
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
119
|
-
if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
120
|
-
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
121
|
-
}
|
|
122
|
-
// create handlers for required characteristics
|
|
123
|
-
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
|
|
124
|
-
this.windowCoveringService
|
|
125
|
-
.getCharacteristic(this.hap.Characteristic.CurrentPosition)
|
|
35
|
+
// Initialize WindowCovering Service
|
|
36
|
+
this.WindowCovering = {
|
|
37
|
+
Name: accessory.context.WindowCoveringName ?? accessory.displayName,
|
|
38
|
+
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering),
|
|
39
|
+
PositionState: accessory.context.PositionState ?? this.hap.Characteristic.PositionState.STOPPED,
|
|
40
|
+
TargetPosition: accessory.context.TargetPosition ?? 100,
|
|
41
|
+
CurrentPosition: accessory.context.CurrentPosition ?? 100,
|
|
42
|
+
TargetHorizontalTiltAngle: accessory.context.TargetHorizontalTiltAngle ?? 90,
|
|
43
|
+
CurrentHorizontalTiltAngle: accessory.context.CurrentHorizontalTiltAngle ?? 90,
|
|
44
|
+
};
|
|
45
|
+
// Initialize WindowCovering Characteristics
|
|
46
|
+
this.WindowCovering.Service
|
|
47
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
|
|
48
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
126
49
|
.setProps({
|
|
127
|
-
minStep: this.minStep(device),
|
|
50
|
+
minStep: Number(this.minStep(device)),
|
|
128
51
|
minValue: 0,
|
|
129
52
|
maxValue: 100,
|
|
130
53
|
validValueRanges: [0, 100],
|
|
131
54
|
})
|
|
132
55
|
.onGet(() => {
|
|
133
|
-
return this.
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
|
|
56
|
+
return this.WindowCovering.TargetPosition;
|
|
57
|
+
})
|
|
58
|
+
.onSet(this.TargetPositionSet.bind(this));
|
|
59
|
+
// Initialize WindowCovering CurrentPosition Characteristic
|
|
60
|
+
this.WindowCovering.Service
|
|
61
|
+
.getCharacteristic(this.hap.Characteristic.CurrentPosition)
|
|
137
62
|
.setProps({
|
|
138
|
-
minStep: this.minStep(device),
|
|
63
|
+
minStep: Number(this.minStep(device)),
|
|
139
64
|
minValue: 0,
|
|
140
65
|
maxValue: 100,
|
|
141
66
|
validValueRanges: [0, 100],
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
67
|
+
}).onGet(() => {
|
|
68
|
+
return this.WindowCovering?.CurrentPosition ?? 0;
|
|
69
|
+
});
|
|
70
|
+
// Initialize WindowCovering TargetHorizontalTiltAngle Characteristic
|
|
71
|
+
this.WindowCovering.Service
|
|
72
|
+
.getCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle)
|
|
147
73
|
.setProps({
|
|
148
74
|
minStep: 180,
|
|
149
75
|
minValue: -90,
|
|
@@ -151,27 +77,58 @@ export class BlindTilt {
|
|
|
151
77
|
validValues: [-90, 90],
|
|
152
78
|
})
|
|
153
79
|
.onGet(() => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
80
|
+
return this.WindowCovering.TargetHorizontalTiltAngle;
|
|
81
|
+
})
|
|
82
|
+
.onSet(this.TargetHorizontalTiltAngleSet.bind(this));
|
|
83
|
+
accessory.context.WindowCoveringName = this.WindowCovering.Name;
|
|
84
|
+
// Initialize WindowCovering CurrentHorizontalTiltAngle Characteristic
|
|
85
|
+
this.WindowCovering.Service
|
|
86
|
+
.getCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle)
|
|
160
87
|
.setProps({
|
|
161
88
|
minStep: 180,
|
|
162
89
|
minValue: -90,
|
|
163
90
|
maxValue: 90,
|
|
164
91
|
validValues: [-90, 90],
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
92
|
+
}).onGet(() => {
|
|
93
|
+
return this.WindowCovering.CurrentHorizontalTiltAngle ?? 0;
|
|
94
|
+
});
|
|
95
|
+
// Initialize Battery Service
|
|
96
|
+
this.Battery = {
|
|
97
|
+
Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
|
|
98
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
|
|
99
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
100
|
+
StatusLowBattery: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
101
|
+
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
|
|
102
|
+
};
|
|
103
|
+
// Initialize Battery Name Characteristic
|
|
104
|
+
this.Battery.Service
|
|
105
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
106
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
107
|
+
accessory.context.BatteryName = this.Battery.Name;
|
|
108
|
+
// Initialize LightSensor Service
|
|
109
|
+
if (device.blindTilt?.hide_lightsensor) {
|
|
110
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
111
|
+
this.LightSensor.Service = accessory.getService(this.hap.Service.LightSensor);
|
|
112
|
+
accessory.removeService(this.LightSensor.Service);
|
|
174
113
|
}
|
|
114
|
+
else {
|
|
115
|
+
this.LightSensor = {
|
|
116
|
+
Name: accessory.context.LightSensorName ?? `${accessory.displayName} Light Sensor`,
|
|
117
|
+
Service: accessory.getService(this.hap.Service.LightSensor) ?? accessory.addService(this.hap.Service.LightSensor),
|
|
118
|
+
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
|
|
119
|
+
};
|
|
120
|
+
// Initialize LightSensor Characteristics
|
|
121
|
+
this.LightSensor.Service
|
|
122
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name)
|
|
123
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
124
|
+
.getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel)
|
|
125
|
+
.onGet(() => {
|
|
126
|
+
return this.LightSensor?.CurrentAmbientLightLevel ?? 0.0001;
|
|
127
|
+
});
|
|
128
|
+
accessory.context.LightSensorName = this.LightSensor.Name;
|
|
129
|
+
}
|
|
130
|
+
// Retrieve initial values and updateHomekit
|
|
131
|
+
this.refreshStatus();
|
|
175
132
|
// Update Homekit
|
|
176
133
|
this.updateHomeKitCharacteristics();
|
|
177
134
|
// Start an update interval
|
|
@@ -181,21 +138,23 @@ export class BlindTilt {
|
|
|
181
138
|
await this.refreshStatus();
|
|
182
139
|
});
|
|
183
140
|
//regisiter webhook event handler
|
|
184
|
-
if (
|
|
185
|
-
this.
|
|
141
|
+
if (device.webhook) {
|
|
142
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
|
|
186
143
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
187
144
|
try {
|
|
188
|
-
this.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
145
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
146
|
+
const { slidePosition, battery, lightLevel } = context;
|
|
147
|
+
const { CurrentPosition } = this.WindowCovering;
|
|
148
|
+
const { BatteryLevel } = this.Battery;
|
|
149
|
+
const { CurrentAmbientLightLevel } = this.LightSensor ?? {};
|
|
150
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} (slidePosition, battery, lightLevel) = `
|
|
151
|
+
+ `Webhook:(${slidePosition}, ${battery}, ${lightLevel}), current:(${CurrentPosition}, ${BatteryLevel}, ${CurrentAmbientLightLevel})`);
|
|
152
|
+
this.WindowCovering.CurrentPosition = slidePosition;
|
|
153
|
+
this.Battery.BatteryLevel = battery;
|
|
154
|
+
if (!device.blindTilt?.hide_lightsensor) {
|
|
155
|
+
this.LightSensor.CurrentAmbientLightLevel = lightLevel;
|
|
156
|
+
}
|
|
157
|
+
this.updateHomeKitCharacteristics();
|
|
199
158
|
}
|
|
200
159
|
catch (e) {
|
|
201
160
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -204,13 +163,14 @@ export class BlindTilt {
|
|
|
204
163
|
};
|
|
205
164
|
}
|
|
206
165
|
// update slide progress
|
|
207
|
-
interval(this.
|
|
166
|
+
interval(this.deviceUpdateRate * 1000)
|
|
208
167
|
//.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
209
168
|
.subscribe(async () => {
|
|
210
|
-
if (this.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
169
|
+
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
211
170
|
return;
|
|
212
171
|
}
|
|
213
|
-
this.debugLog(`${
|
|
172
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} Refresh Status When Moving,`
|
|
173
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
214
174
|
await this.refreshStatus();
|
|
215
175
|
});
|
|
216
176
|
// Watch for BlindTilt change events
|
|
@@ -225,206 +185,218 @@ export class BlindTilt {
|
|
|
225
185
|
}
|
|
226
186
|
catch (e) {
|
|
227
187
|
this.apiError(e);
|
|
228
|
-
this.errorLog(`${
|
|
188
|
+
this.errorLog(`${device.deviceType}: ${accessory.displayName} failed pushChanges with ${device.connectionType} Connection,` +
|
|
229
189
|
` Error Message: ${JSON.stringify(e.message)}`);
|
|
230
190
|
}
|
|
231
191
|
this.blindTiltUpdateInProgress = false;
|
|
232
192
|
});
|
|
233
193
|
}
|
|
234
194
|
/**
|
|
235
|
-
* Parse the device status from the
|
|
195
|
+
* Parse the device status from the SwitchBotBLE API
|
|
236
196
|
*/
|
|
237
|
-
async
|
|
238
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
239
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
240
|
-
}
|
|
241
|
-
else if (this.BLE) {
|
|
242
|
-
await this.BLEparseStatus();
|
|
243
|
-
}
|
|
244
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
245
|
-
await this.openAPIparseStatus();
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
await this.offlineOff();
|
|
249
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
async BLEparseStatus() {
|
|
197
|
+
async BLEparseStatus(serviceData) {
|
|
253
198
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
254
199
|
// CurrentPosition
|
|
255
|
-
this.CurrentPosition = 100 - Number(
|
|
200
|
+
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.position);
|
|
256
201
|
await this.setMinMax();
|
|
257
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
202
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
258
203
|
if (this.setNewTarget) {
|
|
259
204
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
260
205
|
}
|
|
261
|
-
if (this.setNewTarget &&
|
|
206
|
+
if (this.setNewTarget && serviceData.inMotion) {
|
|
262
207
|
await this.setMinMax();
|
|
263
|
-
if (Number(this.TargetPosition) > this.CurrentPosition) {
|
|
264
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
265
|
-
this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
266
|
-
this.
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING
|
|
208
|
+
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
210
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
211
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
212
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} INCREASING`
|
|
213
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
268
214
|
}
|
|
269
|
-
else if (Number(this.TargetPosition) < this.CurrentPosition) {
|
|
270
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
271
|
-
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
272
|
-
this.
|
|
273
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING
|
|
215
|
+
else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
217
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
218
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
219
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} DECREASING`
|
|
220
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
274
221
|
}
|
|
275
222
|
else {
|
|
276
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby2
|
|
277
|
-
|
|
278
|
-
this.
|
|
279
|
-
this.
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} Standby2,`
|
|
224
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
225
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
226
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
227
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} STOPPED`
|
|
228
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
280
229
|
}
|
|
281
230
|
}
|
|
282
231
|
else {
|
|
283
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
284
|
-
this.TargetPosition = this.CurrentPosition;
|
|
285
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
233
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
234
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
286
235
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
287
236
|
}
|
|
288
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
|
|
289
|
-
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
237
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},`
|
|
238
|
+
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
|
|
290
239
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
240
|
+
const set_minLux = await this.minLux();
|
|
241
|
+
const set_maxLux = await this.maxLux();
|
|
242
|
+
const spaceBetweenLevels = 9;
|
|
243
|
+
if (this.LightSensor?.CurrentAmbientLightLevel === 0) {
|
|
244
|
+
this.LightSensor.CurrentAmbientLightLevel = 0.0001;
|
|
245
|
+
}
|
|
294
246
|
// Brightness
|
|
295
|
-
switch (
|
|
247
|
+
switch (serviceData.lightLevel) {
|
|
296
248
|
case 1:
|
|
297
|
-
this.CurrentAmbientLightLevel =
|
|
298
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
249
|
+
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
299
251
|
break;
|
|
300
252
|
case 2:
|
|
301
|
-
this.CurrentAmbientLightLevel = (
|
|
302
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
303
|
-
` Calculation: ${(
|
|
253
|
+
this.LightSensor.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},` +
|
|
255
|
+
` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
304
256
|
break;
|
|
305
257
|
case 3:
|
|
306
|
-
this.CurrentAmbientLightLevel = ((
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
258
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
308
260
|
break;
|
|
309
261
|
case 4:
|
|
310
|
-
this.CurrentAmbientLightLevel = ((
|
|
311
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
262
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
312
264
|
break;
|
|
313
265
|
case 5:
|
|
314
|
-
this.CurrentAmbientLightLevel = ((
|
|
315
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
266
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
316
268
|
break;
|
|
317
269
|
case 6:
|
|
318
|
-
this.CurrentAmbientLightLevel = ((
|
|
319
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
270
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
320
272
|
break;
|
|
321
273
|
case 7:
|
|
322
|
-
this.CurrentAmbientLightLevel = ((
|
|
323
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
274
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
324
276
|
break;
|
|
325
277
|
case 8:
|
|
326
|
-
this.CurrentAmbientLightLevel = ((
|
|
327
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
278
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
279
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
328
280
|
break;
|
|
329
281
|
case 9:
|
|
330
|
-
this.CurrentAmbientLightLevel = ((
|
|
331
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
282
|
+
this.LightSensor.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
283
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
332
284
|
break;
|
|
333
285
|
case 10:
|
|
334
286
|
default:
|
|
335
|
-
this.CurrentAmbientLightLevel =
|
|
287
|
+
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
336
288
|
this.debugLog();
|
|
337
289
|
}
|
|
338
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
339
|
-
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
290
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},` +
|
|
291
|
+
` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
340
292
|
}
|
|
341
293
|
// Battery
|
|
342
|
-
this.BatteryLevel = Number(
|
|
343
|
-
if (this.BatteryLevel < 10) {
|
|
344
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
294
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
295
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
296
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
345
297
|
}
|
|
346
298
|
else {
|
|
347
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
299
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
348
300
|
}
|
|
349
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
301
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
302
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
350
303
|
}
|
|
351
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Parse the device status from the SwitchBot OpenAPI
|
|
306
|
+
*/
|
|
307
|
+
async openAPIparseStatus(deviceStatus) {
|
|
352
308
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
353
|
-
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(
|
|
354
|
-
this.debugLog(` device: ${
|
|
355
|
-
this.CurrentPosition = homekitPosition;
|
|
309
|
+
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(deviceStatus.body.slidePosition), String(deviceStatus.body.direction));
|
|
310
|
+
this.debugLog(` device: ${deviceStatus.body.slidePosition} => HK: ${homekitPosition}`);
|
|
311
|
+
this.WindowCovering.CurrentPosition = homekitPosition;
|
|
356
312
|
// CurrentPosition
|
|
357
313
|
await this.setMinMax();
|
|
358
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
314
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
359
315
|
if (homekitTiltAngle) {
|
|
360
|
-
this.CurrentHorizontalTiltAngle = homekitTiltAngle;
|
|
361
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
316
|
+
this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle;
|
|
317
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
318
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
362
319
|
}
|
|
363
320
|
if (this.setNewTarget) {
|
|
364
321
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
365
322
|
}
|
|
366
|
-
if (this.setNewTarget &&
|
|
323
|
+
if (this.setNewTarget && deviceStatus.body.moving) {
|
|
367
324
|
await this.setMinMax();
|
|
368
|
-
if (this.TargetPosition > this.CurrentPosition
|
|
369
|
-
|
|
370
|
-
this.
|
|
371
|
-
this.
|
|
372
|
-
this.
|
|
325
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
326
|
+
|| (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition} `);
|
|
328
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
329
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
330
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} INCREASING`
|
|
331
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
373
332
|
}
|
|
374
|
-
else if (this.TargetPosition < this.CurrentPosition) {
|
|
375
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
376
|
-
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
377
|
-
this.
|
|
378
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING
|
|
333
|
+
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
334
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition} `);
|
|
335
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
336
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
337
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} DECREASING`
|
|
338
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
379
339
|
}
|
|
380
340
|
else {
|
|
381
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby because reached position,`
|
|
382
|
-
|
|
383
|
-
this.
|
|
384
|
-
this.
|
|
341
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} Standby because reached position,`
|
|
342
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
343
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
344
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
345
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} STOPPED`
|
|
346
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
385
347
|
}
|
|
386
348
|
}
|
|
387
349
|
else {
|
|
388
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby because device not moving,`
|
|
389
|
-
|
|
350
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby because device not moving,`
|
|
351
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
352
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
390
353
|
if (homekitTiltAngle) {
|
|
391
|
-
this.TargetHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
354
|
+
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
392
355
|
}
|
|
393
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
356
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
394
357
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
395
358
|
}
|
|
396
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
397
|
-
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
|
|
359
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},` +
|
|
360
|
+
` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
|
|
398
361
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
399
|
-
|
|
400
|
-
|
|
362
|
+
const set_minLux = await this.minLux();
|
|
363
|
+
const set_maxLux = await this.maxLux();
|
|
401
364
|
// Brightness
|
|
402
|
-
switch (
|
|
365
|
+
switch (deviceStatus.body.brightness) {
|
|
403
366
|
case 'dim':
|
|
404
|
-
this.CurrentAmbientLightLevel =
|
|
367
|
+
this.LightSensor.CurrentAmbientLightLevel = set_minLux;
|
|
405
368
|
break;
|
|
406
369
|
case 'bright':
|
|
407
370
|
default:
|
|
408
|
-
this.CurrentAmbientLightLevel =
|
|
371
|
+
this.LightSensor.CurrentAmbientLightLevel = set_maxLux;
|
|
409
372
|
}
|
|
410
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
373
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
374
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
411
375
|
}
|
|
412
376
|
// BatteryLevel
|
|
413
|
-
this.BatteryLevel = Number(
|
|
414
|
-
if (this.BatteryLevel < 10) {
|
|
415
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
377
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
378
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
379
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
416
380
|
}
|
|
417
381
|
else {
|
|
418
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
382
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
383
|
+
}
|
|
384
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
385
|
+
this.Battery.BatteryLevel = 100;
|
|
386
|
+
}
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
388
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
389
|
+
// Firmware Version
|
|
390
|
+
const version = deviceStatus.body.version?.toString();
|
|
391
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
392
|
+
if (deviceStatus.body.version) {
|
|
393
|
+
this.accessory.context.version = version?.replace(/^V|-.*$/g, '');
|
|
394
|
+
this.accessory
|
|
395
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
396
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
397
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
398
|
+
.updateValue(this.accessory.context.version);
|
|
419
399
|
}
|
|
420
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
421
|
-
this.BatteryLevel = 100;
|
|
422
|
-
}
|
|
423
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
424
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
425
|
-
// FirmwareRevision
|
|
426
|
-
this.FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
427
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
428
400
|
}
|
|
429
401
|
async refreshStatus() {
|
|
430
402
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
@@ -455,21 +427,13 @@ export class BlindTilt {
|
|
|
455
427
|
// Start to monitor advertisement packets
|
|
456
428
|
(async () => {
|
|
457
429
|
// Start to monitor advertisement packets
|
|
458
|
-
await switchbot.startScan({
|
|
459
|
-
model: 'x',
|
|
460
|
-
id: this.device.bleMac,
|
|
461
|
-
});
|
|
430
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
462
431
|
// Set an event handler
|
|
463
432
|
switchbot.onadvertisement = (ad) => {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
433
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
434
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
467
436
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
468
|
-
this.BLE_Calibration = ad.serviceData.calibration;
|
|
469
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
470
|
-
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
471
|
-
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
472
|
-
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
473
437
|
}
|
|
474
438
|
else {
|
|
475
439
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
@@ -480,82 +444,25 @@ export class BlindTilt {
|
|
|
480
444
|
// Stop to monitor
|
|
481
445
|
await switchbot.stopScan();
|
|
482
446
|
// Update HomeKit
|
|
483
|
-
await this.BLEparseStatus();
|
|
447
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
484
448
|
await this.updateHomeKitCharacteristics();
|
|
485
449
|
})();
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
model: 'c',
|
|
490
|
-
id: this.device.bleMac,
|
|
491
|
-
})
|
|
492
|
-
.then(async () => {
|
|
493
|
-
// Set an event handler
|
|
494
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
495
|
-
this.debugLog(
|
|
496
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
497
|
-
` BLE Address Found: ${ad.address}`,
|
|
498
|
-
);
|
|
499
|
-
this.BLE_Calibration = ad.serviceData.calibration;
|
|
500
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
501
|
-
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
502
|
-
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
503
|
-
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
504
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
505
|
-
this.debugLog(
|
|
506
|
-
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
507
|
-
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
508
|
-
`inMotion: ${ad.serviceData.inMotion}`,
|
|
509
|
-
);
|
|
510
|
-
|
|
511
|
-
if (ad.serviceData) {
|
|
512
|
-
this.BLE_IsConnected = true;
|
|
513
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
514
|
-
await this.stopScanning(switchbot);
|
|
515
|
-
} else {
|
|
516
|
-
this.BLE_IsConnected = false;
|
|
517
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
// Wait
|
|
521
|
-
return await sleep(this.scanDuration * 1000);
|
|
522
|
-
})
|
|
523
|
-
.then(async () => {
|
|
524
|
-
// Stop to monitor
|
|
525
|
-
await this.stopScanning(switchbot);
|
|
526
|
-
})
|
|
527
|
-
.catch(async (e: any) => {
|
|
528
|
-
this.apiError(e);
|
|
529
|
-
this.errorLog(
|
|
530
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
531
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
532
|
-
);
|
|
533
|
-
await this.BLERefreshConnection(switchbot);
|
|
534
|
-
});
|
|
535
|
-
} else {
|
|
536
|
-
await this.BLERefreshConnection(switchbot);
|
|
537
|
-
}*/
|
|
450
|
+
if (switchbot === undefined) {
|
|
451
|
+
await this.BLERefreshConnection(switchbot);
|
|
452
|
+
}
|
|
538
453
|
}
|
|
539
454
|
async openAPIRefreshStatus() {
|
|
540
455
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
541
456
|
try {
|
|
542
|
-
const { body, statusCode } = await
|
|
543
|
-
headers: this.platform.generateHeaders(),
|
|
544
|
-
});
|
|
457
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
545
458
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
546
459
|
const deviceStatus = await body.json();
|
|
547
460
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
548
461
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
549
462
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
550
|
-
this.
|
|
463
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
551
464
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
552
|
-
this.
|
|
553
|
-
this.OpenAPI_Direction = deviceStatus.body.direction;
|
|
554
|
-
this.OpenAPI_InMotion = deviceStatus.body.moving;
|
|
555
|
-
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
556
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
557
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
558
|
-
this.openAPIparseStatus();
|
|
465
|
+
this.openAPIparseStatus(deviceStatus);
|
|
559
466
|
this.updateHomeKitCharacteristics();
|
|
560
467
|
}
|
|
561
468
|
else {
|
|
@@ -593,7 +500,7 @@ export class BlindTilt {
|
|
|
593
500
|
}
|
|
594
501
|
async BLEpushChanges() {
|
|
595
502
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
596
|
-
if (this.TargetPosition !== this.CurrentPosition) {
|
|
503
|
+
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
597
504
|
const switchbot = await this.platform.connectBLE();
|
|
598
505
|
// Convert to BLE Address
|
|
599
506
|
this.device.bleMac = this.device
|
|
@@ -601,26 +508,24 @@ export class BlindTilt {
|
|
|
601
508
|
.join(':')
|
|
602
509
|
.toLowerCase();
|
|
603
510
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
604
|
-
this.
|
|
605
|
-
|
|
606
|
-
if (adjustedMode === null) {
|
|
607
|
-
this.Mode = 'Default Mode';
|
|
608
|
-
}
|
|
609
|
-
this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
511
|
+
const { setPositionMode, Mode } = await this.setPerformance();
|
|
512
|
+
this.debugLog(`${this.accessory.displayName} Mode: ${Mode}`);
|
|
610
513
|
if (switchbot !== false) {
|
|
611
514
|
switchbot
|
|
612
515
|
.discover({ model: 'c', quick: true, id: this.device.bleMac })
|
|
613
516
|
.then(async (device_list) => {
|
|
614
|
-
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
615
|
-
return await this.
|
|
616
|
-
max: this.
|
|
517
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.WindowCovering.TargetPosition}`);
|
|
518
|
+
return await this.retryBLE({
|
|
519
|
+
max: await this.maxRetryBLE(),
|
|
617
520
|
fn: async () => {
|
|
618
|
-
return await device_list[0].runToPos(100 - Number(this.TargetPosition),
|
|
521
|
+
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode);
|
|
619
522
|
},
|
|
620
523
|
});
|
|
621
524
|
})
|
|
622
525
|
.then(() => {
|
|
623
526
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
527
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
528
|
+
+ `Target Position: ${this.WindowCovering.TargetPosition} sent over BLE, sent successfully`);
|
|
624
529
|
})
|
|
625
530
|
.catch(async (e) => {
|
|
626
531
|
this.apiError(e);
|
|
@@ -636,35 +541,20 @@ export class BlindTilt {
|
|
|
636
541
|
}
|
|
637
542
|
else {
|
|
638
543
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
|
|
639
|
-
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
async retry({ max, fn }) {
|
|
643
|
-
return fn().catch(async (e) => {
|
|
644
|
-
if (max === 0) {
|
|
645
|
-
throw e;
|
|
646
|
-
}
|
|
647
|
-
this.infoLog(e);
|
|
648
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
649
|
-
await sleep(1000);
|
|
650
|
-
return this.retry({ max: max - 1, fn });
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
maxRetry() {
|
|
654
|
-
if (this.device.maxRetry) {
|
|
655
|
-
return this.device.maxRetry;
|
|
656
|
-
}
|
|
657
|
-
else {
|
|
658
|
-
return 5;
|
|
544
|
+
` CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition ${this.WindowCovering.TargetPosition}`);
|
|
659
545
|
}
|
|
660
546
|
}
|
|
661
547
|
async openAPIpushChanges() {
|
|
662
548
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
663
|
-
const hasDifferentAndRelevantHorizontalTiltAngle = this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
this.
|
|
549
|
+
const hasDifferentAndRelevantHorizontalTiltAngle = this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
550
|
+
&& this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
551
|
+
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition
|
|
552
|
+
|| hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
|
|
553
|
+
const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition), Number(this.WindowCovering.TargetHorizontalTiltAngle));
|
|
554
|
+
const { Mode } = await this.setPerformance();
|
|
555
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
556
|
+
+ ` Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`);
|
|
557
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${Mode}`);
|
|
668
558
|
let bodyChange = '';
|
|
669
559
|
if (position === 100) {
|
|
670
560
|
bodyChange = JSON.stringify({
|
|
@@ -698,8 +588,10 @@ export class BlindTilt {
|
|
|
698
588
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
699
589
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
700
590
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
701
|
-
this.
|
|
591
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
702
592
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
593
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
594
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
|
|
703
595
|
}
|
|
704
596
|
else {
|
|
705
597
|
this.statusCode(statusCode);
|
|
@@ -708,30 +600,31 @@ export class BlindTilt {
|
|
|
708
600
|
}
|
|
709
601
|
catch (e) {
|
|
710
602
|
this.apiError(e);
|
|
711
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
712
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
603
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
604
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
713
605
|
}
|
|
714
606
|
}
|
|
715
607
|
else {
|
|
716
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
717
|
-
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`
|
|
718
|
-
` CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}
|
|
608
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
609
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition ${this.WindowCovering.TargetPosition}`
|
|
610
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle},`
|
|
611
|
+
+ ` TargetPosition ${this.WindowCovering.TargetHorizontalTiltAngle}`);
|
|
719
612
|
}
|
|
720
613
|
}
|
|
721
614
|
/**
|
|
722
615
|
* Handle requests to set the value of the "Target Horizontal Tilt" characteristic
|
|
723
616
|
*/
|
|
724
617
|
async TargetHorizontalTiltAngleSet(value) {
|
|
725
|
-
if (this.TargetHorizontalTiltAngle === this.accessory.context.TargetHorizontalTiltAngle) {
|
|
618
|
+
if (this.WindowCovering.TargetHorizontalTiltAngle === this.accessory.context.TargetHorizontalTiltAngle) {
|
|
726
619
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetHorizontalTiltAngle: ${value}`);
|
|
727
620
|
}
|
|
728
621
|
else {
|
|
729
622
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHorizontalTiltAngle: ${value}`);
|
|
730
623
|
}
|
|
731
624
|
//value = value < 0 ? -90 : 90;
|
|
732
|
-
this.TargetHorizontalTiltAngle = value;
|
|
625
|
+
this.WindowCovering.TargetHorizontalTiltAngle = value;
|
|
733
626
|
if (this.device.mqttURL) {
|
|
734
|
-
this.mqttPublish('TargetHorizontalTiltAngle', this.TargetHorizontalTiltAngle);
|
|
627
|
+
this.mqttPublish('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle.toString());
|
|
735
628
|
}
|
|
736
629
|
this.startUpdatingBlindTiltIfNeeded();
|
|
737
630
|
}
|
|
@@ -739,49 +632,53 @@ export class BlindTilt {
|
|
|
739
632
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
740
633
|
*/
|
|
741
634
|
async TargetPositionSet(value) {
|
|
742
|
-
if (this.TargetPosition === this.accessory.context.TargetPosition) {
|
|
635
|
+
if (this.WindowCovering.TargetPosition === this.accessory.context.TargetPosition) {
|
|
743
636
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetPosition: ${value}`);
|
|
744
637
|
}
|
|
745
638
|
else {
|
|
746
639
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
747
640
|
}
|
|
748
|
-
this.TargetPosition = value;
|
|
641
|
+
this.WindowCovering.TargetPosition = value;
|
|
749
642
|
if (this.device.mqttURL) {
|
|
750
|
-
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
643
|
+
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
751
644
|
}
|
|
752
645
|
this.startUpdatingBlindTiltIfNeeded();
|
|
753
646
|
}
|
|
754
647
|
async startUpdatingBlindTiltIfNeeded() {
|
|
755
648
|
await this.setMinMax();
|
|
756
649
|
this.debugLog('setMinMax');
|
|
757
|
-
if (this.TargetPosition > this.CurrentPosition
|
|
758
|
-
this.
|
|
650
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
651
|
+
|| this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
|
|
652
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
759
653
|
this.setNewTarget = true;
|
|
760
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
654
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
655
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
761
656
|
}
|
|
762
|
-
else if (this.TargetPosition < this.CurrentPosition) {
|
|
763
|
-
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
657
|
+
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
658
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
764
659
|
this.setNewTarget = true;
|
|
765
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
660
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
661
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
766
662
|
}
|
|
767
663
|
else {
|
|
768
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
664
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
769
665
|
this.setNewTarget = false;
|
|
770
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
666
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
667
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
771
668
|
}
|
|
772
|
-
this.
|
|
773
|
-
this.
|
|
669
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
670
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
774
671
|
/**
|
|
775
672
|
* If Blind Tilt movement time is short, the moving flag from backend is always false.
|
|
776
673
|
* The minimum time depends on the network control latency.
|
|
777
674
|
*/
|
|
778
675
|
clearTimeout(this.setNewTargetTimer);
|
|
779
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.
|
|
676
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.deviceUpdateRate}`);
|
|
780
677
|
if (this.setNewTarget) {
|
|
781
678
|
this.setNewTargetTimer = setTimeout(() => {
|
|
782
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
783
680
|
this.setNewTarget = false;
|
|
784
|
-
}, this.
|
|
681
|
+
}, this.deviceUpdateRate * 1000);
|
|
785
682
|
}
|
|
786
683
|
this.doBlindTiltUpdate.next();
|
|
787
684
|
}
|
|
@@ -789,152 +686,111 @@ export class BlindTilt {
|
|
|
789
686
|
await this.setMinMax();
|
|
790
687
|
// CurrentHorizontalTiltAngle
|
|
791
688
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
792
|
-
if (this.CurrentHorizontalTiltAngle === undefined || Number.isNaN(this.CurrentHorizontalTiltAngle)) {
|
|
793
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
689
|
+
if (this.WindowCovering.CurrentHorizontalTiltAngle === undefined || Number.isNaN(this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
690
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
691
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
794
692
|
}
|
|
795
693
|
else {
|
|
796
694
|
if (this.device.mqttURL) {
|
|
797
|
-
this.mqttPublish('CurrentHorizontalTiltAngle', this.CurrentHorizontalTiltAngle);
|
|
695
|
+
this.mqttPublish('CurrentHorizontalTiltAngle', this.WindowCovering.CurrentHorizontalTiltAngle.toString());
|
|
798
696
|
}
|
|
799
|
-
this.accessory.context.CurrentHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
800
|
-
this.
|
|
697
|
+
this.accessory.context.CurrentHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
698
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, Number(this.WindowCovering.CurrentHorizontalTiltAngle));
|
|
801
699
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
802
|
-
updateCharacteristic CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}`);
|
|
700
|
+
updateCharacteristic CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
803
701
|
}
|
|
804
702
|
}
|
|
805
703
|
// CurrentPosition
|
|
806
|
-
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
807
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
704
|
+
if (this.WindowCovering.CurrentPosition === undefined || Number.isNaN(this.WindowCovering.CurrentPosition)) {
|
|
705
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
808
706
|
}
|
|
809
707
|
else {
|
|
810
708
|
if (this.device.mqttURL) {
|
|
811
|
-
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
709
|
+
this.mqttPublish('CurrentPosition', this.WindowCovering.CurrentPosition.toString());
|
|
812
710
|
}
|
|
813
|
-
this.accessory.context.CurrentPosition = this.CurrentPosition;
|
|
814
|
-
this.
|
|
815
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
711
|
+
this.accessory.context.CurrentPosition = this.WindowCovering.CurrentPosition;
|
|
712
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.WindowCovering.CurrentPosition));
|
|
713
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
714
|
+
+ ` updateCharacteristic CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
816
715
|
}
|
|
817
716
|
// PositionState
|
|
818
|
-
if (this.PositionState === undefined) {
|
|
819
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
717
|
+
if (this.WindowCovering.PositionState === undefined) {
|
|
718
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.WindowCovering.PositionState}`);
|
|
820
719
|
}
|
|
821
720
|
else {
|
|
822
721
|
if (this.device.mqttURL) {
|
|
823
|
-
this.mqttPublish('PositionState', this.PositionState);
|
|
722
|
+
this.mqttPublish('PositionState', this.WindowCovering.PositionState.toString());
|
|
824
723
|
}
|
|
825
|
-
this.accessory.context.PositionState = this.PositionState;
|
|
826
|
-
this.
|
|
827
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
724
|
+
this.accessory.context.PositionState = this.WindowCovering.PositionState;
|
|
725
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
|
|
726
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
727
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
828
728
|
}
|
|
829
729
|
// TargetPosition
|
|
830
|
-
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
831
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
730
|
+
if (this.WindowCovering.TargetPosition === undefined || Number.isNaN(this.WindowCovering.TargetPosition)) {
|
|
731
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
832
732
|
}
|
|
833
733
|
else {
|
|
834
734
|
if (this.device.mqttURL) {
|
|
835
|
-
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
735
|
+
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
836
736
|
}
|
|
837
|
-
this.accessory.context.TargetPosition = this.TargetPosition;
|
|
838
|
-
this.
|
|
839
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
737
|
+
this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
|
|
738
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
|
|
739
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
740
|
+
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
840
741
|
}
|
|
841
742
|
// CurrentAmbientLightLevel
|
|
842
743
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
843
|
-
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
844
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
744
|
+
if (this.LightSensor.CurrentAmbientLightLevel === undefined || Number.isNaN(this.LightSensor.CurrentAmbientLightLevel)) {
|
|
745
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
746
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
845
747
|
}
|
|
846
748
|
else {
|
|
847
749
|
if (this.device.mqttURL) {
|
|
848
|
-
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
750
|
+
this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor.CurrentAmbientLightLevel.toString());
|
|
849
751
|
}
|
|
850
|
-
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
851
|
-
this.
|
|
752
|
+
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor.CurrentAmbientLightLevel;
|
|
753
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel);
|
|
852
754
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
853
|
-
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
755
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
854
756
|
}
|
|
855
757
|
}
|
|
856
758
|
// BatteryLevel
|
|
857
|
-
if (this.BatteryLevel === undefined) {
|
|
858
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
759
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
760
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
859
761
|
}
|
|
860
762
|
else {
|
|
861
763
|
if (this.device.mqttURL) {
|
|
862
|
-
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
764
|
+
this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
|
|
863
765
|
}
|
|
864
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
865
|
-
this.
|
|
866
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
766
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
767
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
768
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
867
769
|
}
|
|
868
770
|
// StatusLowBattery
|
|
869
|
-
if (this.StatusLowBattery === undefined) {
|
|
870
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
771
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
772
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
871
773
|
}
|
|
872
774
|
else {
|
|
873
775
|
if (this.device.mqttURL) {
|
|
874
|
-
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
776
|
+
this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
|
|
875
777
|
}
|
|
876
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
877
|
-
this.
|
|
878
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
778
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
779
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
780
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
781
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
879
782
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
* Publish MQTT message for topics of
|
|
883
|
-
* 'homebridge-switchbot/blindtilt/xx:xx:xx:xx:xx:xx'
|
|
884
|
-
*/
|
|
885
|
-
mqttPublish(topic, message) {
|
|
886
|
-
const mac = this.device.deviceId
|
|
887
|
-
?.toLowerCase()
|
|
888
|
-
.match(/[\s\S]{1,2}/g)
|
|
889
|
-
?.join(':');
|
|
890
|
-
const options = this.device.mqttPubOptions || {};
|
|
891
|
-
this.mqttClient?.publish(`homebridge-switchbot/blindtilt/${mac}/${topic}`, `${message}`, options);
|
|
892
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${JSON.stringify(options)}`);
|
|
893
|
-
}
|
|
894
|
-
/*
|
|
895
|
-
* Setup MQTT hadler if URL is specified.
|
|
896
|
-
*/
|
|
897
|
-
async setupMqtt(device) {
|
|
898
|
-
if (device.mqttURL) {
|
|
899
|
-
try {
|
|
900
|
-
const { connectAsync } = asyncmqtt;
|
|
901
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
902
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
903
|
-
this.mqttClient.on('error', (e) => {
|
|
904
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
catch (e) {
|
|
908
|
-
this.mqttClient = null;
|
|
909
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
async stopScanning(switchbot) {
|
|
914
|
-
switchbot.stopScan();
|
|
915
|
-
if (this.BLE_IsConnected) {
|
|
916
|
-
await this.BLEparseStatus();
|
|
917
|
-
await this.updateHomeKitCharacteristics();
|
|
783
|
+
if (this.Battery.ChargingState === undefined) {
|
|
784
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
918
785
|
}
|
|
919
786
|
else {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
(
|
|
926
|
-
|
|
927
|
-
await switchbot.startScan({
|
|
928
|
-
model: 'c',
|
|
929
|
-
});
|
|
930
|
-
// Set an event handler
|
|
931
|
-
switchbot.onadvertisement = (ad) => {
|
|
932
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
933
|
-
};
|
|
934
|
-
await sleep(10000);
|
|
935
|
-
// Stop to monitor
|
|
936
|
-
switchbot.stopScan();
|
|
937
|
-
})();
|
|
787
|
+
if (this.device.mqttURL) {
|
|
788
|
+
this.mqttPublish('ChargingState', this.Battery.ChargingState.toString());
|
|
789
|
+
}
|
|
790
|
+
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
791
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
792
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
793
|
+
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
938
794
|
}
|
|
939
795
|
}
|
|
940
796
|
async BLEPushConnection() {
|
|
@@ -951,210 +807,105 @@ export class BlindTilt {
|
|
|
951
807
|
await this.openAPIRefreshStatus();
|
|
952
808
|
}
|
|
953
809
|
}
|
|
954
|
-
async
|
|
955
|
-
|
|
810
|
+
async setPerformance() {
|
|
811
|
+
let setPositionMode;
|
|
812
|
+
let Mode;
|
|
813
|
+
if (Number(this.WindowCovering.TargetPosition) > 50) {
|
|
956
814
|
if (this.device.blindTilt?.setOpenMode === '1') {
|
|
957
|
-
|
|
958
|
-
|
|
815
|
+
setPositionMode = 1;
|
|
816
|
+
Mode = 'Silent Mode';
|
|
817
|
+
}
|
|
818
|
+
else if (this.device.blindTilt?.setOpenMode === '0') {
|
|
819
|
+
setPositionMode = 0;
|
|
820
|
+
Mode = 'Performance Mode';
|
|
959
821
|
}
|
|
960
822
|
else {
|
|
961
|
-
|
|
962
|
-
|
|
823
|
+
setPositionMode = 0;
|
|
824
|
+
Mode = 'Default Mode';
|
|
963
825
|
}
|
|
964
826
|
}
|
|
965
827
|
else {
|
|
966
828
|
if (this.device.blindTilt?.setCloseMode === '1') {
|
|
967
|
-
|
|
968
|
-
|
|
829
|
+
setPositionMode = 1;
|
|
830
|
+
Mode = 'Silent Mode';
|
|
831
|
+
}
|
|
832
|
+
else if (this.device.blindTilt?.setOpenMode === '0') {
|
|
833
|
+
setPositionMode = 0;
|
|
834
|
+
Mode = 'Performance Mode';
|
|
969
835
|
}
|
|
970
836
|
else {
|
|
971
|
-
|
|
972
|
-
|
|
837
|
+
setPositionMode = 0;
|
|
838
|
+
Mode = 'Default Mode';
|
|
973
839
|
}
|
|
974
840
|
}
|
|
841
|
+
return { setPositionMode, Mode };
|
|
975
842
|
}
|
|
976
843
|
async setMinMax() {
|
|
977
844
|
if (this.device.blindTilt?.set_min) {
|
|
978
|
-
if (Number(this.CurrentPosition) <= this.device.blindTilt?.set_min) {
|
|
979
|
-
this.CurrentPosition = 0;
|
|
845
|
+
if (Number(this.WindowCovering.CurrentPosition) <= this.device.blindTilt?.set_min) {
|
|
846
|
+
this.WindowCovering.CurrentPosition = 0;
|
|
980
847
|
}
|
|
981
848
|
}
|
|
982
849
|
if (this.device.blindTilt?.set_max) {
|
|
983
|
-
if (Number(this.CurrentPosition) >= this.device.blindTilt?.set_max) {
|
|
984
|
-
this.CurrentPosition = 100;
|
|
850
|
+
if (Number(this.WindowCovering.CurrentPosition) >= this.device.blindTilt?.set_max) {
|
|
851
|
+
this.WindowCovering.CurrentPosition = 100;
|
|
985
852
|
}
|
|
986
853
|
}
|
|
987
854
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
988
|
-
this.CurrentHorizontalTiltAngle = Number(this.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
|
|
855
|
+
this.WindowCovering.CurrentHorizontalTiltAngle = Number(this.WindowCovering.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
|
|
989
856
|
}
|
|
990
857
|
}
|
|
991
|
-
minStep(device) {
|
|
858
|
+
async minStep(device) {
|
|
859
|
+
let set_minStep;
|
|
992
860
|
if (device.blindTilt?.set_minStep) {
|
|
993
|
-
|
|
861
|
+
set_minStep = device.blindTilt?.set_minStep;
|
|
994
862
|
}
|
|
995
863
|
else {
|
|
996
|
-
|
|
864
|
+
set_minStep = 1;
|
|
997
865
|
}
|
|
998
|
-
return
|
|
866
|
+
return set_minStep;
|
|
999
867
|
}
|
|
1000
|
-
minLux() {
|
|
868
|
+
async minLux() {
|
|
869
|
+
let set_minLux;
|
|
1001
870
|
if (this.device.blindTilt?.set_minLux) {
|
|
1002
|
-
|
|
871
|
+
set_minLux = this.device.blindTilt?.set_minLux;
|
|
1003
872
|
}
|
|
1004
873
|
else {
|
|
1005
|
-
|
|
874
|
+
set_minLux = 1;
|
|
1006
875
|
}
|
|
1007
|
-
return
|
|
876
|
+
return set_minLux;
|
|
1008
877
|
}
|
|
1009
|
-
maxLux() {
|
|
878
|
+
async maxLux() {
|
|
879
|
+
let set_maxLux;
|
|
1010
880
|
if (this.device.blindTilt?.set_maxLux) {
|
|
1011
|
-
|
|
881
|
+
set_maxLux = this.device.blindTilt?.set_maxLux;
|
|
1012
882
|
}
|
|
1013
883
|
else {
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
return this.set_maxLux;
|
|
1017
|
-
}
|
|
1018
|
-
async scan(device) {
|
|
1019
|
-
if (device.scanDuration) {
|
|
1020
|
-
if (this.updateRate > device.scanDuration) {
|
|
1021
|
-
this.scanDuration = this.updateRate;
|
|
1022
|
-
if (this.BLE) {
|
|
1023
|
-
this.warnLog(`${this.device.deviceType}: ` +
|
|
1024
|
-
`${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
else {
|
|
1028
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1029
|
-
}
|
|
1030
|
-
if (this.BLE) {
|
|
1031
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
else {
|
|
1035
|
-
if (this.updateRate > 1) {
|
|
1036
|
-
this.scanDuration = this.updateRate;
|
|
1037
|
-
}
|
|
1038
|
-
else {
|
|
1039
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
1040
|
-
}
|
|
1041
|
-
if (this.BLE) {
|
|
1042
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
async statusCode(statusCode) {
|
|
1047
|
-
switch (statusCode) {
|
|
1048
|
-
case 151:
|
|
1049
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
1050
|
-
break;
|
|
1051
|
-
case 152:
|
|
1052
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
1053
|
-
break;
|
|
1054
|
-
case 160:
|
|
1055
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
1056
|
-
break;
|
|
1057
|
-
case 161:
|
|
1058
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
1059
|
-
this.offlineOff();
|
|
1060
|
-
break;
|
|
1061
|
-
case 171:
|
|
1062
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1063
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
1064
|
-
this.offlineOff();
|
|
1065
|
-
break;
|
|
1066
|
-
case 190:
|
|
1067
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1068
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
1069
|
-
break;
|
|
1070
|
-
case 100:
|
|
1071
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
1072
|
-
break;
|
|
1073
|
-
case 200:
|
|
1074
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1075
|
-
break;
|
|
1076
|
-
case 400:
|
|
1077
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
1078
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
1079
|
-
break;
|
|
1080
|
-
case 401:
|
|
1081
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
1082
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
1083
|
-
break;
|
|
1084
|
-
case 403:
|
|
1085
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
1086
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
1087
|
-
break;
|
|
1088
|
-
case 404:
|
|
1089
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
1090
|
-
+ `statusCode: ${statusCode}`);
|
|
1091
|
-
break;
|
|
1092
|
-
case 406:
|
|
1093
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
1094
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
1095
|
-
break;
|
|
1096
|
-
case 415:
|
|
1097
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
1098
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
1099
|
-
break;
|
|
1100
|
-
case 422:
|
|
1101
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
1102
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
1103
|
-
break;
|
|
1104
|
-
case 429:
|
|
1105
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
1106
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
1107
|
-
break;
|
|
1108
|
-
case 500:
|
|
1109
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
1110
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
1111
|
-
break;
|
|
1112
|
-
default:
|
|
1113
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1114
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
884
|
+
set_maxLux = 6001;
|
|
1115
885
|
}
|
|
886
|
+
return set_maxLux;
|
|
1116
887
|
}
|
|
1117
888
|
async offlineOff() {
|
|
1118
889
|
if (this.device.offline) {
|
|
1119
|
-
|
|
1120
|
-
|
|
890
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
891
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
892
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
893
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, 90);
|
|
894
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, 90);
|
|
1121
895
|
}
|
|
1122
896
|
}
|
|
1123
897
|
async apiError(e) {
|
|
1124
|
-
this.
|
|
1125
|
-
this.
|
|
1126
|
-
this.
|
|
898
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
899
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
900
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
901
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, e);
|
|
902
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle, e);
|
|
903
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
904
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
905
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, e);
|
|
1127
906
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
1128
|
-
this.
|
|
1129
|
-
|
|
1130
|
-
if (this.BLE) {
|
|
1131
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1132
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1133
|
-
}
|
|
1134
|
-
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
1135
|
-
}
|
|
1136
|
-
async deviceContext() {
|
|
1137
|
-
if (this.CurrentPosition === undefined) {
|
|
1138
|
-
this.CurrentPosition = 0;
|
|
1139
|
-
}
|
|
1140
|
-
else {
|
|
1141
|
-
this.CurrentPosition = this.accessory.context.CurrentPosition;
|
|
1142
|
-
}
|
|
1143
|
-
if (this.TargetPosition === undefined) {
|
|
1144
|
-
this.TargetPosition = 0;
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
this.TargetPosition = this.accessory.context.TargetPosition;
|
|
1148
|
-
}
|
|
1149
|
-
if (this.PositionState === undefined) {
|
|
1150
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
1151
|
-
}
|
|
1152
|
-
else {
|
|
1153
|
-
this.PositionState = this.accessory.context.PositionState;
|
|
1154
|
-
}
|
|
1155
|
-
if (this.FirmwareRevision === undefined) {
|
|
1156
|
-
this.FirmwareRevision = this.platform.version;
|
|
1157
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
907
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
908
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
1158
909
|
}
|
|
1159
910
|
}
|
|
1160
911
|
/**
|
|
@@ -1271,127 +1022,5 @@ export class BlindTilt {
|
|
|
1271
1022
|
}
|
|
1272
1023
|
}
|
|
1273
1024
|
}
|
|
1274
|
-
async refreshRate(device) {
|
|
1275
|
-
// refreshRate
|
|
1276
|
-
if (device.refreshRate) {
|
|
1277
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1278
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1279
|
-
}
|
|
1280
|
-
else if (this.platform.config.options.refreshRate) {
|
|
1281
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
1282
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1283
|
-
}
|
|
1284
|
-
// updateRate
|
|
1285
|
-
if (device?.blindTilt?.updateRate) {
|
|
1286
|
-
this.updateRate = device?.blindTilt?.updateRate;
|
|
1287
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Blind Tilt updateRate: ${this.updateRate}`);
|
|
1288
|
-
}
|
|
1289
|
-
else {
|
|
1290
|
-
this.updateRate = 2;
|
|
1291
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Blind Tilt updateRate: ${this.updateRate}`);
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
async deviceConfig(device) {
|
|
1295
|
-
let config = {};
|
|
1296
|
-
if (device.blindTilt) {
|
|
1297
|
-
config = device.blindTilt;
|
|
1298
|
-
}
|
|
1299
|
-
if (device.connectionType !== undefined) {
|
|
1300
|
-
config['connectionType'] = device.connectionType;
|
|
1301
|
-
}
|
|
1302
|
-
if (device.external !== undefined) {
|
|
1303
|
-
config['external'] = device.external;
|
|
1304
|
-
}
|
|
1305
|
-
if (device.mqttURL !== undefined) {
|
|
1306
|
-
config['mqttURL'] = device.mqttURL;
|
|
1307
|
-
}
|
|
1308
|
-
if (device.logging !== undefined) {
|
|
1309
|
-
config['logging'] = device.logging;
|
|
1310
|
-
}
|
|
1311
|
-
if (device.refreshRate !== undefined) {
|
|
1312
|
-
config['refreshRate'] = device.refreshRate;
|
|
1313
|
-
}
|
|
1314
|
-
if (device.scanDuration !== undefined) {
|
|
1315
|
-
config['scanDuration'] = device.scanDuration;
|
|
1316
|
-
}
|
|
1317
|
-
if (device.maxRetry !== undefined) {
|
|
1318
|
-
config['maxRetry'] = device.maxRetry;
|
|
1319
|
-
}
|
|
1320
|
-
if (device.webhook !== undefined) {
|
|
1321
|
-
config['webhook'] = device.webhook;
|
|
1322
|
-
}
|
|
1323
|
-
if (device.blindTilt?.mode === undefined) {
|
|
1324
|
-
config['mode'] = BlindTiltMappingMode.OnlyUp;
|
|
1325
|
-
}
|
|
1326
|
-
else {
|
|
1327
|
-
config['mode'] = device.blindTilt?.mode;
|
|
1328
|
-
}
|
|
1329
|
-
if (Object.entries(config).length !== 0) {
|
|
1330
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
async deviceLogs(device) {
|
|
1334
|
-
if (this.platform.debugMode) {
|
|
1335
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1336
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1337
|
-
}
|
|
1338
|
-
else if (device.logging) {
|
|
1339
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1340
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1341
|
-
}
|
|
1342
|
-
else if (this.platform.config.options?.logging) {
|
|
1343
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1344
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1345
|
-
}
|
|
1346
|
-
else {
|
|
1347
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1348
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Logging for Device
|
|
1353
|
-
*/
|
|
1354
|
-
infoLog(...log) {
|
|
1355
|
-
if (this.enablingDeviceLogging()) {
|
|
1356
|
-
this.platform.log.info(String(...log));
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
warnLog(...log) {
|
|
1360
|
-
if (this.enablingDeviceLogging()) {
|
|
1361
|
-
this.platform.log.warn(String(...log));
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
debugWarnLog(...log) {
|
|
1365
|
-
if (this.enablingDeviceLogging()) {
|
|
1366
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1367
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
errorLog(...log) {
|
|
1372
|
-
if (this.enablingDeviceLogging()) {
|
|
1373
|
-
this.platform.log.error(String(...log));
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
debugErrorLog(...log) {
|
|
1377
|
-
if (this.enablingDeviceLogging()) {
|
|
1378
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1379
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
debugLog(...log) {
|
|
1384
|
-
if (this.enablingDeviceLogging()) {
|
|
1385
|
-
if (this.deviceLogging === 'debug') {
|
|
1386
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1387
|
-
}
|
|
1388
|
-
else {
|
|
1389
|
-
this.platform.log.debug(String(...log));
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
enablingDeviceLogging() {
|
|
1394
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1395
|
-
}
|
|
1396
1025
|
}
|
|
1397
1026
|
//# sourceMappingURL=blindtilt.js.map
|