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