@switchbot/homebridge-switchbot 1.3.1-beta.9 → 1.4.1-beta.2
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 +18 -2
- package/config.schema.json +82 -32
- package/dist/devices/bots.d.ts +15 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +227 -165
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +14 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +163 -105
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +102 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +180 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +14 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +173 -133
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +17 -13
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +150 -105
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +89 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +15 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +115 -53
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +13 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +97 -46
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +13 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +85 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +12 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +73 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +12 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +83 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +12 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +74 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +12 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +80 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +12 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +90 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +12 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +73 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +12 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +73 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -6
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +6 -6
- package/src/devices/bots.ts +221 -152
- package/src/devices/colorbulb.ts +172 -108
- package/src/devices/contact.ts +109 -64
- package/src/devices/curtains.ts +190 -146
- package/src/devices/humidifiers.ts +181 -135
- package/src/devices/meters.ts +156 -105
- package/src/devices/motion.ts +95 -45
- package/src/devices/plugs.ts +121 -53
- package/src/irdevices/airconditioners.ts +102 -46
- package/src/irdevices/airpurifiers.ts +91 -31
- package/src/irdevices/cameras.ts +79 -24
- package/src/irdevices/fans.ts +89 -36
- package/src/irdevices/lights.ts +80 -25
- package/src/irdevices/others.ts +86 -31
- package/src/irdevices/tvs.ts +96 -42
- package/src/irdevices/vacuumcleaners.ts +79 -24
- package/src/irdevices/waterheaters.ts +79 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +10 -6
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
|
@@ -18,12 +18,9 @@ class Humidifier {
|
|
|
18
18
|
this.platform = platform;
|
|
19
19
|
this.accessory = accessory;
|
|
20
20
|
this.device = device;
|
|
21
|
-
this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
|
|
22
|
-
this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
23
|
-
// Humidifiers Config
|
|
24
|
-
this.platform.device(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, hide_temperature: `
|
|
25
|
-
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
|
|
26
21
|
// default placeholders
|
|
22
|
+
this.refreshRate();
|
|
23
|
+
this.logs();
|
|
27
24
|
this.CurrentRelativeHumidity = 0;
|
|
28
25
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
29
26
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
@@ -31,6 +28,9 @@ class Humidifier {
|
|
|
31
28
|
this.RelativeHumidityHumidifierThreshold = 0;
|
|
32
29
|
this.CurrentTemperature = 0;
|
|
33
30
|
this.WaterLevel = 0;
|
|
31
|
+
// Humidifiers Config
|
|
32
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
|
|
33
|
+
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
|
|
34
34
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
35
35
|
this.doHumidifierUpdate = new rxjs_1.Subject();
|
|
36
36
|
this.humidifierUpdateInProgress = false;
|
|
@@ -79,12 +79,12 @@ class Humidifier {
|
|
|
79
79
|
// create a new Temperature Sensor service
|
|
80
80
|
// Temperature Sensor Service
|
|
81
81
|
if (device.humidifier?.hide_temperature || device.ble) {
|
|
82
|
-
this.
|
|
82
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
83
83
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
84
84
|
accessory.removeService(this.temperatureservice);
|
|
85
85
|
}
|
|
86
86
|
else if (!this.temperatureservice && !device.ble) {
|
|
87
|
-
this.
|
|
87
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
88
88
|
(this.temperatureservice =
|
|
89
89
|
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
90
90
|
this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
|
|
@@ -102,14 +102,12 @@ class Humidifier {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
|
-
|
|
106
|
-
this.platform.device(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
107
|
-
}
|
|
105
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
108
106
|
}
|
|
109
107
|
// Retrieve initial values and updateHomekit
|
|
110
108
|
this.updateHomeKitCharacteristics();
|
|
111
109
|
// Start an update interval
|
|
112
|
-
(0, rxjs_1.interval)(this.
|
|
110
|
+
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
113
111
|
.pipe((0, operators_1.skipWhile)(() => this.humidifierUpdateInProgress))
|
|
114
112
|
.subscribe(() => {
|
|
115
113
|
this.refreshStatus();
|
|
@@ -125,20 +123,39 @@ class Humidifier {
|
|
|
125
123
|
await this.pushChanges();
|
|
126
124
|
}
|
|
127
125
|
catch (e) {
|
|
128
|
-
this.
|
|
129
|
-
if (this.
|
|
130
|
-
this.
|
|
126
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
127
|
+
if (this.deviceLogging === 'debug') {
|
|
128
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
131
129
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
132
130
|
}
|
|
133
|
-
if (this.
|
|
134
|
-
this.
|
|
131
|
+
if (this.platform.debugMode) {
|
|
132
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
135
133
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
136
134
|
}
|
|
137
|
-
this.apiError(
|
|
135
|
+
this.apiError();
|
|
138
136
|
}
|
|
139
137
|
this.humidifierUpdateInProgress = false;
|
|
140
138
|
});
|
|
141
139
|
}
|
|
140
|
+
refreshRate() {
|
|
141
|
+
if (this.device.refreshRate) {
|
|
142
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
143
|
+
}
|
|
144
|
+
else if (this.platform.config.options.refreshRate) {
|
|
145
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
logs() {
|
|
149
|
+
if (this.device.logging) {
|
|
150
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
151
|
+
}
|
|
152
|
+
else if (this.platform.config.options?.logging) {
|
|
153
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
142
159
|
minStep() {
|
|
143
160
|
if (this.device.humidifier?.set_minStep) {
|
|
144
161
|
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
@@ -160,10 +177,10 @@ class Humidifier {
|
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
BLEparseStatus() {
|
|
163
|
-
this.
|
|
180
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
|
|
164
181
|
// Current Relative Humidity
|
|
165
182
|
this.CurrentRelativeHumidity = this.percentage;
|
|
166
|
-
this.
|
|
183
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
167
184
|
// Active
|
|
168
185
|
if (this.onState) {
|
|
169
186
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
@@ -171,18 +188,18 @@ class Humidifier {
|
|
|
171
188
|
else {
|
|
172
189
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
173
190
|
}
|
|
174
|
-
this.
|
|
191
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
175
192
|
}
|
|
176
193
|
openAPIparseStatus() {
|
|
177
194
|
if (this.platform.config.credentials?.openToken) {
|
|
178
|
-
this.
|
|
195
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
179
196
|
// Current Relative Humidity
|
|
180
197
|
this.CurrentRelativeHumidity = this.deviceStatus.body.humidity;
|
|
181
|
-
this.
|
|
198
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
182
199
|
// Current Temperature
|
|
183
200
|
if (!this.device.humidifier?.hide_temperature) {
|
|
184
201
|
this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
|
|
185
|
-
this.
|
|
202
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
186
203
|
}
|
|
187
204
|
// Target Humidifier Dehumidifier State
|
|
188
205
|
switch (this.deviceStatus.body.auto) {
|
|
@@ -209,10 +226,10 @@ class Humidifier {
|
|
|
209
226
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
229
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
230
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
214
231
|
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
215
|
-
this.
|
|
232
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
216
233
|
// Active
|
|
217
234
|
switch (this.deviceStatus.body.power) {
|
|
218
235
|
case 'on':
|
|
@@ -221,7 +238,7 @@ class Humidifier {
|
|
|
221
238
|
default:
|
|
222
239
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
223
240
|
}
|
|
224
|
-
this.
|
|
241
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
225
242
|
// Water Level
|
|
226
243
|
if (this.deviceStatus.body.lackWater) {
|
|
227
244
|
this.WaterLevel = 0;
|
|
@@ -229,7 +246,7 @@ class Humidifier {
|
|
|
229
246
|
else {
|
|
230
247
|
this.WaterLevel = 100;
|
|
231
248
|
}
|
|
232
|
-
this.
|
|
249
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
233
250
|
}
|
|
234
251
|
}
|
|
235
252
|
/**
|
|
@@ -246,11 +263,11 @@ class Humidifier {
|
|
|
246
263
|
connectBLE() {
|
|
247
264
|
const switchbot = new node_switchbot_1.default();
|
|
248
265
|
this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
|
|
249
|
-
this.
|
|
266
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
250
267
|
return switchbot;
|
|
251
268
|
}
|
|
252
269
|
async BLERefreshStatus() {
|
|
253
|
-
this.
|
|
270
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
254
271
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
255
272
|
const switchbot = this.connectBLE();
|
|
256
273
|
// Start to monitor advertisement packets
|
|
@@ -264,16 +281,16 @@ class Humidifier {
|
|
|
264
281
|
this.autoMode = ad.serviceData.autoMode;
|
|
265
282
|
this.onState = ad.serviceData.onState;
|
|
266
283
|
this.percentage = ad.serviceData.percentage;
|
|
267
|
-
this.
|
|
268
|
-
this.
|
|
284
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
285
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
|
|
269
286
|
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
|
|
270
287
|
if (this.serviceData) {
|
|
271
288
|
this.connected = true;
|
|
272
|
-
this.
|
|
289
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
273
290
|
}
|
|
274
291
|
else {
|
|
275
292
|
this.connected = false;
|
|
276
|
-
this.
|
|
293
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
277
294
|
}
|
|
278
295
|
};
|
|
279
296
|
// Wait 10 seconds
|
|
@@ -286,54 +303,54 @@ class Humidifier {
|
|
|
286
303
|
this.updateHomeKitCharacteristics();
|
|
287
304
|
}
|
|
288
305
|
else {
|
|
289
|
-
this.
|
|
306
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
290
307
|
if (this.platform.config.credentials?.openToken) {
|
|
291
|
-
this.
|
|
308
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
292
309
|
await this.openAPIRefreshStatus();
|
|
293
310
|
}
|
|
294
311
|
}
|
|
295
312
|
}).catch(async (e) => {
|
|
296
|
-
this.
|
|
297
|
-
if (this.
|
|
298
|
-
this.
|
|
313
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
314
|
+
if (this.deviceLogging === 'debug') {
|
|
315
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
299
316
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
300
317
|
}
|
|
301
|
-
if (this.
|
|
302
|
-
this.
|
|
318
|
+
if (this.platform.debugMode) {
|
|
319
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
303
320
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
304
321
|
}
|
|
305
322
|
if (this.platform.config.credentials?.openToken) {
|
|
306
|
-
this.
|
|
323
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
307
324
|
await this.openAPIRefreshStatus();
|
|
308
325
|
}
|
|
309
|
-
this.apiError(
|
|
326
|
+
this.apiError();
|
|
310
327
|
});
|
|
311
328
|
}
|
|
312
329
|
async openAPIRefreshStatus() {
|
|
313
330
|
if (this.platform.config.credentials?.openToken) {
|
|
314
|
-
this.
|
|
331
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
315
332
|
try {
|
|
316
333
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
317
334
|
if (this.deviceStatus.message === 'success') {
|
|
318
|
-
this.
|
|
335
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
319
336
|
this.parseStatus();
|
|
320
337
|
this.updateHomeKitCharacteristics();
|
|
321
338
|
}
|
|
322
339
|
else {
|
|
323
|
-
this.
|
|
340
|
+
this.debugLog(this.deviceStatus);
|
|
324
341
|
}
|
|
325
342
|
}
|
|
326
343
|
catch (e) {
|
|
327
|
-
this.
|
|
328
|
-
if (this.
|
|
329
|
-
this.
|
|
344
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
345
|
+
if (this.deviceLogging === 'debug') {
|
|
346
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
330
347
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
331
348
|
}
|
|
332
|
-
if (this.
|
|
333
|
-
this.
|
|
349
|
+
if (this.platform.debugMode) {
|
|
350
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
334
351
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
335
352
|
}
|
|
336
|
-
this.apiError(
|
|
353
|
+
this.apiError();
|
|
337
354
|
}
|
|
338
355
|
}
|
|
339
356
|
}
|
|
@@ -354,61 +371,61 @@ class Humidifier {
|
|
|
354
371
|
});
|
|
355
372
|
}
|
|
356
373
|
async BLEpushChanges() {
|
|
357
|
-
this.
|
|
374
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
358
375
|
const switchbot = this.connectBLE();
|
|
359
376
|
switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
360
|
-
this.
|
|
377
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
361
378
|
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
362
379
|
}).then(() => {
|
|
363
|
-
this.
|
|
380
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
|
|
364
381
|
}).catch(async (e) => {
|
|
365
|
-
this.
|
|
366
|
-
if (this.
|
|
367
|
-
this.
|
|
382
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
383
|
+
if (this.deviceLogging === 'debug') {
|
|
384
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
368
385
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
369
386
|
}
|
|
370
|
-
if (this.
|
|
371
|
-
this.
|
|
387
|
+
if (this.platform.debugMode) {
|
|
388
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
372
389
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
373
390
|
}
|
|
374
391
|
if (this.platform.config.credentials?.openToken) {
|
|
375
|
-
this.
|
|
392
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
376
393
|
await this.OpenAPIpushChanges();
|
|
377
394
|
}
|
|
378
|
-
this.apiError(
|
|
395
|
+
this.apiError();
|
|
379
396
|
});
|
|
380
397
|
}
|
|
381
398
|
async OpenAPIpushChanges() {
|
|
382
399
|
if (this.platform.config.credentials?.openToken) {
|
|
383
|
-
this.
|
|
400
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
384
401
|
if (this.TargetHumidifierDehumidifierState ===
|
|
385
402
|
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
386
403
|
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
387
404
|
try {
|
|
388
|
-
this.
|
|
405
|
+
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
389
406
|
const payload = {
|
|
390
407
|
commandType: 'command',
|
|
391
408
|
command: 'setMode',
|
|
392
409
|
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
393
410
|
};
|
|
394
|
-
this.
|
|
411
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
395
412
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
396
413
|
// Make the API request
|
|
397
414
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
398
|
-
this.
|
|
415
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
399
416
|
this.statusCode(push);
|
|
400
417
|
}
|
|
401
418
|
catch (e) {
|
|
402
|
-
this.
|
|
403
|
-
if (this.
|
|
404
|
-
this.
|
|
419
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
420
|
+
if (this.deviceLogging === 'debug') {
|
|
421
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
405
422
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
406
423
|
}
|
|
407
|
-
if (this.
|
|
408
|
-
this.
|
|
424
|
+
if (this.platform.debugMode) {
|
|
425
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
409
426
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
410
427
|
}
|
|
411
|
-
this.apiError(
|
|
428
|
+
this.apiError();
|
|
412
429
|
}
|
|
413
430
|
}
|
|
414
431
|
else if (this.TargetHumidifierDehumidifierState ===
|
|
@@ -429,31 +446,31 @@ class Humidifier {
|
|
|
429
446
|
if (this.TargetHumidifierDehumidifierState ===
|
|
430
447
|
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
431
448
|
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
432
|
-
this.
|
|
449
|
+
this.debugLog('Pushing Auto!');
|
|
433
450
|
const payload = {
|
|
434
451
|
commandType: 'command',
|
|
435
452
|
command: 'setMode',
|
|
436
453
|
parameter: 'auto',
|
|
437
454
|
};
|
|
438
|
-
this.
|
|
455
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
439
456
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
440
457
|
// Make the API request
|
|
441
458
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
442
|
-
this.
|
|
459
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
|
|
443
460
|
this.statusCode(push);
|
|
444
461
|
}
|
|
445
462
|
}
|
|
446
463
|
catch (e) {
|
|
447
|
-
this.
|
|
448
|
-
if (this.
|
|
449
|
-
this.
|
|
464
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
465
|
+
if (this.deviceLogging === 'debug') {
|
|
466
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
450
467
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
451
468
|
}
|
|
452
|
-
if (this.
|
|
453
|
-
this.
|
|
469
|
+
if (this.platform.debugMode) {
|
|
470
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
454
471
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
455
472
|
}
|
|
456
|
-
this.apiError(
|
|
473
|
+
this.apiError();
|
|
457
474
|
}
|
|
458
475
|
}
|
|
459
476
|
/**
|
|
@@ -462,31 +479,31 @@ class Humidifier {
|
|
|
462
479
|
async pushActiveChanges() {
|
|
463
480
|
try {
|
|
464
481
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
465
|
-
this.
|
|
482
|
+
this.debugLog('Pushing Off!');
|
|
466
483
|
const payload = {
|
|
467
484
|
commandType: 'command',
|
|
468
485
|
command: 'turnOff',
|
|
469
486
|
parameter: 'default',
|
|
470
487
|
};
|
|
471
|
-
this.
|
|
488
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
472
489
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
473
490
|
// Make the API request
|
|
474
491
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
475
|
-
this.
|
|
492
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
|
|
476
493
|
this.statusCode(push);
|
|
477
494
|
}
|
|
478
495
|
}
|
|
479
496
|
catch (e) {
|
|
480
|
-
this.
|
|
481
|
-
if (this.
|
|
482
|
-
this.
|
|
497
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
498
|
+
if (this.deviceLogging === 'debug') {
|
|
499
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
483
500
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
484
501
|
}
|
|
485
|
-
if (this.
|
|
486
|
-
this.
|
|
502
|
+
if (this.platform.debugMode) {
|
|
503
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
487
504
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
488
505
|
}
|
|
489
|
-
this.apiError(
|
|
506
|
+
this.apiError();
|
|
490
507
|
}
|
|
491
508
|
}
|
|
492
509
|
/**
|
|
@@ -494,116 +511,108 @@ class Humidifier {
|
|
|
494
511
|
*/
|
|
495
512
|
updateHomeKitCharacteristics() {
|
|
496
513
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
497
|
-
this.
|
|
514
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
498
515
|
}
|
|
499
516
|
else {
|
|
500
517
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
501
|
-
this.
|
|
518
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
502
519
|
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
503
520
|
}
|
|
504
521
|
if (!this.device.ble) {
|
|
505
522
|
if (this.WaterLevel === undefined) {
|
|
506
|
-
this.
|
|
523
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
507
524
|
}
|
|
508
525
|
else {
|
|
509
526
|
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
510
|
-
this.
|
|
527
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
511
528
|
}
|
|
512
529
|
}
|
|
513
530
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
514
|
-
this.
|
|
531
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
515
532
|
}
|
|
516
533
|
else {
|
|
517
534
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
518
|
-
this.
|
|
535
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
519
536
|
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
520
537
|
}
|
|
521
538
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
522
|
-
this.
|
|
539
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
523
540
|
}
|
|
524
541
|
else {
|
|
525
542
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
526
|
-
this.
|
|
543
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
527
544
|
+ ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
528
545
|
}
|
|
529
546
|
if (this.Active === undefined) {
|
|
530
|
-
this.
|
|
547
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
531
548
|
}
|
|
532
549
|
else {
|
|
533
550
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
534
|
-
this.
|
|
551
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
535
552
|
}
|
|
536
553
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
537
|
-
this.
|
|
554
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
538
555
|
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
539
556
|
}
|
|
540
557
|
else {
|
|
541
558
|
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
542
|
-
this.
|
|
559
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
543
560
|
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
544
561
|
}
|
|
545
562
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
546
563
|
if (this.CurrentTemperature === undefined) {
|
|
547
|
-
this.
|
|
564
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
548
565
|
}
|
|
549
566
|
else {
|
|
550
567
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
551
|
-
this.
|
|
568
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
552
569
|
}
|
|
553
570
|
}
|
|
554
571
|
}
|
|
555
|
-
apiError(
|
|
556
|
-
this.
|
|
557
|
-
if (!this.device.ble) {
|
|
558
|
-
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
559
|
-
}
|
|
560
|
-
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
561
|
-
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
562
|
-
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
563
|
-
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
564
|
-
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
565
|
-
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
566
|
-
}
|
|
572
|
+
apiError() {
|
|
573
|
+
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */);
|
|
567
574
|
}
|
|
568
575
|
statusCode(push) {
|
|
569
576
|
switch (push.data.statusCode) {
|
|
570
577
|
case 151:
|
|
571
|
-
this.
|
|
578
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
572
579
|
break;
|
|
573
580
|
case 152:
|
|
574
|
-
this.
|
|
581
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
|
|
575
582
|
break;
|
|
576
583
|
case 160:
|
|
577
|
-
this.
|
|
584
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
|
|
578
585
|
break;
|
|
579
586
|
case 161:
|
|
580
|
-
this.
|
|
581
|
-
|
|
582
|
-
this.Active = false;
|
|
583
|
-
}
|
|
587
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
|
|
588
|
+
this.offlineOff();
|
|
584
589
|
break;
|
|
585
590
|
case 171:
|
|
586
|
-
this.
|
|
587
|
-
|
|
588
|
-
this.Active = false;
|
|
589
|
-
}
|
|
591
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
592
|
+
this.offlineOff();
|
|
590
593
|
break;
|
|
591
594
|
case 190:
|
|
592
|
-
this.
|
|
595
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
593
596
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
594
597
|
break;
|
|
595
598
|
case 100:
|
|
596
|
-
this.
|
|
599
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
|
|
597
600
|
break;
|
|
598
601
|
default:
|
|
599
|
-
this.
|
|
602
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
offlineOff() {
|
|
606
|
+
if (this.device.offline) {
|
|
607
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
608
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
|
|
600
609
|
}
|
|
601
610
|
}
|
|
602
611
|
/**
|
|
603
612
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
604
613
|
*/
|
|
605
614
|
handleTargetHumidifierDehumidifierStateSet(value) {
|
|
606
|
-
this.
|
|
615
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
|
|
607
616
|
this.TargetHumidifierDehumidifierState = value;
|
|
608
617
|
this.doHumidifierUpdate.next();
|
|
609
618
|
}
|
|
@@ -611,7 +620,7 @@ class Humidifier {
|
|
|
611
620
|
* Handle requests to set the "Active" characteristic
|
|
612
621
|
*/
|
|
613
622
|
handleActiveSet(value) {
|
|
614
|
-
this.
|
|
623
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
|
|
615
624
|
this.Active = value;
|
|
616
625
|
this.doHumidifierUpdate.next();
|
|
617
626
|
}
|
|
@@ -619,7 +628,7 @@ class Humidifier {
|
|
|
619
628
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
620
629
|
*/
|
|
621
630
|
handleRelativeHumidityHumidifierThresholdSet(value) {
|
|
622
|
-
this.
|
|
631
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
623
632
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
624
633
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
625
634
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
@@ -627,6 +636,37 @@ class Humidifier {
|
|
|
627
636
|
}
|
|
628
637
|
this.doHumidifierUpdate.next();
|
|
629
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* Logging for Device
|
|
641
|
+
*/
|
|
642
|
+
infoLog(...log) {
|
|
643
|
+
if (this.enablingDeviceLogging()) {
|
|
644
|
+
this.platform.log.info(String(...log));
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
warnLog(...log) {
|
|
648
|
+
if (this.enablingDeviceLogging()) {
|
|
649
|
+
this.platform.log.warn(String(...log));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
errorLog(...log) {
|
|
653
|
+
if (this.enablingDeviceLogging()) {
|
|
654
|
+
this.platform.log.error(String(...log));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
debugLog(...log) {
|
|
658
|
+
if (this.enablingDeviceLogging()) {
|
|
659
|
+
if (this.deviceLogging === 'debug') {
|
|
660
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
this.platform.log.debug(String(...log));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
enablingDeviceLogging() {
|
|
668
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
669
|
+
}
|
|
630
670
|
}
|
|
631
671
|
exports.Humidifier = Humidifier;
|
|
632
672
|
//# sourceMappingURL=humidifiers.js.map
|