@switchbot/homebridge-switchbot 2.0.0-beta.3 → 2.0.0-beta.31
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 +8 -1
- package/README.md +1 -2
- package/config.schema.json +75 -20
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +655 -649
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +36 -19
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +483 -309
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +303 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +541 -498
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +450 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +302 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +340 -262
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +359 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +276 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +292 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +503 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +275 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +151 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +130 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +157 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +134 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +142 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +140 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +129 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +129 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +456 -434
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +16 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -10
- package/src/device/bot.ts +654 -660
- package/src/device/colorbulb.ts +487 -344
- package/src/device/contact.ts +306 -241
- package/src/device/curtain.ts +546 -512
- package/src/device/humidifier.ts +453 -403
- package/src/device/lock.ts +311 -149
- package/src/device/meter.ts +351 -275
- package/src/device/meterplus.ts +369 -219
- package/src/device/motion.ts +282 -222
- package/src/device/plug.ts +296 -260
- package/src/device/striplight.ts +519 -289
- package/src/irdevice/airconditioner.ts +279 -241
- package/src/irdevice/airpurifier.ts +148 -103
- package/src/irdevice/camera.ts +128 -85
- package/src/irdevice/fan.ts +154 -106
- package/src/irdevice/light.ts +132 -103
- package/src/irdevice/other.ts +140 -97
- package/src/irdevice/tv.ts +139 -93
- package/src/irdevice/vacuumcleaner.ts +128 -89
- package/src/irdevice/waterheater.ts +127 -89
- package/src/platform.ts +447 -457
- package/src/settings.ts +16 -11
package/src/device/humidifier.ts
CHANGED
|
@@ -3,6 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { Context } from 'vm';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
|
+
import superStringify from 'super-stringify';
|
|
6
7
|
import { SwitchBotPlatform } from '../platform';
|
|
7
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
@@ -54,19 +55,17 @@ export class Humidifier {
|
|
|
54
55
|
humidifierUpdateInProgress!: boolean;
|
|
55
56
|
doHumidifierUpdate!: Subject<void>;
|
|
56
57
|
|
|
58
|
+
// Connection
|
|
59
|
+
private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
|
|
60
|
+
private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
|
|
61
|
+
|
|
57
62
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
58
63
|
// default placeholders
|
|
59
64
|
this.logs(device);
|
|
60
65
|
this.scan(device);
|
|
61
66
|
this.refreshRate(device);
|
|
62
67
|
this.config(device);
|
|
63
|
-
this.
|
|
64
|
-
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
65
|
-
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
66
|
-
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
67
|
-
this.RelativeHumidityHumidifierThreshold = 0;
|
|
68
|
-
this.CurrentTemperature = 0;
|
|
69
|
-
this.WaterLevel = 0;
|
|
68
|
+
this.context();
|
|
70
69
|
|
|
71
70
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
72
71
|
this.doHumidifierUpdate = new Subject();
|
|
@@ -116,9 +115,9 @@ export class Humidifier {
|
|
|
116
115
|
maxValue: 1,
|
|
117
116
|
validValues: [0, 1],
|
|
118
117
|
})
|
|
119
|
-
.onSet(this.
|
|
118
|
+
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
120
119
|
|
|
121
|
-
this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.
|
|
120
|
+
this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
122
121
|
|
|
123
122
|
this.humidifierService
|
|
124
123
|
.getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
@@ -128,15 +127,15 @@ export class Humidifier {
|
|
|
128
127
|
maxValue: 100,
|
|
129
128
|
minStep: this.minStep(),
|
|
130
129
|
})
|
|
131
|
-
.onSet(this.
|
|
130
|
+
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
132
131
|
|
|
133
132
|
// Temperature Sensor Service
|
|
134
|
-
if (device.humidifier?.hide_temperature ||
|
|
135
|
-
this.debugLog(
|
|
133
|
+
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
134
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
136
135
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
137
136
|
accessory.removeService(this.temperatureservice!);
|
|
138
|
-
} else if (!this.temperatureservice && !
|
|
139
|
-
this.debugLog(
|
|
137
|
+
} else if (!this.temperatureservice && !this.BLE) {
|
|
138
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
140
139
|
(this.temperatureservice =
|
|
141
140
|
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
142
141
|
`${accessory.displayName} Temperature Sensor`;
|
|
@@ -155,7 +154,7 @@ export class Humidifier {
|
|
|
155
154
|
return this.CurrentTemperature;
|
|
156
155
|
});
|
|
157
156
|
} else {
|
|
158
|
-
this.debugLog(
|
|
157
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
// Retrieve initial values and updateHomekit
|
|
@@ -181,11 +180,9 @@ export class Humidifier {
|
|
|
181
180
|
try {
|
|
182
181
|
await this.pushChanges();
|
|
183
182
|
} catch (e: any) {
|
|
184
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
185
|
-
if (this.deviceLogging.includes('debug')) {
|
|
186
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
187
|
-
}
|
|
188
183
|
this.apiError(e);
|
|
184
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
185
|
+
+ ` Error Message: ${superStringify(e.message)}`);
|
|
189
186
|
}
|
|
190
187
|
this.humidifierUpdateInProgress = false;
|
|
191
188
|
});
|
|
@@ -195,104 +192,112 @@ export class Humidifier {
|
|
|
195
192
|
* Parse the device status from the SwitchBot api
|
|
196
193
|
*/
|
|
197
194
|
async parseStatus(): Promise<void> {
|
|
198
|
-
if (this.
|
|
195
|
+
if (this.BLE) {
|
|
199
196
|
await this.BLEparseStatus();
|
|
200
|
-
} else {
|
|
197
|
+
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
201
198
|
await this.openAPIparseStatus();
|
|
199
|
+
} else {
|
|
200
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
201
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
async BLEparseStatus(): Promise<void> {
|
|
206
|
-
this.debugLog(
|
|
206
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
207
207
|
// Current Relative Humidity
|
|
208
208
|
this.CurrentRelativeHumidity = this.percentage!;
|
|
209
|
-
this.debugLog(
|
|
209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
210
210
|
// Active
|
|
211
211
|
if (this.onState) {
|
|
212
212
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
213
213
|
} else {
|
|
214
214
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
215
215
|
}
|
|
216
|
-
this.debugLog(
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
async openAPIparseStatus(): Promise<void> {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
220
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
221
|
+
// Current Relative Humidity
|
|
222
|
+
this.CurrentRelativeHumidity = this.humidity!;
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
224
|
+
// Current Temperature
|
|
225
|
+
if (!this.device.humidifier?.hide_temperature) {
|
|
226
|
+
this.CurrentTemperature = this.temperature!;
|
|
227
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
228
|
+
}
|
|
229
|
+
// Target Humidifier Dehumidifier State
|
|
230
|
+
switch (this.auto) {
|
|
231
|
+
case true:
|
|
232
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
233
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
234
|
+
this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
|
|
235
|
+
break;
|
|
236
|
+
default:
|
|
237
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
238
|
+
if (this.nebulizationEfficiency! > 100) {
|
|
239
|
+
this.RelativeHumidityHumidifierThreshold = 100;
|
|
240
|
+
} else {
|
|
241
|
+
this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
|
|
242
|
+
}
|
|
243
|
+
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
244
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
245
|
+
} else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
246
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
247
|
+
} else {
|
|
234
248
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
235
|
-
|
|
236
|
-
break;
|
|
237
|
-
default:
|
|
238
|
-
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
239
|
-
if (this.nebulizationEfficiency! > 100) {
|
|
240
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
241
|
-
} else {
|
|
242
|
-
this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
|
|
243
|
-
}
|
|
244
|
-
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
245
|
-
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
246
|
-
} else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
247
|
-
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
248
|
-
} else {
|
|
249
|
-
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
253
|
-
this.debugLog(
|
|
254
|
-
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
255
|
-
);
|
|
256
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
257
|
-
// Active
|
|
258
|
-
switch (this.power) {
|
|
259
|
-
case 'on':
|
|
260
|
-
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
261
|
-
break;
|
|
262
|
-
default:
|
|
263
|
-
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
264
|
-
}
|
|
265
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
266
|
-
// Water Level
|
|
267
|
-
if (this.lackWater) {
|
|
268
|
-
this.WaterLevel = 0;
|
|
269
|
-
} else {
|
|
270
|
-
this.WaterLevel = 100;
|
|
271
|
-
}
|
|
272
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
249
|
+
}
|
|
273
250
|
}
|
|
251
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
252
|
+
+ ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
253
|
+
this.debugLog(
|
|
254
|
+
`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
255
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
256
|
+
);
|
|
257
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
258
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
259
|
+
// Active
|
|
260
|
+
switch (this.power) {
|
|
261
|
+
case 'on':
|
|
262
|
+
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
266
|
+
}
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
268
|
+
// Water Level
|
|
269
|
+
if (this.lackWater) {
|
|
270
|
+
this.WaterLevel = 0;
|
|
271
|
+
} else {
|
|
272
|
+
this.WaterLevel = 100;
|
|
273
|
+
}
|
|
274
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
275
|
+
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
/**
|
|
277
279
|
* Asks the SwitchBot API for the latest device information
|
|
278
280
|
*/
|
|
279
281
|
async refreshStatus(): Promise<void> {
|
|
280
|
-
if (this.
|
|
282
|
+
if (this.BLE) {
|
|
281
283
|
await this.BLERefreshStatus();
|
|
282
|
-
} else {
|
|
284
|
+
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
283
285
|
await this.openAPIRefreshStatus();
|
|
286
|
+
} else {
|
|
287
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
288
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
291
|
|
|
287
292
|
async BLERefreshStatus(): Promise<void> {
|
|
288
|
-
this.debugLog(
|
|
293
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
289
294
|
const switchbot = await this.platform.connectBLE();
|
|
290
295
|
// Convert to BLE Address
|
|
291
296
|
this.device.bleMac = this.device
|
|
292
297
|
.deviceId!.match(/.{1,2}/g)!
|
|
293
298
|
.join(':')
|
|
294
299
|
.toLowerCase();
|
|
295
|
-
this.debugLog(
|
|
300
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
296
301
|
this.getCustomBLEAddress(switchbot);
|
|
297
302
|
// Start to monitor advertisement packets
|
|
298
303
|
if (switchbot !== false) {
|
|
@@ -305,28 +310,24 @@ export class Humidifier {
|
|
|
305
310
|
// Set an event hander
|
|
306
311
|
switchbot.onadvertisement = (ad: ad) => {
|
|
307
312
|
this.address = ad.address;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this.infoLog(this.device.bleMac);
|
|
311
|
-
this.infoLog(`Humidifier: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
312
|
-
this.infoLog(`Humidifier: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
313
|
-
}
|
|
313
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
314
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
314
315
|
this.serviceData = ad.serviceData;
|
|
315
316
|
this.autoMode = ad.serviceData.autoMode;
|
|
316
317
|
this.onState = ad.serviceData.onState;
|
|
317
318
|
this.percentage = ad.serviceData.percentage;
|
|
318
|
-
this.debugLog(
|
|
319
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
319
320
|
this.debugLog(
|
|
320
|
-
|
|
321
|
+
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
321
322
|
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
322
323
|
);
|
|
323
324
|
|
|
324
325
|
if (this.serviceData) {
|
|
325
326
|
this.connected = true;
|
|
326
|
-
this.debugLog(
|
|
327
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
327
328
|
} else {
|
|
328
329
|
this.connected = false;
|
|
329
|
-
this.debugLog(
|
|
330
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
330
331
|
}
|
|
331
332
|
};
|
|
332
333
|
// Wait 2 seconds
|
|
@@ -336,117 +337,77 @@ export class Humidifier {
|
|
|
336
337
|
// Stop to monitor
|
|
337
338
|
switchbot.stopScan();
|
|
338
339
|
if (this.connected) {
|
|
339
|
-
this.
|
|
340
|
+
this.BLEparseStatus();
|
|
340
341
|
this.updateHomeKitCharacteristics();
|
|
341
342
|
} else {
|
|
342
|
-
await this.
|
|
343
|
+
await this.BLERefreshConnection(switchbot);
|
|
343
344
|
}
|
|
344
345
|
})
|
|
345
346
|
.catch(async (e: any) => {
|
|
346
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
347
|
-
if (this.deviceLogging.includes('debug')) {
|
|
348
|
-
this.errorLog(
|
|
349
|
-
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
if (this.platform.config.credentials?.token) {
|
|
353
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
354
|
-
await this.openAPIRefreshStatus();
|
|
355
|
-
}
|
|
356
347
|
this.apiError(e);
|
|
348
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
349
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
350
|
+
await this.BLERefreshConnection(switchbot);
|
|
357
351
|
});
|
|
358
352
|
} else {
|
|
359
|
-
await this.
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
async getCustomBLEAddress(switchbot: any) {
|
|
364
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
365
|
-
(async () => {
|
|
366
|
-
// Start to monitor advertisement packets
|
|
367
|
-
await switchbot.startScan({
|
|
368
|
-
model: 'e',
|
|
369
|
-
});
|
|
370
|
-
// Set an event handler
|
|
371
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
372
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
373
|
-
};
|
|
374
|
-
await switchbot.wait(10000);
|
|
375
|
-
// Stop to monitor
|
|
376
|
-
switchbot.stopScan();
|
|
377
|
-
})();
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
async BLEconnection(switchbot: any): Promise<void> {
|
|
382
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
383
|
-
if (this.platform.config.credentials?.token) {
|
|
384
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
385
|
-
await this.openAPIRefreshStatus();
|
|
353
|
+
await this.BLERefreshConnection(switchbot);
|
|
386
354
|
}
|
|
387
355
|
}
|
|
388
356
|
|
|
389
357
|
async openAPIRefreshStatus(): Promise<void> {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
|
|
418
|
-
});
|
|
419
|
-
res.on('end', () => {
|
|
420
|
-
try {
|
|
421
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
422
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
423
|
-
this.auto = this.deviceStatus.body.auto;
|
|
424
|
-
this.power = this.deviceStatus.body.power;
|
|
425
|
-
this.lackWater = this.deviceStatus.body.lackWater;
|
|
426
|
-
this.humidity = this.deviceStatus.body.humidity;
|
|
427
|
-
this.temperature = this.deviceStatus.body.temperature;
|
|
428
|
-
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
429
|
-
this.parseStatus();
|
|
430
|
-
this.updateHomeKitCharacteristics();
|
|
431
|
-
} catch (e: any) {
|
|
432
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
358
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
359
|
+
try {
|
|
360
|
+
const t = Date.now();
|
|
361
|
+
const nonce = 'requestID';
|
|
362
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
363
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
364
|
+
const sign = signTerm.toString('base64');
|
|
365
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
366
|
+
const options = {
|
|
367
|
+
hostname: HostDomain,
|
|
368
|
+
port: 443,
|
|
369
|
+
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
370
|
+
method: 'GET',
|
|
371
|
+
headers: {
|
|
372
|
+
Authorization: this.platform.config.credentials?.token,
|
|
373
|
+
sign: sign,
|
|
374
|
+
nonce: nonce,
|
|
375
|
+
t: t,
|
|
376
|
+
'Content-Type': 'application/json',
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
const req = https.request(options, (res) => {
|
|
380
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
381
|
+
let rawData = '';
|
|
382
|
+
res.on('data', (d) => {
|
|
383
|
+
rawData += d;
|
|
384
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
435
385
|
});
|
|
436
|
-
|
|
437
|
-
|
|
386
|
+
res.on('end', () => {
|
|
387
|
+
try {
|
|
388
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
389
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
390
|
+
this.auto = this.deviceStatus.body.auto;
|
|
391
|
+
this.power = this.deviceStatus.body.power;
|
|
392
|
+
this.lackWater = this.deviceStatus.body.lackWater;
|
|
393
|
+
this.humidity = this.deviceStatus.body.humidity;
|
|
394
|
+
this.temperature = this.deviceStatus.body.temperature;
|
|
395
|
+
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
396
|
+
this.openAPIparseStatus();
|
|
397
|
+
this.updateHomeKitCharacteristics();
|
|
398
|
+
} catch (e: any) {
|
|
399
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
400
|
+
}
|
|
438
401
|
});
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
this.errorLog(
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this.apiError(e);
|
|
449
|
-
}
|
|
402
|
+
});
|
|
403
|
+
req.on('error', (e: any) => {
|
|
404
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
405
|
+
});
|
|
406
|
+
req.end();
|
|
407
|
+
} catch (e: any) {
|
|
408
|
+
this.apiError(e);
|
|
409
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
410
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
450
411
|
}
|
|
451
412
|
}
|
|
452
413
|
|
|
@@ -454,11 +415,14 @@ export class Humidifier {
|
|
|
454
415
|
* Pushes the requested changes to the SwitchBot API
|
|
455
416
|
*/
|
|
456
417
|
async pushChanges(): Promise<void> {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
418
|
+
/*if (this.BLE) {
|
|
419
|
+
await this.BLERefreshStatus();
|
|
420
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
421
|
+
await this.openAPIpushChanges();
|
|
422
|
+
} else {
|
|
423
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
424
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
425
|
+
}
|
|
462
426
|
interval(5000)
|
|
463
427
|
.pipe(take(1))
|
|
464
428
|
.subscribe(async () => {
|
|
@@ -467,54 +431,41 @@ export class Humidifier {
|
|
|
467
431
|
}
|
|
468
432
|
|
|
469
433
|
async BLEpushChanges(): Promise<void> {
|
|
470
|
-
this.debugLog(
|
|
434
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
471
435
|
const switchbot = await this.platform.connectBLE();
|
|
472
436
|
// Convert to BLE Address
|
|
473
437
|
this.device.bleMac = this.device
|
|
474
438
|
.deviceId!.match(/.{1,2}/g)!
|
|
475
439
|
.join(':')
|
|
476
440
|
.toLowerCase();
|
|
477
|
-
this.debugLog(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
.
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
await this.openAPIpushChanges();
|
|
498
|
-
}
|
|
499
|
-
this.apiError(e);
|
|
500
|
-
});
|
|
501
|
-
} else {
|
|
502
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
503
|
-
if (this.platform.config.credentials?.token) {
|
|
504
|
-
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
505
|
-
await this.openAPIpushChanges();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
441
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
442
|
+
switchbot
|
|
443
|
+
.discover({
|
|
444
|
+
model: 'e',
|
|
445
|
+
quick: true,
|
|
446
|
+
id: this.device.bleMac,
|
|
447
|
+
})
|
|
448
|
+
.then((device_list: any) => {
|
|
449
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
450
|
+
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
451
|
+
})
|
|
452
|
+
.then(() => {
|
|
453
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
454
|
+
})
|
|
455
|
+
.catch(async (e: any) => {
|
|
456
|
+
this.apiError(e);
|
|
457
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
458
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
459
|
+
await this.BLEPushConnection();
|
|
460
|
+
});
|
|
508
461
|
}
|
|
509
462
|
|
|
510
463
|
async openAPIpushChanges(): Promise<void> {
|
|
511
|
-
|
|
512
|
-
this.debugLog(
|
|
513
|
-
if (
|
|
514
|
-
this.
|
|
515
|
-
|
|
516
|
-
) {
|
|
517
|
-
// Make Push On request to the API
|
|
464
|
+
try {
|
|
465
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
466
|
+
if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
467
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
468
|
+
// Make Push On request to the API
|
|
518
469
|
const t = Date.now();
|
|
519
470
|
const nonce = 'requestID';
|
|
520
471
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
@@ -522,14 +473,14 @@ export class Humidifier {
|
|
|
522
473
|
.update(Buffer.from(data, 'utf-8'))
|
|
523
474
|
.digest();
|
|
524
475
|
const sign = signTerm.toString('base64');
|
|
525
|
-
this.debugLog(
|
|
476
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
526
477
|
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
527
|
-
const body =
|
|
478
|
+
const body = superStringify({
|
|
528
479
|
'command': 'setMode',
|
|
529
480
|
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
530
481
|
'commandType': 'command',
|
|
531
482
|
});
|
|
532
|
-
this.infoLog(
|
|
483
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
533
484
|
const options = {
|
|
534
485
|
hostname: HostDomain,
|
|
535
486
|
port: 443,
|
|
@@ -545,18 +496,18 @@ export class Humidifier {
|
|
|
545
496
|
},
|
|
546
497
|
};
|
|
547
498
|
const req = https.request(options, res => {
|
|
548
|
-
this.debugLog(
|
|
499
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
549
500
|
res.on('data', d => {
|
|
550
|
-
this.debugLog(
|
|
501
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
551
502
|
});
|
|
552
503
|
});
|
|
553
504
|
req.on('error', (e: any) => {
|
|
554
|
-
this.errorLog(
|
|
505
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
555
506
|
this.apiError(e);
|
|
556
507
|
});
|
|
557
508
|
req.write(body);
|
|
558
509
|
req.end();
|
|
559
|
-
this.debugLog(
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
560
511
|
} else if (
|
|
561
512
|
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
562
513
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
@@ -565,6 +516,10 @@ export class Humidifier {
|
|
|
565
516
|
} else {
|
|
566
517
|
await this.pushActiveChanges();
|
|
567
518
|
}
|
|
519
|
+
} catch (e: any) {
|
|
520
|
+
this.apiError(e);
|
|
521
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
522
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
568
523
|
}
|
|
569
524
|
}
|
|
570
525
|
|
|
@@ -573,6 +528,7 @@ export class Humidifier {
|
|
|
573
528
|
*/
|
|
574
529
|
async pushAutoChanges(): Promise<void> {
|
|
575
530
|
try {
|
|
531
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
576
532
|
if (
|
|
577
533
|
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
578
534
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
@@ -585,14 +541,14 @@ export class Humidifier {
|
|
|
585
541
|
.update(Buffer.from(data, 'utf-8'))
|
|
586
542
|
.digest();
|
|
587
543
|
const sign = signTerm.toString('base64');
|
|
588
|
-
this.debugLog(
|
|
544
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
589
545
|
this.debugLog('Pushing Auto!');
|
|
590
|
-
const body =
|
|
546
|
+
const body = superStringify({
|
|
591
547
|
'command': 'setMode',
|
|
592
548
|
'parameter': 'auto',
|
|
593
549
|
'commandType': 'command',
|
|
594
550
|
});
|
|
595
|
-
this.infoLog(
|
|
551
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
596
552
|
const options = {
|
|
597
553
|
hostname: HostDomain,
|
|
598
554
|
port: 443,
|
|
@@ -608,28 +564,26 @@ export class Humidifier {
|
|
|
608
564
|
},
|
|
609
565
|
};
|
|
610
566
|
const req = https.request(options, res => {
|
|
611
|
-
this.debugLog(
|
|
567
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
612
568
|
this.statusCode({ res });
|
|
613
569
|
res.on('data', d => {
|
|
614
|
-
this.debugLog(
|
|
570
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
615
571
|
});
|
|
616
572
|
});
|
|
617
573
|
req.on('error', (e: any) => {
|
|
618
|
-
this.errorLog(
|
|
574
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
619
575
|
});
|
|
620
576
|
req.write(body);
|
|
621
577
|
req.end();
|
|
622
|
-
this.debugLog(
|
|
578
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges: ${superStringify(req)}`);
|
|
579
|
+
} else {
|
|
580
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
|
|
581
|
+
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
|
|
623
582
|
}
|
|
624
583
|
} catch (e: any) {
|
|
625
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
626
|
-
if (this.deviceLogging.includes('debug')) {
|
|
627
|
-
this.errorLog(
|
|
628
|
-
`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
|
|
629
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
630
|
-
);
|
|
631
|
-
}
|
|
632
584
|
this.apiError(e);
|
|
585
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
|
|
586
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
633
587
|
}
|
|
634
588
|
}
|
|
635
589
|
|
|
@@ -638,6 +592,7 @@ export class Humidifier {
|
|
|
638
592
|
*/
|
|
639
593
|
async pushActiveChanges(): Promise<void> {
|
|
640
594
|
try {
|
|
595
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
641
596
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
642
597
|
// Make Push On request to the API
|
|
643
598
|
const t = Date.now();
|
|
@@ -647,14 +602,14 @@ export class Humidifier {
|
|
|
647
602
|
.update(Buffer.from(data, 'utf-8'))
|
|
648
603
|
.digest();
|
|
649
604
|
const sign = signTerm.toString('base64');
|
|
650
|
-
this.debugLog(
|
|
605
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
651
606
|
this.debugLog('Pushing Off!');
|
|
652
|
-
const body =
|
|
607
|
+
const body = superStringify({
|
|
653
608
|
'command': 'turnOff',
|
|
654
609
|
'parameter': 'default',
|
|
655
610
|
'commandType': 'command',
|
|
656
611
|
});
|
|
657
|
-
this.infoLog(
|
|
612
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
658
613
|
const options = {
|
|
659
614
|
hostname: HostDomain,
|
|
660
615
|
port: 443,
|
|
@@ -670,29 +625,71 @@ export class Humidifier {
|
|
|
670
625
|
},
|
|
671
626
|
};
|
|
672
627
|
const req = https.request(options, res => {
|
|
673
|
-
this.debugLog(
|
|
628
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges statusCode: ${res.statusCode}`);
|
|
674
629
|
this.statusCode({ res });
|
|
675
630
|
res.on('data', d => {
|
|
676
|
-
this.debugLog(
|
|
631
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
677
632
|
});
|
|
678
633
|
});
|
|
679
634
|
req.on('error', (e: any) => {
|
|
680
|
-
this.errorLog(
|
|
635
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
681
636
|
});
|
|
682
637
|
req.write(body);
|
|
683
638
|
req.end();
|
|
684
|
-
this.debugLog(
|
|
639
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges: ${superStringify(req)}`);
|
|
685
640
|
}
|
|
686
641
|
} catch (e: any) {
|
|
687
|
-
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
688
|
-
if (this.deviceLogging.includes('debug')) {
|
|
689
|
-
this.errorLog(
|
|
690
|
-
`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
|
|
691
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
642
|
this.apiError(e);
|
|
643
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
644
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Handle requests to set the "Active" characteristic
|
|
651
|
+
*/
|
|
652
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
653
|
+
if (this.Active === this.accessory.context.Active) {
|
|
654
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
655
|
+
} else {
|
|
656
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
this.Active = value;
|
|
660
|
+
this.doHumidifierUpdate.next();
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
665
|
+
*/
|
|
666
|
+
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
667
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
668
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
669
|
+
} else {
|
|
670
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
this.TargetHumidifierDehumidifierState = value;
|
|
674
|
+
this.doHumidifierUpdate.next();
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
679
|
+
*/
|
|
680
|
+
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
681
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
682
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
683
|
+
} else {
|
|
684
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
this.RelativeHumidityHumidifierThreshold = value;
|
|
688
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
689
|
+
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
690
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
695
691
|
}
|
|
692
|
+
this.doHumidifierUpdate.next();
|
|
696
693
|
}
|
|
697
694
|
|
|
698
695
|
/**
|
|
@@ -700,118 +697,157 @@ export class Humidifier {
|
|
|
700
697
|
*/
|
|
701
698
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
702
699
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
703
|
-
this.debugLog(
|
|
700
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
704
701
|
} else {
|
|
702
|
+
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
705
703
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
706
|
-
this.debugLog(
|
|
704
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
705
|
+
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
707
706
|
}
|
|
708
|
-
if (
|
|
707
|
+
if (this.OpenAPI) {
|
|
709
708
|
if (this.WaterLevel === undefined) {
|
|
710
|
-
this.debugLog(
|
|
709
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
711
710
|
} else {
|
|
711
|
+
this.accessory.context.WaterLevel = this.WaterLevel;
|
|
712
712
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
713
|
-
this.debugLog(
|
|
713
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
717
|
-
this.debugLog(
|
|
717
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
718
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
718
719
|
} else {
|
|
719
|
-
this.
|
|
720
|
-
|
|
721
|
-
this.CurrentHumidifierDehumidifierState
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
725
|
-
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
726
|
-
);
|
|
720
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
721
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
722
|
+
this.CurrentHumidifierDehumidifierState);
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
724
|
+
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
727
725
|
}
|
|
728
726
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
729
|
-
this.debugLog(
|
|
727
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
728
|
+
+` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
730
729
|
} else {
|
|
731
|
-
this.
|
|
732
|
-
|
|
733
|
-
this.TargetHumidifierDehumidifierState
|
|
734
|
-
|
|
735
|
-
this.debugLog(
|
|
736
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
730
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
731
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
732
|
+
this.TargetHumidifierDehumidifierState);
|
|
733
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
737
734
|
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
738
735
|
);
|
|
739
736
|
}
|
|
740
737
|
if (this.Active === undefined) {
|
|
741
|
-
this.debugLog(
|
|
738
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
742
739
|
} else {
|
|
740
|
+
this.accessory.context.Active = this.Active;
|
|
743
741
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
744
|
-
this.debugLog(
|
|
742
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
745
743
|
}
|
|
746
744
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
747
|
-
this.debugLog(
|
|
748
|
-
|
|
749
|
-
);
|
|
745
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
746
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
750
747
|
} else {
|
|
751
|
-
this.
|
|
752
|
-
|
|
753
|
-
this.RelativeHumidityHumidifierThreshold
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
757
|
-
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
758
|
-
);
|
|
748
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
749
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
750
|
+
this.RelativeHumidityHumidifierThreshold);
|
|
751
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
752
|
+
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
759
753
|
}
|
|
760
|
-
if (!this.device.humidifier?.hide_temperature && !this.
|
|
754
|
+
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
761
755
|
if (this.CurrentTemperature === undefined) {
|
|
762
|
-
this.debugLog(
|
|
756
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
763
757
|
} else {
|
|
758
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
764
759
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
765
|
-
this.debugLog(
|
|
760
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
766
761
|
}
|
|
767
762
|
}
|
|
768
763
|
}
|
|
769
764
|
|
|
770
|
-
async
|
|
771
|
-
this.
|
|
772
|
-
|
|
773
|
-
|
|
765
|
+
async getCustomBLEAddress(switchbot: any) {
|
|
766
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
767
|
+
(async () => {
|
|
768
|
+
// Start to monitor advertisement packets
|
|
769
|
+
await switchbot.startScan({
|
|
770
|
+
model: 'e',
|
|
771
|
+
});
|
|
772
|
+
// Set an event handler
|
|
773
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
774
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
775
|
+
};
|
|
776
|
+
await switchbot.wait(10000);
|
|
777
|
+
// Stop to monitor
|
|
778
|
+
switchbot.stopScan();
|
|
779
|
+
})();
|
|
774
780
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
this.
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
async BLEPushConnection() {
|
|
784
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
785
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
786
|
+
await this.openAPIpushChanges();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
791
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
792
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
793
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
794
|
+
await this.openAPIRefreshStatus();
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
minStep(): number {
|
|
799
|
+
if (this.device.humidifier?.set_minStep) {
|
|
800
|
+
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
801
|
+
} else {
|
|
802
|
+
this.set_minStep = 1;
|
|
803
|
+
}
|
|
804
|
+
return this.set_minStep;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
808
|
+
if (device.scanDuration) {
|
|
809
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
810
|
+
if (this.BLE) {
|
|
811
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
812
|
+
}
|
|
813
|
+
} else {
|
|
814
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
815
|
+
if (this.BLE) {
|
|
816
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
817
|
+
}
|
|
781
818
|
}
|
|
782
|
-
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
783
819
|
}
|
|
784
820
|
|
|
785
821
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
786
822
|
switch (res.statusCode) {
|
|
787
823
|
case 151:
|
|
788
|
-
this.errorLog(
|
|
824
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
789
825
|
break;
|
|
790
826
|
case 152:
|
|
791
|
-
this.errorLog(
|
|
827
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
792
828
|
break;
|
|
793
829
|
case 160:
|
|
794
|
-
this.errorLog(
|
|
830
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
795
831
|
break;
|
|
796
832
|
case 161:
|
|
797
|
-
this.errorLog(
|
|
833
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
798
834
|
this.offlineOff();
|
|
799
835
|
break;
|
|
800
836
|
case 171:
|
|
801
|
-
this.errorLog(
|
|
837
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
802
838
|
this.offlineOff();
|
|
803
839
|
break;
|
|
804
840
|
case 190:
|
|
805
841
|
this.errorLog(
|
|
806
|
-
|
|
807
|
-
` Or command: ${
|
|
842
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
843
|
+
` Or command: ${superStringify(res)} format is invalid`,
|
|
808
844
|
);
|
|
809
845
|
break;
|
|
810
846
|
case 100:
|
|
811
|
-
this.debugLog(
|
|
847
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
812
848
|
break;
|
|
813
849
|
default:
|
|
814
|
-
this.debugLog(
|
|
850
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
815
851
|
}
|
|
816
852
|
}
|
|
817
853
|
|
|
@@ -819,40 +855,86 @@ export class Humidifier {
|
|
|
819
855
|
if (this.device.offline) {
|
|
820
856
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
821
857
|
this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
|
|
858
|
+
await this.updateHomeKitCharacteristics();
|
|
822
859
|
}
|
|
823
860
|
}
|
|
824
861
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
this.TargetHumidifierDehumidifierState
|
|
832
|
-
this.
|
|
862
|
+
async apiError(e: any): Promise<void> {
|
|
863
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
864
|
+
if (!this.BLE) {
|
|
865
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
866
|
+
}
|
|
867
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
868
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
869
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
870
|
+
this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
871
|
+
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
872
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
873
|
+
}
|
|
833
874
|
}
|
|
834
875
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
this.debugLog(
|
|
840
|
-
this.
|
|
841
|
-
|
|
876
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
877
|
+
let FirmwareRevision: string;
|
|
878
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
879
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
880
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
881
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
882
|
+
if (accessory.context.FirmwareRevision) {
|
|
883
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
884
|
+
} else if (device.firmware) {
|
|
885
|
+
FirmwareRevision = device.firmware;
|
|
886
|
+
} else {
|
|
887
|
+
FirmwareRevision = this.platform.version;
|
|
888
|
+
}
|
|
889
|
+
return FirmwareRevision;
|
|
842
890
|
}
|
|
843
891
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
*/
|
|
847
|
-
async handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
848
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
849
|
-
|
|
850
|
-
this.RelativeHumidityHumidifierThreshold = value;
|
|
851
|
-
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
892
|
+
async context() {
|
|
893
|
+
if (this.Active === undefined) {
|
|
852
894
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
853
|
-
|
|
895
|
+
} else {
|
|
896
|
+
this.Active = this.accessory.context.Active;
|
|
897
|
+
}
|
|
898
|
+
if (this.CurrentTemperature === undefined) {
|
|
899
|
+
this.CurrentTemperature = 0;
|
|
900
|
+
} else {
|
|
901
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
902
|
+
}
|
|
903
|
+
if (this.CurrentRelativeHumidity === undefined) {
|
|
904
|
+
this.CurrentRelativeHumidity = 0;
|
|
905
|
+
} else {
|
|
906
|
+
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
907
|
+
}
|
|
908
|
+
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
909
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
910
|
+
} else {
|
|
911
|
+
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
912
|
+
}
|
|
913
|
+
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
914
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
915
|
+
} else {
|
|
916
|
+
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
917
|
+
}
|
|
918
|
+
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
919
|
+
this.RelativeHumidityHumidifierThreshold = 0;
|
|
920
|
+
} else {
|
|
921
|
+
this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
|
|
922
|
+
}
|
|
923
|
+
if (this.WaterLevel === undefined) {
|
|
924
|
+
this.WaterLevel = 0;
|
|
925
|
+
} else {
|
|
926
|
+
this.WaterLevel = this.accessory.context.WaterLevel;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
931
|
+
if (device.refreshRate) {
|
|
932
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
933
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
934
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
935
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
936
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
854
937
|
}
|
|
855
|
-
this.doHumidifierUpdate.next();
|
|
856
938
|
}
|
|
857
939
|
|
|
858
940
|
async config(device: device & devicesConfig): Promise<void> {
|
|
@@ -860,8 +942,8 @@ export class Humidifier {
|
|
|
860
942
|
if (device.humidifier) {
|
|
861
943
|
config = device.humidifier;
|
|
862
944
|
}
|
|
863
|
-
if (device.
|
|
864
|
-
config['
|
|
945
|
+
if (device.connectionType !== undefined) {
|
|
946
|
+
config['connectionType'] = device.connectionType;
|
|
865
947
|
}
|
|
866
948
|
if (device.logging !== undefined) {
|
|
867
949
|
config['logging'] = device.logging;
|
|
@@ -876,72 +958,24 @@ export class Humidifier {
|
|
|
876
958
|
config['offline'] = device.offline;
|
|
877
959
|
}
|
|
878
960
|
if (Object.entries(config).length !== 0) {
|
|
879
|
-
this.infoLog(
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
884
|
-
if (device.refreshRate) {
|
|
885
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
886
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
887
|
-
} else if (this.platform.config.options!.refreshRate) {
|
|
888
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
889
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
async scan(device: device & devicesConfig): Promise<void> {
|
|
894
|
-
if (device.scanDuration) {
|
|
895
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
896
|
-
if (device.ble) {
|
|
897
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
898
|
-
}
|
|
899
|
-
} else {
|
|
900
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
901
|
-
if (this.device.ble) {
|
|
902
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
903
|
-
}
|
|
961
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
904
962
|
}
|
|
905
963
|
}
|
|
906
964
|
|
|
907
965
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
908
966
|
if (this.platform.debugMode) {
|
|
909
967
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
910
|
-
this.debugLog(
|
|
968
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
911
969
|
} else if (device.logging) {
|
|
912
970
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
913
|
-
this.debugLog(
|
|
971
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
914
972
|
} else if (this.platform.config.options?.logging) {
|
|
915
973
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
916
|
-
this.debugLog(
|
|
974
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
917
975
|
} else {
|
|
918
976
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
919
|
-
this.debugLog(
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
924
|
-
let FirmwareRevision: string;
|
|
925
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
926
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
927
|
-
this.debugLog(`Humidifier: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
928
|
-
if (accessory.context.FirmwareRevision) {
|
|
929
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
930
|
-
} else if (device.firmware) {
|
|
931
|
-
FirmwareRevision = device.firmware;
|
|
932
|
-
} else {
|
|
933
|
-
FirmwareRevision = this.platform.version;
|
|
977
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
934
978
|
}
|
|
935
|
-
return FirmwareRevision;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
minStep(): number {
|
|
939
|
-
if (this.device.humidifier?.set_minStep) {
|
|
940
|
-
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
941
|
-
} else {
|
|
942
|
-
this.set_minStep = 1;
|
|
943
|
-
}
|
|
944
|
-
return this.set_minStep;
|
|
945
979
|
}
|
|
946
980
|
|
|
947
981
|
/**
|
|
@@ -959,12 +993,28 @@ export class Humidifier {
|
|
|
959
993
|
}
|
|
960
994
|
}
|
|
961
995
|
|
|
996
|
+
debugWarnLog(...log: any[]): void {
|
|
997
|
+
if (this.enablingDeviceLogging()) {
|
|
998
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
999
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
962
1004
|
errorLog(...log: any[]): void {
|
|
963
1005
|
if (this.enablingDeviceLogging()) {
|
|
964
1006
|
this.platform.log.error(String(...log));
|
|
965
1007
|
}
|
|
966
1008
|
}
|
|
967
1009
|
|
|
1010
|
+
debugErrorLog(...log: any[]): void {
|
|
1011
|
+
if (this.enablingDeviceLogging()) {
|
|
1012
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
1013
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
968
1018
|
debugLog(...log: any[]): void {
|
|
969
1019
|
if (this.enablingDeviceLogging()) {
|
|
970
1020
|
if (this.deviceLogging === 'debug') {
|