@switchbot/homebridge-switchbot 3.5.0-beta.23 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
package/src/device/blindtilt.ts
CHANGED
|
@@ -1,116 +1,57 @@
|
|
|
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 {
|
|
3
|
-
import { MqttClient } from 'mqtt';
|
|
6
|
+
import { BlindTiltMappingMode } from '../utils.js';
|
|
4
7
|
import { interval, Subject } from 'rxjs';
|
|
5
|
-
import
|
|
8
|
+
import { deviceBase } from './device.js';
|
|
6
9
|
import { SwitchBotPlatform } from '../platform.js';
|
|
7
10
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
|
-
import { Service, PlatformAccessory, CharacteristicValue
|
|
9
|
-
import { device, devicesConfig, serviceData, deviceStatus, Devices
|
|
10
|
-
|
|
11
|
-
enum BlindTiltMappingMode {
|
|
12
|
-
OnlyUp = 'only_up',
|
|
13
|
-
OnlyDown = 'only_down',
|
|
14
|
-
DownAndUp = 'down_and_up',
|
|
15
|
-
UpAndDown = 'up_and_down',
|
|
16
|
-
UseTiltForDirection = 'use_tilt_for_direction',
|
|
17
|
-
}
|
|
11
|
+
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
12
|
+
import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../settings.js';
|
|
13
|
+
|
|
18
14
|
|
|
19
|
-
export class BlindTilt {
|
|
20
|
-
public readonly api: API;
|
|
21
|
-
public readonly log: Logging;
|
|
22
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
23
|
-
protected readonly hap: HAP;
|
|
15
|
+
export class BlindTilt extends deviceBase {
|
|
24
16
|
// Services
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
OpenAPI_Calibration: serviceData['calibration'];
|
|
45
|
-
OpenAPI_CurrentPosition: serviceData['position'];
|
|
46
|
-
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
47
|
-
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
17
|
+
private WindowCovering: {
|
|
18
|
+
Service: Service;
|
|
19
|
+
PositionState: CharacteristicValue;
|
|
20
|
+
TargetPosition: CharacteristicValue;
|
|
21
|
+
CurrentPosition: CharacteristicValue;
|
|
22
|
+
TargetHorizontalTiltAngle: CharacteristicValue;
|
|
23
|
+
CurrentHorizontalTiltAngle: CharacteristicValue;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
private Battery: {
|
|
27
|
+
Service: Service;
|
|
28
|
+
BatteryLevel: CharacteristicValue;
|
|
29
|
+
StatusLowBattery: CharacteristicValue;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
private LightSensor?: {
|
|
33
|
+
Service: Service;
|
|
34
|
+
CurrentAmbientLightLevel?: CharacteristicValue;
|
|
35
|
+
};
|
|
48
36
|
|
|
49
37
|
// OpenAPI Others
|
|
50
|
-
Mode!: string;
|
|
51
|
-
setPositionMode?: string | number;
|
|
52
38
|
mappingMode: BlindTiltMappingMode = BlindTiltMappingMode.OnlyUp;
|
|
53
39
|
|
|
54
|
-
// BLE Status
|
|
55
|
-
BLE_InMotion: serviceData['inMotion'];
|
|
56
|
-
BLE_BatteryLevel: serviceData['battery'];
|
|
57
|
-
BLE_Calibration: serviceData['calibration'];
|
|
58
|
-
BLE_CurrentPosition: serviceData['position'];
|
|
59
|
-
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
60
|
-
|
|
61
|
-
// BLE Others
|
|
62
|
-
BLE_IsConnected?: boolean;
|
|
63
|
-
spaceBetweenLevels!: number;
|
|
64
|
-
|
|
65
40
|
// Target
|
|
66
41
|
setNewTarget!: boolean;
|
|
67
42
|
setNewTargetTimer!: NodeJS.Timeout;
|
|
68
43
|
|
|
69
|
-
//MQTT stuff
|
|
70
|
-
mqttClient: MqttClient | null = null;
|
|
71
|
-
|
|
72
|
-
// Config
|
|
73
|
-
set_minStep!: number;
|
|
74
|
-
updateRate!: number;
|
|
75
|
-
set_minLux!: number;
|
|
76
|
-
set_maxLux!: number;
|
|
77
|
-
scanDuration!: number;
|
|
78
|
-
deviceLogging!: string;
|
|
79
|
-
deviceRefreshRate!: number;
|
|
80
|
-
setCloseMode!: string;
|
|
81
|
-
setOpenMode!: string;
|
|
82
|
-
maxRetries!: number;
|
|
83
|
-
delayBetweenRetries!: number;
|
|
84
|
-
|
|
85
44
|
// Updates
|
|
86
45
|
blindTiltUpdateInProgress!: boolean;
|
|
87
46
|
doBlindTiltUpdate!: Subject<void>;
|
|
88
47
|
|
|
89
|
-
// Connection
|
|
90
|
-
private readonly OpenAPI: boolean;
|
|
91
|
-
private readonly BLE: boolean;
|
|
92
|
-
|
|
93
48
|
constructor(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
49
|
+
readonly platform: SwitchBotPlatform,
|
|
50
|
+
accessory: PlatformAccessory,
|
|
51
|
+
device: device & devicesConfig,
|
|
97
52
|
) {
|
|
98
|
-
|
|
99
|
-
this.log = this.platform.log;
|
|
100
|
-
this.config = this.platform.config;
|
|
101
|
-
this.hap = this.api.hap;
|
|
102
|
-
// Connection
|
|
103
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
104
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
53
|
+
super(platform, accessory, device);
|
|
105
54
|
// default placeholders
|
|
106
|
-
this.deviceLogs(device);
|
|
107
|
-
this.refreshRate(device);
|
|
108
|
-
this.scan(device);
|
|
109
|
-
this.setupMqtt(device);
|
|
110
|
-
this.deviceContext();
|
|
111
|
-
this.deviceRetry(device);
|
|
112
|
-
this.deviceConfig(device);
|
|
113
|
-
|
|
114
55
|
this.mappingMode = (device.blindTilt?.mode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp;
|
|
115
56
|
this.debugLog(`Mapping mode: ${this.mappingMode}`);
|
|
116
57
|
|
|
@@ -122,30 +63,43 @@ export class BlindTilt {
|
|
|
122
63
|
// Retrieve initial values and updateHomekit
|
|
123
64
|
this.refreshStatus();
|
|
124
65
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
.
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
66
|
+
// Initialize LightBulb property
|
|
67
|
+
this.WindowCovering = {
|
|
68
|
+
Service: this.accessory.addService(this.hap.Service.WindowCovering),
|
|
69
|
+
PositionState: this.accessory.context.PositionState || this.hap.Characteristic.PositionState.STOPPED,
|
|
70
|
+
TargetPosition: this.accessory.context.TargetPosition || 100,
|
|
71
|
+
CurrentPosition: this.accessory.context.CurrentPosition || 100,
|
|
72
|
+
TargetHorizontalTiltAngle: this.accessory.context.TargetHorizontalTiltAngle || 0,
|
|
73
|
+
CurrentHorizontalTiltAngle: this.accessory.context.CurrentHorizontalTiltAngle || 0,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Initialize Battery property
|
|
77
|
+
this.Battery = {
|
|
78
|
+
Service: this.accessory.addService(this.hap.Service.Battery),
|
|
79
|
+
BatteryLevel: this.accessory.context.BatteryLevel || 100,
|
|
80
|
+
StatusLowBattery: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Initialize LightSensor property
|
|
84
|
+
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
85
|
+
this.LightSensor = {
|
|
86
|
+
Service: this.accessory.addService(this.hap.Service.LightSensor),
|
|
87
|
+
CurrentAmbientLightLevel: this.accessory.context.CurrentAmbientLightLevel || 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
132
90
|
|
|
133
91
|
// get the WindowCovering service if it exists, otherwise create a new WindowCovering service
|
|
134
92
|
// you can create multiple services for each accessory
|
|
135
|
-
|
|
136
|
-
(this.windowCoveringService =
|
|
93
|
+
(this.WindowCovering!.Service =
|
|
137
94
|
accessory.getService(this.hap.Service.WindowCovering)
|
|
138
|
-
|| accessory.addService(this.hap.Service.WindowCovering)),
|
|
95
|
+
|| accessory.addService(this.hap.Service.WindowCovering)), accessory.displayName;
|
|
139
96
|
|
|
140
|
-
this.
|
|
141
|
-
if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
142
|
-
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
143
|
-
}
|
|
97
|
+
this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
144
98
|
|
|
145
99
|
// create handlers for required characteristics
|
|
146
|
-
this.
|
|
100
|
+
this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
147
101
|
|
|
148
|
-
this.
|
|
102
|
+
this.WindowCovering!.Service
|
|
149
103
|
.getCharacteristic(this.hap.Characteristic.CurrentPosition)
|
|
150
104
|
.setProps({
|
|
151
105
|
minStep: this.minStep(device),
|
|
@@ -154,10 +108,10 @@ export class BlindTilt {
|
|
|
154
108
|
validValueRanges: [0, 100],
|
|
155
109
|
})
|
|
156
110
|
.onGet(() => {
|
|
157
|
-
return this.CurrentPosition;
|
|
111
|
+
return this.WindowCovering?.CurrentPosition ?? 0;
|
|
158
112
|
});
|
|
159
113
|
|
|
160
|
-
this.
|
|
114
|
+
this.WindowCovering!.Service
|
|
161
115
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
162
116
|
.setProps({
|
|
163
117
|
minStep: this.minStep(device),
|
|
@@ -167,8 +121,8 @@ export class BlindTilt {
|
|
|
167
121
|
})
|
|
168
122
|
.onSet(this.TargetPositionSet.bind(this));
|
|
169
123
|
|
|
170
|
-
this.CurrentHorizontalTiltAngle = 90;
|
|
171
|
-
this.
|
|
124
|
+
this.WindowCovering!.CurrentHorizontalTiltAngle = 90;
|
|
125
|
+
this.WindowCovering!.Service
|
|
172
126
|
.getCharacteristic(this.hap.Characteristic.CurrentHorizontalTiltAngle)
|
|
173
127
|
.setProps({
|
|
174
128
|
minStep: 180,
|
|
@@ -177,12 +131,12 @@ export class BlindTilt {
|
|
|
177
131
|
validValues: [-90, 90],
|
|
178
132
|
})
|
|
179
133
|
.onGet(() => {
|
|
180
|
-
// this.debugLog(`requested CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}`);
|
|
181
|
-
return this.CurrentHorizontalTiltAngle;
|
|
134
|
+
// this.debugLog(`requested CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
135
|
+
return this.WindowCovering.CurrentHorizontalTiltAngle ?? 0;
|
|
182
136
|
});
|
|
183
137
|
|
|
184
|
-
this.TargetHorizontalTiltAngle = 90;
|
|
185
|
-
this.
|
|
138
|
+
this.WindowCovering!.TargetHorizontalTiltAngle = 90;
|
|
139
|
+
this.WindowCovering!.Service
|
|
186
140
|
.getCharacteristic(this.hap.Characteristic.TargetHorizontalTiltAngle)
|
|
187
141
|
.setProps({
|
|
188
142
|
minStep: 180,
|
|
@@ -194,13 +148,10 @@ export class BlindTilt {
|
|
|
194
148
|
|
|
195
149
|
// Battery Service
|
|
196
150
|
const batteryService = `${accessory.displayName} Battery`;
|
|
197
|
-
(this.
|
|
151
|
+
(this.Battery.Service = this.accessory.getService(this.hap.Service.Battery)
|
|
198
152
|
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
199
153
|
|
|
200
|
-
this.
|
|
201
|
-
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
202
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
203
|
-
}
|
|
154
|
+
this.Battery!.Service.setCharacteristic(this.hap.Characteristic.Name, batteryService);
|
|
204
155
|
|
|
205
156
|
// Update Homekit
|
|
206
157
|
this.updateHomeKitCharacteristics();
|
|
@@ -217,17 +168,17 @@ export class BlindTilt {
|
|
|
217
168
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
218
169
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
219
170
|
try {
|
|
220
|
-
this.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
171
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
172
|
+
const { slidePosition, battery } = context;
|
|
173
|
+
const { CurrentPosition } = this.WindowCovering;
|
|
174
|
+
const { BatteryLevel } = this.Battery;
|
|
175
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
176
|
+
'(slidePosition, battery) = ' +
|
|
177
|
+
`Webhook:(${slidePosition}, ${battery}), ` +
|
|
178
|
+
`current:(${CurrentPosition}, ${BatteryLevel})`);
|
|
179
|
+
this.WindowCovering!.CurrentPosition = slidePosition;
|
|
180
|
+
this.Battery.BatteryLevel = battery;
|
|
181
|
+
this.updateHomeKitCharacteristics();
|
|
231
182
|
} catch (e: any) {
|
|
232
183
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
233
184
|
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -236,13 +187,14 @@ export class BlindTilt {
|
|
|
236
187
|
}
|
|
237
188
|
|
|
238
189
|
// update slide progress
|
|
239
|
-
interval(this.
|
|
190
|
+
interval(this.deviceUpdateRate * 1000)
|
|
240
191
|
//.pipe(skipWhile(() => this.blindTiltUpdateInProgress))
|
|
241
192
|
.subscribe(async () => {
|
|
242
|
-
if (this.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
193
|
+
if (this.WindowCovering!.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
243
194
|
return;
|
|
244
195
|
}
|
|
245
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving
|
|
196
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving,`
|
|
197
|
+
+ ` PositionState: ${this.WindowCovering!.PositionState}`);
|
|
246
198
|
await this.refreshStatus();
|
|
247
199
|
});
|
|
248
200
|
|
|
@@ -270,218 +222,219 @@ export class BlindTilt {
|
|
|
270
222
|
}
|
|
271
223
|
|
|
272
224
|
/**
|
|
273
|
-
* Parse the device status from the
|
|
225
|
+
* Parse the device status from the SwitchBotBLE API
|
|
274
226
|
*/
|
|
275
|
-
async
|
|
276
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
277
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
278
|
-
} else if (this.BLE) {
|
|
279
|
-
await this.BLEparseStatus();
|
|
280
|
-
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
281
|
-
await this.openAPIparseStatus();
|
|
282
|
-
} else {
|
|
283
|
-
await this.offlineOff();
|
|
284
|
-
this.debugWarnLog(
|
|
285
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
async BLEparseStatus(): Promise<void> {
|
|
227
|
+
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
291
228
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
292
229
|
// CurrentPosition
|
|
293
|
-
this.CurrentPosition = 100 - Number(
|
|
230
|
+
this.WindowCovering.CurrentPosition = 100 - Number(serviceData.position);
|
|
294
231
|
await this.setMinMax();
|
|
295
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
296
233
|
if (this.setNewTarget) {
|
|
297
234
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
298
235
|
}
|
|
299
236
|
|
|
300
|
-
if (this.setNewTarget &&
|
|
237
|
+
if (this.setNewTarget && serviceData.inMotion) {
|
|
301
238
|
await this.setMinMax();
|
|
302
|
-
if (Number(this.TargetPosition) > this.CurrentPosition) {
|
|
303
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
304
|
-
this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
305
|
-
this.
|
|
306
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.
|
|
310
|
-
this.
|
|
311
|
-
this.
|
|
239
|
+
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
240
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
241
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
242
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
243
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} INCREASING`
|
|
244
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
245
|
+
} else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
247
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
248
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
249
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} DECREASING`
|
|
250
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
312
251
|
} else {
|
|
313
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby2
|
|
314
|
-
|
|
315
|
-
this.
|
|
316
|
-
this.
|
|
252
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} Standby2,`
|
|
253
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
254
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
255
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
256
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} STOPPED`
|
|
257
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
317
258
|
}
|
|
318
259
|
} else {
|
|
319
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
|
|
320
|
-
this.TargetPosition = this.CurrentPosition;
|
|
321
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
260
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
261
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
262
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
322
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
323
264
|
}
|
|
324
265
|
this.debugLog(
|
|
325
|
-
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
326
|
-
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
266
|
+
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},` +
|
|
267
|
+
` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`,
|
|
327
268
|
);
|
|
328
269
|
|
|
329
270
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
271
|
+
const set_minLux = await this.minLux();
|
|
272
|
+
const set_maxLux = await this.maxLux();
|
|
273
|
+
const spaceBetweenLevels = 9;
|
|
333
274
|
|
|
334
275
|
// Brightness
|
|
335
|
-
switch (
|
|
276
|
+
switch (serviceData.lightLevel) {
|
|
336
277
|
case 1:
|
|
337
|
-
this.CurrentAmbientLightLevel =
|
|
338
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
278
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
279
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
339
280
|
break;
|
|
340
281
|
case 2:
|
|
341
|
-
this.CurrentAmbientLightLevel = (
|
|
282
|
+
this.LightSensor!.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
342
283
|
this.debugLog(
|
|
343
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
344
|
-
` Calculation: ${(
|
|
284
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},` +
|
|
285
|
+
` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`,
|
|
345
286
|
);
|
|
346
287
|
break;
|
|
347
288
|
case 3:
|
|
348
|
-
this.CurrentAmbientLightLevel = ((
|
|
349
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
289
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
290
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
350
291
|
break;
|
|
351
292
|
case 4:
|
|
352
|
-
this.CurrentAmbientLightLevel = ((
|
|
353
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
293
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
294
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
354
295
|
break;
|
|
355
296
|
case 5:
|
|
356
|
-
this.CurrentAmbientLightLevel = ((
|
|
357
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
297
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
298
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
358
299
|
break;
|
|
359
300
|
case 6:
|
|
360
|
-
this.CurrentAmbientLightLevel = ((
|
|
361
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
301
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
362
303
|
break;
|
|
363
304
|
case 7:
|
|
364
|
-
this.CurrentAmbientLightLevel = ((
|
|
365
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
305
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
306
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
366
307
|
break;
|
|
367
308
|
case 8:
|
|
368
|
-
this.CurrentAmbientLightLevel = ((
|
|
369
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
309
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
310
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
370
311
|
break;
|
|
371
312
|
case 9:
|
|
372
|
-
this.CurrentAmbientLightLevel = ((
|
|
373
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
313
|
+
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
314
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
374
315
|
break;
|
|
375
316
|
case 10:
|
|
376
317
|
default:
|
|
377
|
-
this.CurrentAmbientLightLevel =
|
|
318
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
378
319
|
this.debugLog();
|
|
379
320
|
}
|
|
380
321
|
this.debugLog(
|
|
381
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${
|
|
382
|
-
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
322
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},` +
|
|
323
|
+
` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`,
|
|
383
324
|
);
|
|
384
325
|
}
|
|
385
326
|
// Battery
|
|
386
|
-
this.BatteryLevel = Number(
|
|
387
|
-
if (this.BatteryLevel < 10) {
|
|
388
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
327
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
328
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
329
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
389
330
|
} else {
|
|
390
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
331
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
391
332
|
}
|
|
392
333
|
this.debugLog(
|
|
393
|
-
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
334
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
335
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`,
|
|
394
336
|
);
|
|
395
337
|
}
|
|
396
338
|
|
|
397
|
-
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Parse the device status from the SwitchBot OpenAPI
|
|
342
|
+
*/
|
|
343
|
+
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
398
344
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
399
345
|
|
|
400
|
-
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(
|
|
401
|
-
String(
|
|
402
|
-
this.debugLog(` device: ${
|
|
346
|
+
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(deviceStatus.body.slidePosition),
|
|
347
|
+
String(deviceStatus.body.direction));
|
|
348
|
+
this.debugLog(` device: ${deviceStatus.body.slidePosition} => HK: ${homekitPosition}`);
|
|
403
349
|
|
|
404
|
-
this.CurrentPosition = homekitPosition;
|
|
350
|
+
this.WindowCovering.CurrentPosition = homekitPosition;
|
|
405
351
|
// CurrentPosition
|
|
406
352
|
await this.setMinMax();
|
|
407
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
353
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
408
354
|
|
|
409
355
|
if (homekitTiltAngle) {
|
|
410
|
-
this.CurrentHorizontalTiltAngle = homekitTiltAngle!;
|
|
411
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
356
|
+
this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle!;
|
|
357
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
358
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
412
359
|
}
|
|
413
360
|
|
|
414
361
|
if (this.setNewTarget) {
|
|
415
362
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
416
363
|
}
|
|
417
364
|
|
|
418
|
-
if (this.setNewTarget &&
|
|
365
|
+
if (this.setNewTarget && deviceStatus.body.moving) {
|
|
419
366
|
await this.setMinMax();
|
|
420
|
-
if (this.TargetPosition > this.CurrentPosition
|
|
421
|
-
|
|
422
|
-
this.
|
|
423
|
-
this.
|
|
424
|
-
this.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
this.
|
|
429
|
-
this.
|
|
367
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
368
|
+
|| (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
369
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition} `);
|
|
370
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
371
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} INCREASING`
|
|
373
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
374
|
+
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
375
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition} `);
|
|
376
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
377
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
378
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} DECREASING`
|
|
379
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
430
380
|
} else {
|
|
431
381
|
this.debugLog(
|
|
432
|
-
`${this.device.deviceType}: ${this.CurrentPosition} Standby because reached position,`
|
|
382
|
+
`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} Standby because reached position,`
|
|
383
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`,
|
|
433
384
|
);
|
|
434
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
435
|
-
this.
|
|
436
|
-
this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED
|
|
385
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
386
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.WindowCovering.CurrentPosition} STOPPED`
|
|
388
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
437
389
|
}
|
|
438
390
|
} else {
|
|
439
391
|
this.debugLog(
|
|
440
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Standby because device not moving,`
|
|
392
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Standby because device not moving,`
|
|
393
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`,
|
|
441
394
|
);
|
|
442
|
-
this.TargetPosition = this.CurrentPosition;
|
|
395
|
+
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
443
396
|
if (homekitTiltAngle) {
|
|
444
|
-
this.TargetHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
397
|
+
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
445
398
|
}
|
|
446
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
399
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
447
400
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
|
|
448
401
|
}
|
|
449
402
|
this.debugLog(
|
|
450
|
-
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
|
|
451
|
-
` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`,
|
|
403
|
+
`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition},` +
|
|
404
|
+
` TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`,
|
|
452
405
|
);
|
|
453
406
|
|
|
454
407
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
455
|
-
|
|
456
|
-
|
|
408
|
+
const set_minLux = await this.minLux();
|
|
409
|
+
const set_maxLux = await this.maxLux();
|
|
457
410
|
// Brightness
|
|
458
|
-
switch (
|
|
411
|
+
switch (deviceStatus.body.brightness) {
|
|
459
412
|
case 'dim':
|
|
460
|
-
this.CurrentAmbientLightLevel =
|
|
413
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
461
414
|
break;
|
|
462
415
|
case 'bright':
|
|
463
416
|
default:
|
|
464
|
-
this.CurrentAmbientLightLevel =
|
|
417
|
+
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
465
418
|
}
|
|
466
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
419
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
420
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
467
421
|
}
|
|
468
422
|
|
|
469
423
|
// BatteryLevel
|
|
470
|
-
this.BatteryLevel = Number(
|
|
471
|
-
if (this.BatteryLevel < 10) {
|
|
472
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
424
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
425
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
426
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
473
427
|
} else {
|
|
474
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
428
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
475
429
|
}
|
|
476
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
477
|
-
this.BatteryLevel = 100;
|
|
430
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
431
|
+
this.Battery.BatteryLevel = 100;
|
|
478
432
|
}
|
|
479
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
480
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
433
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
434
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
481
435
|
|
|
482
436
|
// FirmwareRevision
|
|
483
|
-
this.FirmwareRevision =
|
|
484
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
437
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
485
438
|
}
|
|
486
439
|
|
|
487
440
|
async refreshStatus(): Promise<void> {
|
|
@@ -513,21 +466,13 @@ export class BlindTilt {
|
|
|
513
466
|
// Start to monitor advertisement packets
|
|
514
467
|
(async () => {
|
|
515
468
|
// Start to monitor advertisement packets
|
|
516
|
-
await switchbot.startScan({
|
|
517
|
-
model: 'x',
|
|
518
|
-
id: this.device.bleMac,
|
|
519
|
-
});
|
|
469
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
520
470
|
// Set an event handler
|
|
521
471
|
switchbot.onadvertisement = (ad: any) => {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
472
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
473
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
474
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
525
475
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
526
|
-
this.BLE_Calibration = ad.serviceData.calibration;
|
|
527
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
528
|
-
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
529
|
-
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
530
|
-
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
531
476
|
} else {
|
|
532
477
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
533
478
|
}
|
|
@@ -537,70 +482,19 @@ export class BlindTilt {
|
|
|
537
482
|
// Stop to monitor
|
|
538
483
|
await switchbot.stopScan();
|
|
539
484
|
// Update HomeKit
|
|
540
|
-
await this.BLEparseStatus();
|
|
485
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
541
486
|
await this.updateHomeKitCharacteristics();
|
|
542
487
|
})();
|
|
543
|
-
|
|
544
|
-
switchbot
|
|
545
|
-
.startScan({
|
|
546
|
-
model: 'c',
|
|
547
|
-
id: this.device.bleMac,
|
|
548
|
-
})
|
|
549
|
-
.then(async () => {
|
|
550
|
-
// Set an event handler
|
|
551
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
552
|
-
this.debugLog(
|
|
553
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
554
|
-
` BLE Address Found: ${ad.address}`,
|
|
555
|
-
);
|
|
556
|
-
this.BLE_Calibration = ad.serviceData.calibration;
|
|
557
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
558
|
-
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
559
|
-
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
560
|
-
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
561
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
562
|
-
this.debugLog(
|
|
563
|
-
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
564
|
-
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
565
|
-
`inMotion: ${ad.serviceData.inMotion}`,
|
|
566
|
-
);
|
|
567
|
-
|
|
568
|
-
if (ad.serviceData) {
|
|
569
|
-
this.BLE_IsConnected = true;
|
|
570
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
571
|
-
await this.stopScanning(switchbot);
|
|
572
|
-
} else {
|
|
573
|
-
this.BLE_IsConnected = false;
|
|
574
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
// Wait
|
|
578
|
-
return await sleep(this.scanDuration * 1000);
|
|
579
|
-
})
|
|
580
|
-
.then(async () => {
|
|
581
|
-
// Stop to monitor
|
|
582
|
-
await this.stopScanning(switchbot);
|
|
583
|
-
})
|
|
584
|
-
.catch(async (e: any) => {
|
|
585
|
-
this.apiError(e);
|
|
586
|
-
this.errorLog(
|
|
587
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
588
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
589
|
-
);
|
|
590
|
-
await this.BLERefreshConnection(switchbot);
|
|
591
|
-
});
|
|
592
|
-
} else {
|
|
488
|
+
if (switchbot === undefined) {
|
|
593
489
|
await this.BLERefreshConnection(switchbot);
|
|
594
|
-
}
|
|
490
|
+
}
|
|
595
491
|
}
|
|
596
492
|
|
|
597
493
|
async openAPIRefreshStatus(): Promise<void> {
|
|
598
494
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
599
495
|
try {
|
|
600
|
-
const { body, statusCode } = await this.platform.retryRequest(this.
|
|
601
|
-
`${Devices}/${this.device.deviceId}/status`, {
|
|
602
|
-
headers: this.platform.generateHeaders(),
|
|
603
|
-
});
|
|
496
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
497
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
604
498
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
605
499
|
const deviceStatus: any = await body.json();
|
|
606
500
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -608,13 +502,7 @@ export class BlindTilt {
|
|
|
608
502
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
609
503
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
610
504
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
611
|
-
this.
|
|
612
|
-
this.OpenAPI_Direction = deviceStatus.body.direction;
|
|
613
|
-
this.OpenAPI_InMotion = deviceStatus.body.moving;
|
|
614
|
-
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
615
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
616
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
617
|
-
this.openAPIparseStatus();
|
|
505
|
+
this.openAPIparseStatus(deviceStatus);
|
|
618
506
|
this.updateHomeKitCharacteristics();
|
|
619
507
|
} else {
|
|
620
508
|
this.statusCode(statusCode);
|
|
@@ -653,7 +541,7 @@ export class BlindTilt {
|
|
|
653
541
|
|
|
654
542
|
async BLEpushChanges(): Promise<void> {
|
|
655
543
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
656
|
-
if (this.TargetPosition !== this.CurrentPosition) {
|
|
544
|
+
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
657
545
|
const switchbot = await this.platform.connectBLE();
|
|
658
546
|
// Convert to BLE Address
|
|
659
547
|
this.device.bleMac = this.device
|
|
@@ -661,28 +549,24 @@ export class BlindTilt {
|
|
|
661
549
|
.join(':')
|
|
662
550
|
.toLowerCase();
|
|
663
551
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
664
|
-
this.
|
|
665
|
-
|
|
666
|
-
if (adjustedMode === null) {
|
|
667
|
-
this.Mode = 'Default Mode';
|
|
668
|
-
}
|
|
669
|
-
this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
552
|
+
const { setPositionMode, Mode }: { setPositionMode: number; Mode: string; } = await this.setPerformance();
|
|
553
|
+
this.debugLog(`${this.accessory.displayName} Mode: ${Mode}`);
|
|
670
554
|
if (switchbot !== false) {
|
|
671
555
|
switchbot
|
|
672
556
|
.discover({ model: 'c', quick: true, id: this.device.bleMac })
|
|
673
557
|
.then(async (device_list: any) => {
|
|
674
|
-
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
675
|
-
return await this.
|
|
676
|
-
max: this.
|
|
558
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.WindowCovering.TargetPosition}`);
|
|
559
|
+
return await this.retryBLE({
|
|
560
|
+
max: await this.maxRetryBLE(),
|
|
677
561
|
fn: async () => {
|
|
678
|
-
return await device_list[0].runToPos(100 - Number(this.TargetPosition),
|
|
562
|
+
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode);
|
|
679
563
|
},
|
|
680
564
|
});
|
|
681
565
|
})
|
|
682
566
|
.then(() => {
|
|
683
567
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
684
568
|
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
685
|
-
+ `Target Position: ${this.TargetPosition} sent over BLE, sent successfully`);
|
|
569
|
+
+ `Target Position: ${this.WindowCovering.TargetPosition} sent over BLE, sent successfully`);
|
|
686
570
|
})
|
|
687
571
|
.catch(async (e: any) => {
|
|
688
572
|
this.apiError(e);
|
|
@@ -699,39 +583,24 @@ export class BlindTilt {
|
|
|
699
583
|
} else {
|
|
700
584
|
this.debugLog(
|
|
701
585
|
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
|
|
702
|
-
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
586
|
+
` CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition ${this.WindowCovering.TargetPosition}`,
|
|
703
587
|
);
|
|
704
588
|
}
|
|
705
589
|
}
|
|
706
590
|
|
|
707
|
-
async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
|
|
708
|
-
return fn().catch(async (e: any) => {
|
|
709
|
-
if (max === 0) {
|
|
710
|
-
throw e;
|
|
711
|
-
}
|
|
712
|
-
this.infoLog(e);
|
|
713
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
714
|
-
await sleep(1000);
|
|
715
|
-
return this.retry({ max: max - 1, fn });
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
maxRetry(): number {
|
|
720
|
-
if (this.device.maxRetry) {
|
|
721
|
-
return this.device.maxRetry;
|
|
722
|
-
} else {
|
|
723
|
-
return 5;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
591
|
async openAPIpushChanges(): Promise<void> {
|
|
728
592
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
729
593
|
const hasDifferentAndRelevantHorizontalTiltAngle =
|
|
730
|
-
this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
this.
|
|
594
|
+
this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
595
|
+
&& this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
596
|
+
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition
|
|
597
|
+
|| hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
|
|
598
|
+
const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition),
|
|
599
|
+
Number(this.WindowCovering.TargetHorizontalTiltAngle));
|
|
600
|
+
const { Mode }: { setPositionMode: number; Mode: string; } = await this.setPerformance();
|
|
601
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
602
|
+
+ ` Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`);
|
|
603
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${Mode}`);
|
|
735
604
|
let bodyChange = '';
|
|
736
605
|
if (position === 100) {
|
|
737
606
|
bodyChange = JSON.stringify({
|
|
@@ -774,15 +643,16 @@ export class BlindTilt {
|
|
|
774
643
|
} catch (e: any) {
|
|
775
644
|
this.apiError(e);
|
|
776
645
|
this.errorLog(
|
|
777
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
778
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
646
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
647
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
779
648
|
);
|
|
780
649
|
}
|
|
781
650
|
} else {
|
|
782
651
|
this.debugLog(
|
|
783
|
-
`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
784
|
-
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`
|
|
785
|
-
` CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}
|
|
652
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
653
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition ${this.WindowCovering.TargetPosition}`
|
|
654
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle},`
|
|
655
|
+
+ ` TargetPosition ${this.WindowCovering.TargetHorizontalTiltAngle}`,
|
|
786
656
|
);
|
|
787
657
|
}
|
|
788
658
|
}
|
|
@@ -791,16 +661,16 @@ export class BlindTilt {
|
|
|
791
661
|
* Handle requests to set the value of the "Target Horizontal Tilt" characteristic
|
|
792
662
|
*/
|
|
793
663
|
async TargetHorizontalTiltAngleSet(value: CharacteristicValue): Promise<void> {
|
|
794
|
-
if (this.TargetHorizontalTiltAngle === this.accessory.context.TargetHorizontalTiltAngle) {
|
|
664
|
+
if (this.WindowCovering.TargetHorizontalTiltAngle === this.accessory.context.TargetHorizontalTiltAngle) {
|
|
795
665
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetHorizontalTiltAngle: ${value}`);
|
|
796
666
|
} else {
|
|
797
667
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHorizontalTiltAngle: ${value}`);
|
|
798
668
|
}
|
|
799
669
|
|
|
800
670
|
//value = value < 0 ? -90 : 90;
|
|
801
|
-
this.TargetHorizontalTiltAngle = value;
|
|
671
|
+
this.WindowCovering.TargetHorizontalTiltAngle = value;
|
|
802
672
|
if (this.device.mqttURL) {
|
|
803
|
-
this.mqttPublish('TargetHorizontalTiltAngle', this.TargetHorizontalTiltAngle);
|
|
673
|
+
this.mqttPublish('TargetHorizontalTiltAngle', this.WindowCovering.TargetHorizontalTiltAngle.toString());
|
|
804
674
|
}
|
|
805
675
|
|
|
806
676
|
this.startUpdatingBlindTiltIfNeeded();
|
|
@@ -810,15 +680,15 @@ export class BlindTilt {
|
|
|
810
680
|
* Handle requests to set the value of the "Target Position" characteristic
|
|
811
681
|
*/
|
|
812
682
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
813
|
-
if (this.TargetPosition === this.accessory.context.TargetPosition) {
|
|
683
|
+
if (this.WindowCovering.TargetPosition === this.accessory.context.TargetPosition) {
|
|
814
684
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set TargetPosition: ${value}`);
|
|
815
685
|
} else {
|
|
816
686
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
817
687
|
}
|
|
818
688
|
|
|
819
|
-
this.TargetPosition = value;
|
|
689
|
+
this.WindowCovering.TargetPosition = value;
|
|
820
690
|
if (this.device.mqttURL) {
|
|
821
|
-
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
691
|
+
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
822
692
|
}
|
|
823
693
|
this.startUpdatingBlindTiltIfNeeded();
|
|
824
694
|
}
|
|
@@ -826,39 +696,43 @@ export class BlindTilt {
|
|
|
826
696
|
async startUpdatingBlindTiltIfNeeded(): Promise<void> {
|
|
827
697
|
await this.setMinMax();
|
|
828
698
|
this.debugLog('setMinMax');
|
|
829
|
-
if (this.TargetPosition > this.CurrentPosition
|
|
830
|
-
this.
|
|
699
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
700
|
+
|| this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
|
|
701
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
831
702
|
this.setNewTarget = true;
|
|
832
703
|
this.debugLog(
|
|
833
|
-
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
704
|
+
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
705
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`,
|
|
834
706
|
);
|
|
835
|
-
} else if (this.TargetPosition < this.CurrentPosition) {
|
|
836
|
-
this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
707
|
+
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
708
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
837
709
|
this.setNewTarget = true;
|
|
838
710
|
this.debugLog(
|
|
839
|
-
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
711
|
+
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
712
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`,
|
|
840
713
|
);
|
|
841
714
|
} else {
|
|
842
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
715
|
+
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
843
716
|
this.setNewTarget = false;
|
|
844
717
|
this.debugLog(
|
|
845
|
-
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.CurrentPosition},`
|
|
718
|
+
`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.CurrentPosition},`
|
|
719
|
+
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`,
|
|
846
720
|
);
|
|
847
721
|
}
|
|
848
|
-
this.
|
|
849
|
-
this.
|
|
722
|
+
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
723
|
+
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
850
724
|
|
|
851
725
|
/**
|
|
852
726
|
* If Blind Tilt movement time is short, the moving flag from backend is always false.
|
|
853
727
|
* The minimum time depends on the network control latency.
|
|
854
728
|
*/
|
|
855
729
|
clearTimeout(this.setNewTargetTimer);
|
|
856
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.
|
|
730
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateRate: ${this.deviceUpdateRate}`);
|
|
857
731
|
if (this.setNewTarget) {
|
|
858
732
|
this.setNewTargetTimer = setTimeout(() => {
|
|
859
733
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
|
|
860
734
|
this.setNewTarget = false;
|
|
861
|
-
}, this.
|
|
735
|
+
}, this.deviceUpdateRate * 1000);
|
|
862
736
|
}
|
|
863
737
|
this.doBlindTiltUpdate.next();
|
|
864
738
|
}
|
|
@@ -867,152 +741,97 @@ export class BlindTilt {
|
|
|
867
741
|
await this.setMinMax();
|
|
868
742
|
// CurrentHorizontalTiltAngle
|
|
869
743
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
870
|
-
if (this.CurrentHorizontalTiltAngle === undefined || Number.isNaN(this.CurrentHorizontalTiltAngle)) {
|
|
871
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
744
|
+
if (this.WindowCovering.CurrentHorizontalTiltAngle === undefined || Number.isNaN(this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
745
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
746
|
+
+ ` CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
872
747
|
} else {
|
|
873
748
|
if (this.device.mqttURL) {
|
|
874
|
-
this.mqttPublish('CurrentHorizontalTiltAngle', this.CurrentHorizontalTiltAngle);
|
|
749
|
+
this.mqttPublish('CurrentHorizontalTiltAngle', this.WindowCovering.CurrentHorizontalTiltAngle.toString());
|
|
875
750
|
}
|
|
876
|
-
this.accessory.context.CurrentHorizontalTiltAngle = this.CurrentHorizontalTiltAngle;
|
|
877
|
-
this.
|
|
751
|
+
this.accessory.context.CurrentHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle;
|
|
752
|
+
this.WindowCovering.Service.updateCharacteristic(
|
|
878
753
|
this.hap.Characteristic.CurrentHorizontalTiltAngle,
|
|
879
|
-
Number(this.CurrentHorizontalTiltAngle),
|
|
754
|
+
Number(this.WindowCovering.CurrentHorizontalTiltAngle),
|
|
880
755
|
);
|
|
881
756
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
882
|
-
updateCharacteristic CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}`);
|
|
757
|
+
updateCharacteristic CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`);
|
|
883
758
|
}
|
|
884
759
|
}
|
|
885
760
|
// CurrentPosition
|
|
886
|
-
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
|
|
887
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
|
|
761
|
+
if (this.WindowCovering.CurrentPosition === undefined || Number.isNaN(this.WindowCovering.CurrentPosition)) {
|
|
762
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
888
763
|
} else {
|
|
889
764
|
if (this.device.mqttURL) {
|
|
890
|
-
this.mqttPublish('CurrentPosition', this.CurrentPosition);
|
|
765
|
+
this.mqttPublish('CurrentPosition', this.WindowCovering.CurrentPosition.toString());
|
|
891
766
|
}
|
|
892
|
-
this.accessory.context.CurrentPosition = this.CurrentPosition;
|
|
893
|
-
this.
|
|
894
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
767
|
+
this.accessory.context.CurrentPosition = this.WindowCovering.CurrentPosition;
|
|
768
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.WindowCovering.CurrentPosition));
|
|
769
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
770
|
+
+ ` updateCharacteristic CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
895
771
|
}
|
|
896
772
|
// PositionState
|
|
897
|
-
if (this.PositionState === undefined) {
|
|
898
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
|
|
773
|
+
if (this.WindowCovering.PositionState === undefined) {
|
|
774
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} PositionState: ${this.WindowCovering.PositionState}`);
|
|
899
775
|
} else {
|
|
900
776
|
if (this.device.mqttURL) {
|
|
901
|
-
this.mqttPublish('PositionState', this.PositionState);
|
|
777
|
+
this.mqttPublish('PositionState', this.WindowCovering.PositionState.toString());
|
|
902
778
|
}
|
|
903
|
-
this.accessory.context.PositionState = this.PositionState;
|
|
904
|
-
this.
|
|
905
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
779
|
+
this.accessory.context.PositionState = this.WindowCovering.PositionState;
|
|
780
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
|
|
781
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
782
|
+
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
906
783
|
}
|
|
907
784
|
// TargetPosition
|
|
908
|
-
if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
|
|
909
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
|
|
785
|
+
if (this.WindowCovering.TargetPosition === undefined || Number.isNaN(this.WindowCovering.TargetPosition)) {
|
|
786
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
910
787
|
} else {
|
|
911
788
|
if (this.device.mqttURL) {
|
|
912
|
-
this.mqttPublish('TargetPosition', this.TargetPosition);
|
|
789
|
+
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
913
790
|
}
|
|
914
|
-
this.accessory.context.TargetPosition = this.TargetPosition;
|
|
915
|
-
this.
|
|
916
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
791
|
+
this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
|
|
792
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
|
|
793
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
794
|
+
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
917
795
|
}
|
|
918
796
|
// CurrentAmbientLightLevel
|
|
919
797
|
if (!this.device.blindTilt?.hide_lightsensor) {
|
|
920
|
-
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
|
|
921
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
798
|
+
if (this.LightSensor!.CurrentAmbientLightLevel === undefined || Number.isNaN(this.LightSensor!.CurrentAmbientLightLevel)) {
|
|
799
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
800
|
+
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
922
801
|
} else {
|
|
923
802
|
if (this.device.mqttURL) {
|
|
924
|
-
this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
|
|
803
|
+
this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor!.CurrentAmbientLightLevel.toString());
|
|
925
804
|
}
|
|
926
|
-
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
927
|
-
this.
|
|
805
|
+
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor!.CurrentAmbientLightLevel;
|
|
806
|
+
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor!.CurrentAmbientLightLevel);
|
|
928
807
|
this.debugLog(
|
|
929
808
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
930
|
-
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
809
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`,
|
|
931
810
|
);
|
|
932
811
|
}
|
|
933
812
|
}
|
|
934
813
|
// BatteryLevel
|
|
935
|
-
if (this.BatteryLevel === undefined) {
|
|
936
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
814
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
815
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
937
816
|
} else {
|
|
938
817
|
if (this.device.mqttURL) {
|
|
939
|
-
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
818
|
+
this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
|
|
940
819
|
}
|
|
941
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
942
|
-
this.
|
|
943
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
820
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
821
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
822
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
944
823
|
}
|
|
945
824
|
// StatusLowBattery
|
|
946
|
-
if (this.StatusLowBattery === undefined) {
|
|
947
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
825
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
826
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
948
827
|
} else {
|
|
949
828
|
if (this.device.mqttURL) {
|
|
950
|
-
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
951
|
-
}
|
|
952
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
953
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
954
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
/*
|
|
959
|
-
* Publish MQTT message for topics of
|
|
960
|
-
* 'homebridge-switchbot/blindtilt/xx:xx:xx:xx:xx:xx'
|
|
961
|
-
*/
|
|
962
|
-
mqttPublish(topic: string, message: any) {
|
|
963
|
-
const mac = this.device.deviceId
|
|
964
|
-
?.toLowerCase()
|
|
965
|
-
.match(/[\s\S]{1,2}/g)
|
|
966
|
-
?.join(':');
|
|
967
|
-
const options = this.device.mqttPubOptions || {};
|
|
968
|
-
this.mqttClient?.publish(`homebridge-switchbot/blindtilt/${mac}/${topic}`, `${message}`, options);
|
|
969
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${JSON.stringify(options)}`);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
/*
|
|
973
|
-
* Setup MQTT hadler if URL is specified.
|
|
974
|
-
*/
|
|
975
|
-
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
976
|
-
if (device.mqttURL) {
|
|
977
|
-
try {
|
|
978
|
-
const { connectAsync } = asyncmqtt;
|
|
979
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
980
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
981
|
-
this.mqttClient.on('error', (e: Error) => {
|
|
982
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
983
|
-
});
|
|
984
|
-
} catch (e) {
|
|
985
|
-
this.mqttClient = null;
|
|
986
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
829
|
+
this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
|
|
987
830
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
switchbot.stopScan();
|
|
993
|
-
if (this.BLE_IsConnected) {
|
|
994
|
-
await this.BLEparseStatus();
|
|
995
|
-
await this.updateHomeKitCharacteristics();
|
|
996
|
-
} else {
|
|
997
|
-
await this.BLERefreshConnection(switchbot);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
async getCustomBLEAddress(switchbot: any) {
|
|
1002
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
1003
|
-
(async () => {
|
|
1004
|
-
// Start to monitor advertisement packets
|
|
1005
|
-
await switchbot.startScan({
|
|
1006
|
-
model: 'c',
|
|
1007
|
-
});
|
|
1008
|
-
// Set an event handler
|
|
1009
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
1010
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
1011
|
-
};
|
|
1012
|
-
await sleep(10000);
|
|
1013
|
-
// Stop to monitor
|
|
1014
|
-
switchbot.stopScan();
|
|
1015
|
-
})();
|
|
831
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
832
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
833
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
834
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1016
835
|
}
|
|
1017
836
|
}
|
|
1018
837
|
|
|
@@ -1032,221 +851,104 @@ export class BlindTilt {
|
|
|
1032
851
|
}
|
|
1033
852
|
}
|
|
1034
853
|
|
|
1035
|
-
async
|
|
1036
|
-
|
|
854
|
+
async setPerformance() {
|
|
855
|
+
let setPositionMode: number;
|
|
856
|
+
let Mode: string;
|
|
857
|
+
if (Number(this.WindowCovering.TargetPosition) > 50) {
|
|
1037
858
|
if (this.device.blindTilt?.setOpenMode === '1') {
|
|
1038
|
-
|
|
1039
|
-
|
|
859
|
+
setPositionMode = 1;
|
|
860
|
+
Mode = 'Silent Mode';
|
|
861
|
+
} else if (this.device.blindTilt?.setOpenMode === '0') {
|
|
862
|
+
setPositionMode = 0;
|
|
863
|
+
Mode = 'Performance Mode';
|
|
1040
864
|
} else {
|
|
1041
|
-
|
|
1042
|
-
|
|
865
|
+
setPositionMode = 0;
|
|
866
|
+
Mode = 'Default Mode';
|
|
1043
867
|
}
|
|
1044
868
|
} else {
|
|
1045
869
|
if (this.device.blindTilt?.setCloseMode === '1') {
|
|
1046
|
-
|
|
1047
|
-
|
|
870
|
+
setPositionMode = 1;
|
|
871
|
+
Mode = 'Silent Mode';
|
|
872
|
+
} else if (this.device.blindTilt?.setOpenMode === '0') {
|
|
873
|
+
setPositionMode = 0;
|
|
874
|
+
Mode = 'Performance Mode';
|
|
1048
875
|
} else {
|
|
1049
|
-
|
|
1050
|
-
|
|
876
|
+
setPositionMode = 0;
|
|
877
|
+
Mode = 'Default Mode';
|
|
1051
878
|
}
|
|
1052
879
|
}
|
|
880
|
+
return { setPositionMode, Mode };
|
|
1053
881
|
}
|
|
1054
882
|
|
|
1055
883
|
async setMinMax(): Promise<void> {
|
|
1056
884
|
if (this.device.blindTilt?.set_min) {
|
|
1057
|
-
if (Number(this.CurrentPosition) <= this.device.blindTilt?.set_min) {
|
|
1058
|
-
this.CurrentPosition = 0;
|
|
885
|
+
if (Number(this.WindowCovering.CurrentPosition) <= this.device.blindTilt?.set_min) {
|
|
886
|
+
this.WindowCovering.CurrentPosition = 0;
|
|
1059
887
|
}
|
|
1060
888
|
}
|
|
1061
889
|
if (this.device.blindTilt?.set_max) {
|
|
1062
|
-
if (Number(this.CurrentPosition) >= this.device.blindTilt?.set_max) {
|
|
1063
|
-
this.CurrentPosition = 100;
|
|
890
|
+
if (Number(this.WindowCovering.CurrentPosition) >= this.device.blindTilt?.set_max) {
|
|
891
|
+
this.WindowCovering.CurrentPosition = 100;
|
|
1064
892
|
}
|
|
1065
893
|
}
|
|
1066
894
|
|
|
1067
895
|
if (this.mappingMode === BlindTiltMappingMode.UseTiltForDirection) {
|
|
1068
|
-
this.CurrentHorizontalTiltAngle = Number(this.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
|
|
896
|
+
this.WindowCovering.CurrentHorizontalTiltAngle = Number(this.WindowCovering.CurrentHorizontalTiltAngle) < 0 ? -90 : 90;
|
|
1069
897
|
}
|
|
1070
898
|
}
|
|
1071
899
|
|
|
1072
900
|
minStep(device: device & devicesConfig): number {
|
|
901
|
+
let set_minStep: number;
|
|
1073
902
|
if (device.blindTilt?.set_minStep) {
|
|
1074
|
-
|
|
903
|
+
set_minStep = device.blindTilt?.set_minStep;
|
|
1075
904
|
} else {
|
|
1076
|
-
|
|
905
|
+
set_minStep = 1;
|
|
1077
906
|
}
|
|
1078
|
-
return
|
|
907
|
+
return set_minStep;
|
|
1079
908
|
}
|
|
1080
909
|
|
|
1081
|
-
minLux(): number {
|
|
910
|
+
async minLux(): Promise<number> {
|
|
911
|
+
let set_minLux: number;
|
|
1082
912
|
if (this.device.blindTilt?.set_minLux) {
|
|
1083
|
-
|
|
913
|
+
set_minLux = this.device.blindTilt?.set_minLux;
|
|
1084
914
|
} else {
|
|
1085
|
-
|
|
915
|
+
set_minLux = 1;
|
|
1086
916
|
}
|
|
1087
|
-
return
|
|
917
|
+
return set_minLux;
|
|
1088
918
|
}
|
|
1089
919
|
|
|
1090
|
-
maxLux(): number {
|
|
920
|
+
async maxLux(): Promise<number> {
|
|
921
|
+
let set_maxLux: number;
|
|
1091
922
|
if (this.device.blindTilt?.set_maxLux) {
|
|
1092
|
-
|
|
923
|
+
set_maxLux = this.device.blindTilt?.set_maxLux;
|
|
1093
924
|
} else {
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1096
|
-
return this.set_maxLux;
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
async scan(device: device & devicesConfig): Promise<void> {
|
|
1100
|
-
if (device.scanDuration) {
|
|
1101
|
-
if (this.updateRate > device.scanDuration) {
|
|
1102
|
-
this.scanDuration = this.updateRate;
|
|
1103
|
-
if (this.BLE) {
|
|
1104
|
-
this.warnLog(
|
|
1105
|
-
`${this.device.deviceType}: ` +
|
|
1106
|
-
`${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`,
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
} else {
|
|
1110
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1111
|
-
}
|
|
1112
|
-
if (this.BLE) {
|
|
1113
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1114
|
-
}
|
|
1115
|
-
} else {
|
|
1116
|
-
if (this.updateRate > 1) {
|
|
1117
|
-
this.scanDuration = this.updateRate;
|
|
1118
|
-
} else {
|
|
1119
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
1120
|
-
}
|
|
1121
|
-
if (this.BLE) {
|
|
1122
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
1128
|
-
switch (statusCode) {
|
|
1129
|
-
case 151:
|
|
1130
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
1131
|
-
break;
|
|
1132
|
-
case 152:
|
|
1133
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
1134
|
-
break;
|
|
1135
|
-
case 160:
|
|
1136
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
1137
|
-
break;
|
|
1138
|
-
case 161:
|
|
1139
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
1140
|
-
this.offlineOff();
|
|
1141
|
-
break;
|
|
1142
|
-
case 171:
|
|
1143
|
-
this.errorLog(
|
|
1144
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1145
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
1146
|
-
);
|
|
1147
|
-
this.offlineOff();
|
|
1148
|
-
break;
|
|
1149
|
-
case 190:
|
|
1150
|
-
this.errorLog(
|
|
1151
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1152
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
1153
|
-
);
|
|
1154
|
-
break;
|
|
1155
|
-
case 100:
|
|
1156
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
1157
|
-
break;
|
|
1158
|
-
case 200:
|
|
1159
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1160
|
-
break;
|
|
1161
|
-
case 400:
|
|
1162
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
1163
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
1164
|
-
break;
|
|
1165
|
-
case 401:
|
|
1166
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
1167
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
1168
|
-
break;
|
|
1169
|
-
case 403:
|
|
1170
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
1171
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
1172
|
-
break;
|
|
1173
|
-
case 404:
|
|
1174
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
1175
|
-
+ `statusCode: ${statusCode}`);
|
|
1176
|
-
break;
|
|
1177
|
-
case 406:
|
|
1178
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
1179
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
1180
|
-
break;
|
|
1181
|
-
case 415:
|
|
1182
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
1183
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
1184
|
-
break;
|
|
1185
|
-
case 422:
|
|
1186
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
1187
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
1188
|
-
break;
|
|
1189
|
-
case 429:
|
|
1190
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
1191
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
1192
|
-
break;
|
|
1193
|
-
case 500:
|
|
1194
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
1195
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
1196
|
-
break;
|
|
1197
|
-
default:
|
|
1198
|
-
this.infoLog(
|
|
1199
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1200
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
1201
|
-
);
|
|
925
|
+
set_maxLux = 6001;
|
|
1202
926
|
}
|
|
927
|
+
return set_maxLux;
|
|
1203
928
|
}
|
|
1204
929
|
|
|
1205
930
|
async offlineOff(): Promise<void> {
|
|
1206
931
|
if (this.device.offline) {
|
|
1207
|
-
|
|
1208
|
-
|
|
932
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
933
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
934
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
1209
935
|
}
|
|
1210
936
|
}
|
|
1211
937
|
|
|
1212
938
|
async apiError(e: any): Promise<void> {
|
|
1213
|
-
this.
|
|
1214
|
-
this.
|
|
1215
|
-
this.
|
|
939
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
940
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
941
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
1216
942
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
1217
|
-
this.
|
|
943
|
+
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
1218
944
|
}
|
|
1219
945
|
if (this.BLE) {
|
|
1220
|
-
this.
|
|
1221
|
-
this.
|
|
946
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
947
|
+
this.Battery?.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
1222
948
|
}
|
|
1223
949
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
1224
950
|
}
|
|
1225
951
|
|
|
1226
|
-
async deviceContext() {
|
|
1227
|
-
if (this.CurrentPosition === undefined) {
|
|
1228
|
-
this.CurrentPosition = 0;
|
|
1229
|
-
} else {
|
|
1230
|
-
this.CurrentPosition = this.accessory.context.CurrentPosition;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
if (this.TargetPosition === undefined) {
|
|
1234
|
-
this.TargetPosition = 0;
|
|
1235
|
-
} else {
|
|
1236
|
-
this.TargetPosition = this.accessory.context.TargetPosition;
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
if (this.PositionState === undefined) {
|
|
1240
|
-
this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
1241
|
-
} else {
|
|
1242
|
-
this.PositionState = this.accessory.context.PositionState;
|
|
1243
|
-
}
|
|
1244
|
-
if (this.FirmwareRevision === undefined) {
|
|
1245
|
-
this.FirmwareRevision = this.platform.version;
|
|
1246
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
952
|
/**
|
|
1251
953
|
* Maps device values to homekit values
|
|
1252
954
|
*
|
|
@@ -1366,159 +1068,4 @@ export class BlindTilt {
|
|
|
1366
1068
|
}
|
|
1367
1069
|
}
|
|
1368
1070
|
}
|
|
1369
|
-
|
|
1370
|
-
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
1371
|
-
// refreshRate
|
|
1372
|
-
if (device.refreshRate) {
|
|
1373
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1374
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1375
|
-
} else if (this.platform.config.options!.refreshRate) {
|
|
1376
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
1377
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1378
|
-
}
|
|
1379
|
-
// updateRate
|
|
1380
|
-
if (device?.blindTilt?.updateRate) {
|
|
1381
|
-
this.updateRate = device?.blindTilt?.updateRate;
|
|
1382
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Blind Tilt updateRate: ${this.updateRate}`);
|
|
1383
|
-
} else {
|
|
1384
|
-
this.updateRate = 2;
|
|
1385
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Blind Tilt updateRate: ${this.updateRate}`);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
1390
|
-
if (!device.maxRetries) {
|
|
1391
|
-
this.maxRetries = 5; // Maximum number of retries
|
|
1392
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
1393
|
-
} else {
|
|
1394
|
-
this.maxRetries = device.maxRetries;
|
|
1395
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
1396
|
-
}
|
|
1397
|
-
if (!device.delayBetweenRetries) {
|
|
1398
|
-
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
1399
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
1400
|
-
} else {
|
|
1401
|
-
this.delayBetweenRetries = device.delayBetweenRetries * 1000;
|
|
1402
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1407
|
-
let config = {};
|
|
1408
|
-
if (device.blindTilt) {
|
|
1409
|
-
config = device.blindTilt;
|
|
1410
|
-
}
|
|
1411
|
-
if (device.connectionType !== undefined) {
|
|
1412
|
-
config['connectionType'] = device.connectionType;
|
|
1413
|
-
}
|
|
1414
|
-
if (device.external !== undefined) {
|
|
1415
|
-
config['external'] = device.external;
|
|
1416
|
-
}
|
|
1417
|
-
if (device.mqttURL !== undefined) {
|
|
1418
|
-
config['mqttURL'] = device.mqttURL;
|
|
1419
|
-
}
|
|
1420
|
-
if (device.logging !== undefined) {
|
|
1421
|
-
config['logging'] = device.logging;
|
|
1422
|
-
}
|
|
1423
|
-
if (device.refreshRate !== undefined) {
|
|
1424
|
-
config['refreshRate'] = device.refreshRate;
|
|
1425
|
-
}
|
|
1426
|
-
if (device.scanDuration !== undefined) {
|
|
1427
|
-
config['scanDuration'] = device.scanDuration;
|
|
1428
|
-
}
|
|
1429
|
-
if (device.maxRetry !== undefined) {
|
|
1430
|
-
config['maxRetry'] = device.maxRetry;
|
|
1431
|
-
}
|
|
1432
|
-
if (device.webhook !== undefined) {
|
|
1433
|
-
config['webhook'] = device.webhook;
|
|
1434
|
-
}
|
|
1435
|
-
if (device.maxRetries !== undefined) {
|
|
1436
|
-
config['maxRetries'] = device.maxRetries;
|
|
1437
|
-
}
|
|
1438
|
-
if (device.delayBetweenRetries !== undefined) {
|
|
1439
|
-
config['delayBetweenRetries'] = device.delayBetweenRetries;
|
|
1440
|
-
}
|
|
1441
|
-
if (device.blindTilt?.mode === undefined) {
|
|
1442
|
-
config['mode'] = BlindTiltMappingMode.OnlyUp;
|
|
1443
|
-
} else {
|
|
1444
|
-
config['mode'] = device.blindTilt?.mode;
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
if (Object.entries(config).length !== 0) {
|
|
1448
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1453
|
-
if (this.platform.debugMode) {
|
|
1454
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1455
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1456
|
-
} else if (device.logging) {
|
|
1457
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1458
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1459
|
-
} else if (this.platform.config.options?.logging) {
|
|
1460
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1461
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1462
|
-
} else {
|
|
1463
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1464
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
/**
|
|
1469
|
-
* Logging for Device
|
|
1470
|
-
*/
|
|
1471
|
-
successLog(...log: any[]): void {
|
|
1472
|
-
if (this.enablingDeviceLogging()) {
|
|
1473
|
-
this.platform.log.success(String(...log));
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
infoLog(...log: any[]): void {
|
|
1478
|
-
if (this.enablingDeviceLogging()) {
|
|
1479
|
-
this.platform.log.info(String(...log));
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
warnLog(...log: any[]): void {
|
|
1484
|
-
if (this.enablingDeviceLogging()) {
|
|
1485
|
-
this.platform.log.warn(String(...log));
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
debugWarnLog(...log: any[]): void {
|
|
1490
|
-
if (this.enablingDeviceLogging()) {
|
|
1491
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1492
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
errorLog(...log: any[]): void {
|
|
1498
|
-
if (this.enablingDeviceLogging()) {
|
|
1499
|
-
this.platform.log.error(String(...log));
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
debugErrorLog(...log: any[]): void {
|
|
1504
|
-
if (this.enablingDeviceLogging()) {
|
|
1505
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1506
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
debugLog(...log: any[]): void {
|
|
1512
|
-
if (this.enablingDeviceLogging()) {
|
|
1513
|
-
if (this.deviceLogging === 'debug') {
|
|
1514
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1515
|
-
} else {
|
|
1516
|
-
this.platform.log.debug(String(...log));
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
enablingDeviceLogging(): boolean {
|
|
1522
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1523
|
-
}
|
|
1524
1071
|
}
|