@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/dist/device/blindtilt.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const async_mqtt_1 = require("async-mqtt");
|
|
8
|
-
const operators_1 = require("rxjs/operators");
|
|
9
|
-
const settings_1 = require("../settings");
|
|
1
|
+
import { request } from 'undici';
|
|
2
|
+
import { sleep } from '../utils';
|
|
3
|
+
import { interval, Subject } from 'rxjs';
|
|
4
|
+
import { connectAsync } from 'async-mqtt';
|
|
5
|
+
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
+
import { Devices } from '../settings';
|
|
10
7
|
var BlindTiltMappingMode;
|
|
11
8
|
(function (BlindTiltMappingMode) {
|
|
12
9
|
BlindTiltMappingMode["OnlyUp"] = "only_up";
|
|
@@ -15,53 +12,117 @@ var BlindTiltMappingMode;
|
|
|
15
12
|
BlindTiltMappingMode["UpAndDown"] = "up_and_down";
|
|
16
13
|
BlindTiltMappingMode["UseTiltForDirection"] = "use_tilt_for_direction";
|
|
17
14
|
})(BlindTiltMappingMode || (BlindTiltMappingMode = {}));
|
|
18
|
-
class BlindTilt {
|
|
15
|
+
export class BlindTilt {
|
|
16
|
+
platform;
|
|
17
|
+
accessory;
|
|
18
|
+
device;
|
|
19
|
+
api;
|
|
20
|
+
log;
|
|
21
|
+
config;
|
|
22
|
+
hap;
|
|
23
|
+
// Services
|
|
24
|
+
batteryService;
|
|
25
|
+
lightSensorService;
|
|
26
|
+
windowCoveringService;
|
|
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;
|
|
45
|
+
// OpenAPI Others
|
|
46
|
+
Mode;
|
|
47
|
+
setPositionMode;
|
|
48
|
+
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
|
+
// Target
|
|
59
|
+
setNewTarget;
|
|
60
|
+
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
|
+
// Updates
|
|
74
|
+
blindTiltUpdateInProgress;
|
|
75
|
+
doBlindTiltUpdate;
|
|
76
|
+
// Connection
|
|
77
|
+
OpenAPI;
|
|
78
|
+
BLE;
|
|
19
79
|
constructor(platform, accessory, device) {
|
|
20
80
|
this.platform = platform;
|
|
21
81
|
this.accessory = accessory;
|
|
22
82
|
this.device = device;
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
this.
|
|
83
|
+
this.api = this.platform.api;
|
|
84
|
+
this.log = this.platform.log;
|
|
85
|
+
this.config = this.platform.config;
|
|
86
|
+
this.hap = this.api.hap;
|
|
26
87
|
// Connection
|
|
27
88
|
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
28
89
|
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
29
90
|
// default placeholders
|
|
30
|
-
this.
|
|
91
|
+
this.deviceLogs(device);
|
|
31
92
|
this.refreshRate(device);
|
|
32
93
|
this.scan(device);
|
|
33
94
|
this.setupMqtt(device);
|
|
34
95
|
this.context();
|
|
35
|
-
this.
|
|
96
|
+
this.deviceConfig(device);
|
|
36
97
|
this.mappingMode = device.blindTilt?.mode ?? BlindTiltMappingMode.OnlyUp;
|
|
37
98
|
this.debugLog(`Mapping mode: ${this.mappingMode}`);
|
|
38
99
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
39
|
-
this.doBlindTiltUpdate = new
|
|
100
|
+
this.doBlindTiltUpdate = new Subject();
|
|
40
101
|
this.blindTiltUpdateInProgress = false;
|
|
41
102
|
this.setNewTarget = false;
|
|
42
103
|
// Retrieve initial values and updateHomekit
|
|
43
104
|
this.refreshStatus();
|
|
44
105
|
// set accessory information
|
|
45
106
|
accessory
|
|
46
|
-
.getService(this.
|
|
47
|
-
.setCharacteristic(this.
|
|
48
|
-
.setCharacteristic(this.
|
|
49
|
-
.setCharacteristic(this.
|
|
50
|
-
.setCharacteristic(this.
|
|
107
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
108
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
109
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W2701600')
|
|
110
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
111
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
51
112
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
52
113
|
// you can create multiple services for each accessory
|
|
53
114
|
const windowCoveringService = `${device.deviceName} ${device.deviceType}`;
|
|
54
115
|
(this.windowCoveringService =
|
|
55
|
-
accessory.getService(this.
|
|
56
|
-
|| accessory.addService(this.
|
|
57
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
58
|
-
if (!this.windowCoveringService.testCharacteristic(this.
|
|
59
|
-
this.windowCoveringService.addCharacteristic(this.
|
|
116
|
+
accessory.getService(this.hap.Service.WindowCovering)
|
|
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);
|
|
60
121
|
}
|
|
61
122
|
// create handlers for required characteristics
|
|
62
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
123
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
|
|
63
124
|
this.windowCoveringService
|
|
64
|
-
.getCharacteristic(this.
|
|
125
|
+
.getCharacteristic(this.hap.Characteristic.CurrentPosition)
|
|
65
126
|
.setProps({
|
|
66
127
|
minStep: this.minStep(device),
|
|
67
128
|
minValue: 0,
|
|
@@ -72,7 +133,7 @@ class BlindTilt {
|
|
|
72
133
|
return this.CurrentPosition;
|
|
73
134
|
});
|
|
74
135
|
this.windowCoveringService
|
|
75
|
-
.getCharacteristic(this.
|
|
136
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
76
137
|
.setProps({
|
|
77
138
|
minStep: this.minStep(device),
|
|
78
139
|
minValue: 0,
|
|
@@ -82,7 +143,7 @@ class BlindTilt {
|
|
|
82
143
|
.onSet(this.TargetPositionSet.bind(this));
|
|
83
144
|
this.CurrentHorizontalTiltAngle = 90;
|
|
84
145
|
this.windowCoveringService
|
|
85
|
-
.getCharacteristic(this.
|
|
146
|
+
.getCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle)
|
|
86
147
|
.setProps({
|
|
87
148
|
minStep: 180,
|
|
88
149
|
minValue: -90,
|
|
@@ -95,7 +156,7 @@ class BlindTilt {
|
|
|
95
156
|
});
|
|
96
157
|
this.TargetHorizontalTiltAngle = 90;
|
|
97
158
|
this.windowCoveringService
|
|
98
|
-
.getCharacteristic(this.
|
|
159
|
+
.getCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle)
|
|
99
160
|
.setProps({
|
|
100
161
|
minStep: 180,
|
|
101
162
|
minValue: -90,
|
|
@@ -105,17 +166,17 @@ class BlindTilt {
|
|
|
105
166
|
.onSet(this.TargetHorizontalTiltAngleSet.bind(this));
|
|
106
167
|
// Battery Service
|
|
107
168
|
const batteryService = `${accessory.displayName} Battery`;
|
|
108
|
-
(this.batteryService = this.accessory.getService(this.
|
|
109
|
-
|| accessory.addService(this.
|
|
110
|
-
this.batteryService.setCharacteristic(this.
|
|
111
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
112
|
-
this.batteryService.addCharacteristic(this.
|
|
169
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
170
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
171
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
172
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
173
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
113
174
|
}
|
|
114
175
|
// Update Homekit
|
|
115
176
|
this.updateHomeKitCharacteristics();
|
|
116
177
|
// Start an update interval
|
|
117
|
-
|
|
118
|
-
.pipe(
|
|
178
|
+
interval(this.deviceRefreshRate * 1000)
|
|
179
|
+
.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
119
180
|
.subscribe(async () => {
|
|
120
181
|
await this.refreshStatus();
|
|
121
182
|
});
|
|
@@ -143,10 +204,10 @@ class BlindTilt {
|
|
|
143
204
|
};
|
|
144
205
|
}
|
|
145
206
|
// update slide progress
|
|
146
|
-
|
|
207
|
+
interval(this.updateRate * 1000)
|
|
147
208
|
//.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
148
209
|
.subscribe(async () => {
|
|
149
|
-
if (this.PositionState === this.
|
|
210
|
+
if (this.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
150
211
|
return;
|
|
151
212
|
}
|
|
152
213
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
|
|
@@ -155,9 +216,9 @@ class BlindTilt {
|
|
|
155
216
|
// Watch for BlindTilt change events
|
|
156
217
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
157
218
|
this.doBlindTiltUpdate
|
|
158
|
-
.pipe(
|
|
219
|
+
.pipe(tap(() => {
|
|
159
220
|
this.blindTiltUpdateInProgress = true;
|
|
160
|
-
}),
|
|
221
|
+
}), debounceTime(this.platform.config.options.pushRate * 1000))
|
|
161
222
|
.subscribe(async () => {
|
|
162
223
|
try {
|
|
163
224
|
await this.pushChanges();
|
|
@@ -201,27 +262,27 @@ class BlindTilt {
|
|
|
201
262
|
await this.setMinMax();
|
|
202
263
|
if (Number(this.TargetPosition) > this.CurrentPosition) {
|
|
203
264
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
204
|
-
this.PositionState = this.
|
|
205
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
265
|
+
this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
266
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
206
267
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
207
268
|
}
|
|
208
269
|
else if (Number(this.TargetPosition) < this.CurrentPosition) {
|
|
209
270
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
|
|
210
|
-
this.PositionState = this.
|
|
211
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
271
|
+
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
272
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
212
273
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
213
274
|
}
|
|
214
275
|
else {
|
|
215
276
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby2, CurrentPosition: ${this.CurrentPosition}`);
|
|
216
|
-
this.PositionState = this.
|
|
217
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
277
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
278
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
218
279
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
219
280
|
}
|
|
220
281
|
}
|
|
221
282
|
else {
|
|
222
283
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
223
284
|
this.TargetPosition = this.CurrentPosition;
|
|
224
|
-
this.PositionState = this.
|
|
285
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
225
286
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
226
287
|
}
|
|
227
288
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
@@ -280,10 +341,10 @@ class BlindTilt {
|
|
|
280
341
|
// Battery
|
|
281
342
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
282
343
|
if (this.BatteryLevel < 10) {
|
|
283
|
-
this.StatusLowBattery = this.
|
|
344
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
284
345
|
}
|
|
285
346
|
else {
|
|
286
|
-
this.StatusLowBattery = this.
|
|
347
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
287
348
|
}
|
|
288
349
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
289
350
|
}
|
|
@@ -306,20 +367,20 @@ class BlindTilt {
|
|
|
306
367
|
await this.setMinMax();
|
|
307
368
|
if (this.TargetPosition > this.CurrentPosition || (homekitTiltAngle && this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle)) {
|
|
308
369
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
309
|
-
this.PositionState = this.
|
|
310
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
370
|
+
this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
371
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
311
372
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
|
|
312
373
|
}
|
|
313
374
|
else if (this.TargetPosition < this.CurrentPosition) {
|
|
314
375
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
|
|
315
|
-
this.PositionState = this.
|
|
316
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
376
|
+
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
377
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
317
378
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
|
|
318
379
|
}
|
|
319
380
|
else {
|
|
320
381
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby because reached position,` + ` CurrentPosition: ${this.CurrentPosition}`);
|
|
321
|
-
this.PositionState = this.
|
|
322
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
382
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
383
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
323
384
|
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
|
|
324
385
|
}
|
|
325
386
|
}
|
|
@@ -329,7 +390,7 @@ class BlindTilt {
|
|
|
329
390
|
if (homekitTiltAngle) {
|
|
330
391
|
this.TargetHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
331
392
|
}
|
|
332
|
-
this.PositionState = this.
|
|
393
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
333
394
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
334
395
|
}
|
|
335
396
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
@@ -351,10 +412,10 @@ class BlindTilt {
|
|
|
351
412
|
// BatteryLevel
|
|
352
413
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
353
414
|
if (this.BatteryLevel < 10) {
|
|
354
|
-
this.StatusLowBattery = this.
|
|
415
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
355
416
|
}
|
|
356
417
|
else {
|
|
357
|
-
this.StatusLowBattery = this.
|
|
418
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
358
419
|
}
|
|
359
420
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
360
421
|
this.BatteryLevel = 100;
|
|
@@ -423,7 +484,7 @@ class BlindTilt {
|
|
|
423
484
|
}
|
|
424
485
|
};
|
|
425
486
|
// Wait
|
|
426
|
-
return await
|
|
487
|
+
return await sleep(this.scanDuration * 1000);
|
|
427
488
|
})
|
|
428
489
|
.then(async () => {
|
|
429
490
|
// Stop to monitor
|
|
@@ -443,7 +504,7 @@ class BlindTilt {
|
|
|
443
504
|
async openAPIRefreshStatus() {
|
|
444
505
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
445
506
|
try {
|
|
446
|
-
const { body, statusCode, headers } = await
|
|
507
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
447
508
|
headers: this.platform.generateHeaders(),
|
|
448
509
|
});
|
|
449
510
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
@@ -491,9 +552,9 @@ class BlindTilt {
|
|
|
491
552
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
492
553
|
}
|
|
493
554
|
// Refresh the status from the API
|
|
494
|
-
|
|
495
|
-
.pipe(
|
|
496
|
-
.pipe(
|
|
555
|
+
interval(15000)
|
|
556
|
+
.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
557
|
+
.pipe(take(1))
|
|
497
558
|
.subscribe(async () => {
|
|
498
559
|
await this.refreshStatus();
|
|
499
560
|
});
|
|
@@ -553,7 +614,7 @@ class BlindTilt {
|
|
|
553
614
|
}
|
|
554
615
|
this.infoLog(e);
|
|
555
616
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
556
|
-
await
|
|
617
|
+
await sleep(1000);
|
|
557
618
|
return this.retry({ max: max - 1, fn });
|
|
558
619
|
});
|
|
559
620
|
}
|
|
@@ -594,7 +655,7 @@ class BlindTilt {
|
|
|
594
655
|
}
|
|
595
656
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
596
657
|
try {
|
|
597
|
-
const { body, statusCode, headers } = await
|
|
658
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
598
659
|
body: bodyChange,
|
|
599
660
|
method: 'POST',
|
|
600
661
|
headers: this.platform.generateHeaders(),
|
|
@@ -664,22 +725,22 @@ class BlindTilt {
|
|
|
664
725
|
await this.setMinMax();
|
|
665
726
|
this.debugLog('setMinMax');
|
|
666
727
|
if (this.TargetPosition > this.CurrentPosition || this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle) {
|
|
667
|
-
this.PositionState = this.
|
|
728
|
+
this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
668
729
|
this.setNewTarget = true;
|
|
669
730
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},` + ` CurrentPosition: ${this.CurrentPosition}`);
|
|
670
731
|
}
|
|
671
732
|
else if (this.TargetPosition < this.CurrentPosition) {
|
|
672
|
-
this.PositionState = this.
|
|
733
|
+
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
673
734
|
this.setNewTarget = true;
|
|
674
735
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},` + ` CurrentPosition: ${this.CurrentPosition}`);
|
|
675
736
|
}
|
|
676
737
|
else {
|
|
677
|
-
this.PositionState = this.
|
|
738
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
678
739
|
this.setNewTarget = false;
|
|
679
740
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},` + ` CurrentPosition: ${this.CurrentPosition}`);
|
|
680
741
|
}
|
|
681
|
-
this.windowCoveringService.setCharacteristic(this.
|
|
682
|
-
this.windowCoveringService.getCharacteristic(this.
|
|
742
|
+
this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
|
|
743
|
+
this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
|
|
683
744
|
/**
|
|
684
745
|
* If Blind Tilt movement time is short, the moving flag from backend is always false.
|
|
685
746
|
* The minimum time depends on the network control latency.
|
|
@@ -706,7 +767,7 @@ class BlindTilt {
|
|
|
706
767
|
this.mqttPublish('CurrentHorizontalTiltAngle', this.CurrentHorizontalTiltAngle);
|
|
707
768
|
}
|
|
708
769
|
this.accessory.context.CurrentHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
709
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
770
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle, Number(this.CurrentHorizontalTiltAngle));
|
|
710
771
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
711
772
|
updateCharacteristic CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}`);
|
|
712
773
|
}
|
|
@@ -720,7 +781,7 @@ class BlindTilt {
|
|
|
720
781
|
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
721
782
|
}
|
|
722
783
|
this.accessory.context.CurrentPosition = this.CurrentPosition;
|
|
723
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
784
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.CurrentPosition));
|
|
724
785
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
|
|
725
786
|
}
|
|
726
787
|
// PositionState
|
|
@@ -732,7 +793,7 @@ class BlindTilt {
|
|
|
732
793
|
this.mqttPublish('PositionState', this.PositionState);
|
|
733
794
|
}
|
|
734
795
|
this.accessory.context.PositionState = this.PositionState;
|
|
735
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
796
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.PositionState));
|
|
736
797
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
|
|
737
798
|
}
|
|
738
799
|
// TargetPosition
|
|
@@ -744,7 +805,7 @@ class BlindTilt {
|
|
|
744
805
|
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
745
806
|
}
|
|
746
807
|
this.accessory.context.TargetPosition = this.TargetPosition;
|
|
747
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
808
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.TargetPosition));
|
|
748
809
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
|
|
749
810
|
}
|
|
750
811
|
// CurrentAmbientLightLevel
|
|
@@ -757,7 +818,7 @@ class BlindTilt {
|
|
|
757
818
|
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
758
819
|
}
|
|
759
820
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
760
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
821
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
761
822
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
762
823
|
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
763
824
|
}
|
|
@@ -771,7 +832,7 @@ class BlindTilt {
|
|
|
771
832
|
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
772
833
|
}
|
|
773
834
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
774
|
-
this.batteryService?.updateCharacteristic(this.
|
|
835
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
775
836
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
776
837
|
}
|
|
777
838
|
// StatusLowBattery
|
|
@@ -783,7 +844,7 @@ class BlindTilt {
|
|
|
783
844
|
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
784
845
|
}
|
|
785
846
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
786
|
-
this.batteryService?.updateCharacteristic(this.
|
|
847
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
787
848
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
788
849
|
}
|
|
789
850
|
}
|
|
@@ -806,7 +867,7 @@ class BlindTilt {
|
|
|
806
867
|
async setupMqtt(device) {
|
|
807
868
|
if (device.mqttURL) {
|
|
808
869
|
try {
|
|
809
|
-
this.mqttClient = await
|
|
870
|
+
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
810
871
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
811
872
|
this.mqttClient.on('error', (e) => {
|
|
812
873
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
@@ -839,7 +900,7 @@ class BlindTilt {
|
|
|
839
900
|
switchbot.onadvertisement = (ad) => {
|
|
840
901
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
841
902
|
};
|
|
842
|
-
await
|
|
903
|
+
await sleep(10000);
|
|
843
904
|
// Stop to monitor
|
|
844
905
|
await switchbot.stopScan();
|
|
845
906
|
})();
|
|
@@ -992,15 +1053,15 @@ class BlindTilt {
|
|
|
992
1053
|
}
|
|
993
1054
|
}
|
|
994
1055
|
async apiError(e) {
|
|
995
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
996
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
997
|
-
this.windowCoveringService.updateCharacteristic(this.
|
|
1056
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
1057
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
1058
|
+
this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
998
1059
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
999
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
1060
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
1000
1061
|
}
|
|
1001
1062
|
if (this.BLE) {
|
|
1002
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1003
|
-
this.batteryService?.updateCharacteristic(this.
|
|
1063
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
1064
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1004
1065
|
}
|
|
1005
1066
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
1006
1067
|
}
|
|
@@ -1018,7 +1079,7 @@ class BlindTilt {
|
|
|
1018
1079
|
this.TargetPosition = this.accessory.context.TargetPosition;
|
|
1019
1080
|
}
|
|
1020
1081
|
if (this.PositionState === undefined) {
|
|
1021
|
-
this.PositionState = this.
|
|
1082
|
+
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
1022
1083
|
}
|
|
1023
1084
|
else {
|
|
1024
1085
|
this.PositionState = this.accessory.context.PositionState;
|
|
@@ -1162,7 +1223,7 @@ class BlindTilt {
|
|
|
1162
1223
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Blind Tilt updateRate: ${this.updateRate}`);
|
|
1163
1224
|
}
|
|
1164
1225
|
}
|
|
1165
|
-
async
|
|
1226
|
+
async deviceConfig(device) {
|
|
1166
1227
|
let config = {};
|
|
1167
1228
|
if (device.blindTilt) {
|
|
1168
1229
|
config = device.blindTilt;
|
|
@@ -1198,7 +1259,7 @@ class BlindTilt {
|
|
|
1198
1259
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1199
1260
|
}
|
|
1200
1261
|
}
|
|
1201
|
-
async
|
|
1262
|
+
async deviceLogs(device) {
|
|
1202
1263
|
if (this.platform.debugMode) {
|
|
1203
1264
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1204
1265
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -1262,5 +1323,4 @@ class BlindTilt {
|
|
|
1262
1323
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1263
1324
|
}
|
|
1264
1325
|
}
|
|
1265
|
-
exports.BlindTilt = BlindTilt;
|
|
1266
1326
|
//# sourceMappingURL=blindtilt.js.map
|