@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4
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/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/device/humidifier.ts
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
* humidifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { interval, Subject } from 'rxjs';
|
|
7
6
|
import { convertUnits } from '../utils.js';
|
|
8
|
-
import {
|
|
7
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
|
+
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
9
|
|
|
10
|
+
import type { devicesConfig } from '../settings.js';
|
|
11
|
+
import type { device } from '../types/devicelist.js';
|
|
10
12
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
13
|
+
import type { humidifierServiceData } from '../types/bledevicestatus.js';
|
|
14
|
+
import type { humidifierStatus } from '../types/devicestatus.js';
|
|
15
|
+
import type { humidifierWebhookContext } from '../types/devicewebhookstatus.js';
|
|
11
16
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
12
|
-
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Platform Accessory
|
|
@@ -140,6 +144,9 @@ export class Humidifier extends deviceBase {
|
|
|
140
144
|
// Retrieve initial values and updateHomekit
|
|
141
145
|
this.updateHomeKitCharacteristics();
|
|
142
146
|
|
|
147
|
+
//regisiter webhook event handler
|
|
148
|
+
this.registerWebhook();
|
|
149
|
+
|
|
143
150
|
// Start an update interval
|
|
144
151
|
interval(this.deviceRefreshRate * 1000)
|
|
145
152
|
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
@@ -147,9 +154,6 @@ export class Humidifier extends deviceBase {
|
|
|
147
154
|
await this.refreshStatus();
|
|
148
155
|
});
|
|
149
156
|
|
|
150
|
-
//regisiter webhook event handler
|
|
151
|
-
this.registerWebhook(accessory, device);
|
|
152
|
-
|
|
153
157
|
// Watch for Humidifier change events
|
|
154
158
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
155
159
|
this.doHumidifierUpdate
|
|
@@ -163,46 +167,25 @@ export class Humidifier extends deviceBase {
|
|
|
163
167
|
try {
|
|
164
168
|
await this.pushChanges();
|
|
165
169
|
} catch (e: any) {
|
|
166
|
-
this.apiError(e);
|
|
167
|
-
this.errorLog(
|
|
168
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
170
|
+
await this.apiError(e);
|
|
171
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
169
172
|
}
|
|
170
173
|
this.humidifierUpdateInProgress = false;
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
async BLEparseStatus(serviceData:
|
|
175
|
-
this.debugLog(
|
|
176
|
-
// Target Humidifier Dehumidifier State
|
|
177
|
-
if (serviceData.autoMode) {
|
|
178
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
179
|
-
}
|
|
180
|
-
// Current Relative Humidity
|
|
181
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage!;
|
|
182
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
183
|
-
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
177
|
+
async BLEparseStatus(serviceData: humidifierServiceData): Promise<void> {
|
|
178
|
+
await this.debugLog('BLEparseStatus');
|
|
184
179
|
// Active
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
} else {
|
|
188
|
-
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
189
|
-
}
|
|
190
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
191
|
-
}
|
|
180
|
+
this.HumidifierDehumidifier.Active = serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
181
|
+
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
|
|
192
182
|
|
|
193
|
-
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
194
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
195
183
|
// Current Relative Humidity
|
|
196
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity =
|
|
197
|
-
this.debugLog(
|
|
198
|
-
|
|
199
|
-
// Current Temperature
|
|
200
|
-
if (!this.device.humidifier?.hide_temperature) {
|
|
201
|
-
this.TemperatureSensor!.CurrentTemperature = deviceStatus.body.temperature!;
|
|
202
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
203
|
-
}
|
|
184
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
|
|
185
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
186
|
+
|
|
204
187
|
// Target Humidifier Dehumidifier State
|
|
205
|
-
switch (
|
|
188
|
+
switch (serviceData.autoMode) {
|
|
206
189
|
case true:
|
|
207
190
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
208
191
|
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
@@ -211,11 +194,7 @@ export class Humidifier extends deviceBase {
|
|
|
211
194
|
break;
|
|
212
195
|
default:
|
|
213
196
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
214
|
-
|
|
215
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
216
|
-
} else {
|
|
217
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency!;
|
|
218
|
-
}
|
|
197
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = serviceData.percentage > 100 ? 100 : serviceData.percentage;
|
|
219
198
|
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
220
199
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
221
200
|
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
@@ -224,34 +203,64 @@ export class Humidifier extends deviceBase {
|
|
|
224
203
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
225
204
|
}
|
|
226
205
|
}
|
|
227
|
-
this.debugLog(
|
|
228
|
-
+ `
|
|
229
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
230
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
231
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
206
|
+
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
|
|
207
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
232
208
|
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async openAPIparseStatus(deviceStatus: humidifierStatus): Promise<void> {
|
|
212
|
+
await this.debugLog('openAPIparseStatus');
|
|
233
213
|
// Active
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
214
|
+
this.HumidifierDehumidifier.Active = deviceStatus.power === 'on'
|
|
215
|
+
? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
216
|
+
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
|
|
217
|
+
|
|
218
|
+
// Current Relative Humidity
|
|
219
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.temperature!;
|
|
220
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
221
|
+
|
|
222
|
+
// Current Temperature
|
|
223
|
+
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
224
|
+
this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
|
|
225
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
226
|
+
}
|
|
227
|
+
// Target Humidifier Dehumidifier State
|
|
228
|
+
switch (deviceStatus.auto) {
|
|
229
|
+
case true:
|
|
230
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
231
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
232
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
233
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
237
234
|
break;
|
|
238
235
|
default:
|
|
239
|
-
this.HumidifierDehumidifier.
|
|
236
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
237
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.nebulizationEfficiency > 100
|
|
238
|
+
? 100 : deviceStatus.nebulizationEfficiency;
|
|
239
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
240
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
241
|
+
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
242
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
243
|
+
} else {
|
|
244
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
245
|
+
}
|
|
240
246
|
}
|
|
241
|
-
this.debugLog(
|
|
247
|
+
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
|
|
248
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
249
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
250
|
+
|
|
242
251
|
// Water Level
|
|
243
|
-
if (deviceStatus.
|
|
252
|
+
if (deviceStatus.lackWater) {
|
|
244
253
|
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
245
254
|
} else {
|
|
246
255
|
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
247
256
|
}
|
|
248
|
-
this.debugLog(
|
|
257
|
+
await this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
249
258
|
|
|
250
259
|
// Firmware Version
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const deviceVersion = version
|
|
260
|
+
if (deviceStatus.version) {
|
|
261
|
+
const version = deviceStatus.version.toString();
|
|
262
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
263
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
255
264
|
this.accessory
|
|
256
265
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
257
266
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -259,41 +268,59 @@ export class Humidifier extends deviceBase {
|
|
|
259
268
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
260
269
|
.updateValue(deviceVersion);
|
|
261
270
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
262
|
-
this.debugSuccessLog(
|
|
271
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
263
272
|
}
|
|
264
273
|
}
|
|
265
274
|
|
|
275
|
+
async parseStatusWebhook(context: humidifierWebhookContext): Promise<void> {
|
|
276
|
+
await this.debugLog('parseStatusWebhook');
|
|
277
|
+
await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo)},`
|
|
278
|
+
+ ` ${context.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
|
|
279
|
+
|
|
280
|
+
// CurrentRelativeHumidity
|
|
281
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = context.humidity;
|
|
282
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
283
|
+
|
|
284
|
+
// CurrentTemperature
|
|
285
|
+
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
286
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo);
|
|
287
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Asks the SwitchBot API for the latest device information
|
|
293
|
+
*/
|
|
266
294
|
async refreshStatus(): Promise<void> {
|
|
267
295
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
268
|
-
this.errorLog(
|
|
296
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
269
297
|
} else if (this.BLE) {
|
|
270
298
|
await this.BLERefreshStatus();
|
|
271
299
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
272
300
|
await this.openAPIRefreshStatus();
|
|
273
301
|
} else {
|
|
274
302
|
await this.offlineOff();
|
|
275
|
-
this.debugWarnLog(
|
|
276
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
303
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
277
304
|
}
|
|
278
305
|
}
|
|
279
306
|
|
|
280
307
|
async BLERefreshStatus(): Promise<void> {
|
|
281
|
-
this.debugLog(
|
|
308
|
+
await this.debugLog('BLERefreshStatus');
|
|
282
309
|
const switchbot = await this.switchbotBLE();
|
|
283
310
|
|
|
284
311
|
if (switchbot === undefined) {
|
|
285
312
|
await this.BLERefreshConnection(switchbot);
|
|
286
313
|
} else {
|
|
287
|
-
// Start to monitor advertisement packets
|
|
288
|
-
(async () => {
|
|
289
314
|
// Start to monitor advertisement packets
|
|
290
|
-
|
|
315
|
+
(async () => {
|
|
316
|
+
// Start to monitor advertisement packets
|
|
317
|
+
const serviceData= await this.monitorAdvertisementPackets(switchbot) as unknown as humidifierServiceData;
|
|
291
318
|
// Update HomeKit
|
|
292
|
-
if (serviceData.model
|
|
319
|
+
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
293
320
|
await this.BLEparseStatus(serviceData);
|
|
294
321
|
await this.updateHomeKitCharacteristics();
|
|
295
322
|
} else {
|
|
296
|
-
this.errorLog(
|
|
323
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
297
324
|
await this.BLERefreshConnection(switchbot);
|
|
298
325
|
}
|
|
299
326
|
})();
|
|
@@ -301,43 +328,35 @@ export class Humidifier extends deviceBase {
|
|
|
301
328
|
}
|
|
302
329
|
|
|
303
330
|
async openAPIRefreshStatus(): Promise<void> {
|
|
304
|
-
this.debugLog(
|
|
331
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
305
332
|
try {
|
|
306
333
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
307
334
|
const deviceStatus: any = await body.json();
|
|
308
|
-
await this.
|
|
309
|
-
if (
|
|
310
|
-
await this.
|
|
311
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
335
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
336
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
337
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
338
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
312
339
|
await this.updateHomeKitCharacteristics();
|
|
313
340
|
} else {
|
|
314
|
-
await this.
|
|
341
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
342
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
315
343
|
}
|
|
316
344
|
} catch (e: any) {
|
|
317
345
|
await this.apiError(e);
|
|
318
|
-
await this.
|
|
346
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
319
347
|
}
|
|
320
348
|
}
|
|
321
349
|
|
|
322
|
-
async registerWebhook(
|
|
323
|
-
if (device.webhook) {
|
|
324
|
-
this.debugLog(
|
|
325
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
350
|
+
async registerWebhook() {
|
|
351
|
+
if (this.device.webhook) {
|
|
352
|
+
await this.debugLog('is listening webhook.');
|
|
353
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: humidifierWebhookContext) => {
|
|
326
354
|
try {
|
|
327
|
-
this.debugLog(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
331
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (temperature, humidity) = Webhook:(${convertUnits(temperature,
|
|
332
|
-
context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
333
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
334
|
-
if (!device.humidifier?.hide_temperature) {
|
|
335
|
-
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
|
336
|
-
}
|
|
337
|
-
this.updateHomeKitCharacteristics();
|
|
355
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
356
|
+
await this.parseStatusWebhook(context);
|
|
357
|
+
await this.updateHomeKitCharacteristics();
|
|
338
358
|
} catch (e: any) {
|
|
339
|
-
this.errorLog(
|
|
340
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
359
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
341
360
|
}
|
|
342
361
|
};
|
|
343
362
|
}
|
|
@@ -348,14 +367,14 @@ export class Humidifier extends deviceBase {
|
|
|
348
367
|
*/
|
|
349
368
|
async pushChanges(): Promise<void> {
|
|
350
369
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
351
|
-
this.errorLog(
|
|
370
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
352
371
|
} else if (this.BLE) {
|
|
353
372
|
await this.BLEpushChanges();
|
|
354
373
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
355
374
|
await this.openAPIpushChanges();
|
|
356
375
|
} else {
|
|
357
376
|
await this.offlineOff();
|
|
358
|
-
await this.
|
|
377
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
359
378
|
}
|
|
360
379
|
// Refresh the status from the API
|
|
361
380
|
interval(15000)
|
|
@@ -367,64 +386,69 @@ export class Humidifier extends deviceBase {
|
|
|
367
386
|
}
|
|
368
387
|
|
|
369
388
|
async BLEpushChanges(): Promise<void> {
|
|
370
|
-
this.debugLog(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
+
await this.debugLog('BLEpushChanges');
|
|
390
|
+
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
391
|
+
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
392
|
+
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
393
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
394
|
+
await this.convertBLEAddress();
|
|
395
|
+
if (switchbot !== false) {
|
|
396
|
+
switchbot
|
|
397
|
+
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
398
|
+
.then(async (device_list: any) => {
|
|
399
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
400
|
+
})
|
|
401
|
+
.then(async () => {
|
|
402
|
+
await this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`
|
|
403
|
+
+ ' sent over BLE, sent successfully');
|
|
404
|
+
await this.updateHomeKitCharacteristics();
|
|
405
|
+
})
|
|
406
|
+
.catch(async (e: any) => {
|
|
407
|
+
await this.apiError(e);
|
|
408
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
409
|
+
await this.BLEPushConnection();
|
|
410
|
+
});
|
|
411
|
+
} else {
|
|
412
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
389
413
|
await this.BLEPushConnection();
|
|
390
|
-
}
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
await this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active},`
|
|
417
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
418
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
419
|
+
}
|
|
391
420
|
}
|
|
392
421
|
|
|
393
422
|
async openAPIpushChanges(): Promise<void> {
|
|
394
|
-
this.debugLog(
|
|
395
|
-
if (
|
|
396
|
-
this.HumidifierDehumidifier.
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
400
|
-
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
423
|
+
await this.debugLog('openAPIpushChanges');
|
|
424
|
+
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
425
|
+
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
426
|
+
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
427
|
+
await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
401
428
|
const bodyChange = JSON.stringify({
|
|
402
429
|
command: 'setMode',
|
|
403
430
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
404
431
|
commandType: 'command',
|
|
405
432
|
});
|
|
406
|
-
this.debugLog(
|
|
433
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
407
434
|
try {
|
|
408
435
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
409
436
|
const deviceStatus: any = await body.json();
|
|
410
|
-
await this.
|
|
411
|
-
if (
|
|
412
|
-
await this.
|
|
437
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
438
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
439
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
413
440
|
await this.updateHomeKitCharacteristics();
|
|
414
441
|
} else {
|
|
415
442
|
await this.statusCode(statusCode);
|
|
416
443
|
await this.statusCode(deviceStatus.statusCode);
|
|
417
444
|
}
|
|
418
445
|
} catch (e: any) {
|
|
419
|
-
this.apiError(e);
|
|
420
|
-
this.errorLog(
|
|
421
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
446
|
+
await this.apiError(e);
|
|
447
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
422
448
|
}
|
|
423
|
-
} else if (
|
|
424
|
-
this.
|
|
425
|
-
this.hap.Characteristic.
|
|
426
|
-
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
427
|
-
) {
|
|
449
|
+
} else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
450
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
451
|
+
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
428
452
|
await this.pushAutoChanges();
|
|
429
453
|
} else {
|
|
430
454
|
await this.pushActiveChanges();
|
|
@@ -435,37 +459,34 @@ export class Humidifier extends deviceBase {
|
|
|
435
459
|
* Pushes the requested changes to the SwitchBot API
|
|
436
460
|
*/
|
|
437
461
|
async pushAutoChanges(): Promise<void> {
|
|
438
|
-
this.debugLog(
|
|
439
|
-
if (
|
|
440
|
-
this.
|
|
441
|
-
this.hap.Characteristic.
|
|
442
|
-
this.
|
|
443
|
-
) {
|
|
444
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
462
|
+
this.debugLog('pushAutoChanges');
|
|
463
|
+
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
464
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
465
|
+
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
466
|
+
await this.debugLog('Pushing Auto');
|
|
445
467
|
const bodyChange = JSON.stringify({
|
|
446
468
|
command: 'setMode',
|
|
447
469
|
parameter: 'auto',
|
|
448
470
|
commandType: 'command',
|
|
449
471
|
});
|
|
450
|
-
this.debugLog(
|
|
472
|
+
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
451
473
|
try {
|
|
452
474
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
453
475
|
const deviceStatus: any = await body.json();
|
|
454
|
-
await this.
|
|
455
|
-
if (
|
|
456
|
-
await this.
|
|
476
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
477
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
478
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
457
479
|
await this.updateHomeKitCharacteristics();
|
|
458
480
|
} else {
|
|
459
481
|
await this.statusCode(statusCode);
|
|
460
482
|
await this.statusCode(deviceStatus.statusCode);
|
|
461
483
|
}
|
|
462
484
|
} catch (e: any) {
|
|
463
|
-
this.apiError(e);
|
|
464
|
-
this.errorLog(
|
|
465
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
485
|
+
await this.apiError(e);
|
|
486
|
+
await this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
466
487
|
}
|
|
467
488
|
} else {
|
|
468
|
-
this.debugLog(
|
|
489
|
+
await this.debugLog('No changes (pushAutoChanges), TargetHumidifierDehumidifierState:'
|
|
469
490
|
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
470
491
|
}
|
|
471
492
|
}
|
|
@@ -474,33 +495,32 @@ export class Humidifier extends deviceBase {
|
|
|
474
495
|
* Pushes the requested changes to the SwitchBot API
|
|
475
496
|
*/
|
|
476
497
|
async pushActiveChanges(): Promise<void> {
|
|
477
|
-
this.debugLog(
|
|
498
|
+
await this.debugLog('pushActiveChanges');
|
|
478
499
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
479
|
-
this.debugLog(
|
|
500
|
+
await this.debugLog('Pushing Off');
|
|
480
501
|
const bodyChange = JSON.stringify({
|
|
481
502
|
command: 'turnOff',
|
|
482
503
|
parameter: 'default',
|
|
483
504
|
commandType: 'command',
|
|
484
505
|
});
|
|
485
|
-
this.debugLog(
|
|
506
|
+
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
486
507
|
try {
|
|
487
508
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
488
509
|
const deviceStatus: any = await body.json();
|
|
489
|
-
await this.
|
|
490
|
-
if (
|
|
491
|
-
await this.
|
|
510
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
511
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
512
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
492
513
|
await this.updateHomeKitCharacteristics();
|
|
493
514
|
} else {
|
|
494
515
|
await this.statusCode(statusCode);
|
|
495
516
|
await this.statusCode(deviceStatus.statusCode);
|
|
496
517
|
}
|
|
497
518
|
} catch (e: any) {
|
|
498
|
-
this.apiError(e);
|
|
499
|
-
this.errorLog(
|
|
500
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
519
|
+
await this.apiError(e);
|
|
520
|
+
await this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
501
521
|
}
|
|
502
522
|
} else {
|
|
503
|
-
this.debugLog(
|
|
523
|
+
await this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`);
|
|
504
524
|
}
|
|
505
525
|
}
|
|
506
526
|
|
|
@@ -508,10 +528,10 @@ export class Humidifier extends deviceBase {
|
|
|
508
528
|
* Handle requests to set the "Active" characteristic
|
|
509
529
|
*/
|
|
510
530
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
511
|
-
if (this.HumidifierDehumidifier.Active
|
|
512
|
-
this.
|
|
531
|
+
if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
|
|
532
|
+
await this.infoLog(`Set Active: ${value}`);
|
|
513
533
|
} else {
|
|
514
|
-
this.
|
|
534
|
+
await this.debugLog(`No Changes, Active: ${value}`);
|
|
515
535
|
}
|
|
516
536
|
|
|
517
537
|
this.HumidifierDehumidifier.Active = value;
|
|
@@ -523,9 +543,9 @@ export class Humidifier extends deviceBase {
|
|
|
523
543
|
*/
|
|
524
544
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
525
545
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
526
|
-
this.infoLog(
|
|
546
|
+
await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`);
|
|
527
547
|
} else {
|
|
528
|
-
this.debugLog(
|
|
548
|
+
await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`);
|
|
529
549
|
}
|
|
530
550
|
|
|
531
551
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
@@ -537,16 +557,17 @@ export class Humidifier extends deviceBase {
|
|
|
537
557
|
*/
|
|
538
558
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
539
559
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
540
|
-
this.infoLog(
|
|
560
|
+
await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
541
561
|
} else {
|
|
542
|
-
this.debugLog(
|
|
562
|
+
await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`);
|
|
543
563
|
}
|
|
544
|
-
|
|
545
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
564
|
+
// If the Humidifier is off, turn it on
|
|
546
565
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
547
566
|
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
548
567
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
549
568
|
}
|
|
569
|
+
|
|
570
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
550
571
|
this.doHumidifierUpdate.next();
|
|
551
572
|
}
|
|
552
573
|
|
|
@@ -554,93 +575,47 @@ export class Humidifier extends deviceBase {
|
|
|
554
575
|
* Updates the status for each of the HomeKit Characteristics
|
|
555
576
|
*/
|
|
556
577
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
this.
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
580
|
-
} else {
|
|
581
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
582
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
583
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
584
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
585
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
586
|
-
}
|
|
587
|
-
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
588
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
589
|
-
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
590
|
-
} else {
|
|
591
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
592
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
593
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
594
|
-
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
595
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
596
|
-
}
|
|
597
|
-
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
598
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
599
|
-
} else {
|
|
600
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
601
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
602
|
-
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
603
|
-
}
|
|
604
|
-
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
605
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
606
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
607
|
-
} else {
|
|
608
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
609
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
610
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
611
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
612
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
613
|
-
}
|
|
614
|
-
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
615
|
-
if (this.TemperatureSensor!.CurrentTemperature === undefined) {
|
|
616
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
617
|
-
} else {
|
|
618
|
-
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
619
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
620
|
-
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
621
|
-
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
622
|
-
}
|
|
578
|
+
// CurrentRelativeHumidity
|
|
579
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
580
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
581
|
+
// WaterLevel
|
|
582
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.WaterLevel,
|
|
583
|
+
this.HumidifierDehumidifier.WaterLevel, 'WaterLevel');
|
|
584
|
+
// CurrentHumidifierDehumidifierState
|
|
585
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
586
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState, 'CurrentHumidifierDehumidifierState');
|
|
587
|
+
// TargetHumidifierDehumidifierState
|
|
588
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
589
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState, 'TargetHumidifierDehumidifierState');
|
|
590
|
+
// Active
|
|
591
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.Active,
|
|
592
|
+
this.HumidifierDehumidifier.Active, 'Active');
|
|
593
|
+
// RelativeHumidityHumidifierThreshold
|
|
594
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
595
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold, 'RelativeHumidityHumidifierThreshold');
|
|
596
|
+
// CurrentTemperature
|
|
597
|
+
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
598
|
+
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
|
|
599
|
+
this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
|
|
623
600
|
}
|
|
624
601
|
}
|
|
625
602
|
|
|
626
603
|
async BLEPushConnection() {
|
|
627
604
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
628
|
-
this.warnLog(
|
|
605
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
629
606
|
await this.openAPIpushChanges();
|
|
630
607
|
}
|
|
631
608
|
}
|
|
632
609
|
|
|
633
610
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
634
|
-
this.errorLog(
|
|
635
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
611
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
636
612
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
637
|
-
this.warnLog(
|
|
613
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
638
614
|
await this.openAPIRefreshStatus();
|
|
639
615
|
}
|
|
640
616
|
}
|
|
641
617
|
|
|
642
618
|
async offlineOff(): Promise<void> {
|
|
643
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
644
619
|
if (this.device.offline) {
|
|
645
620
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
646
621
|
this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
@@ -652,15 +627,13 @@ export class Humidifier extends deviceBase {
|
|
|
652
627
|
|
|
653
628
|
async apiError(e: any): Promise<void> {
|
|
654
629
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
655
|
-
|
|
656
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
657
|
-
}
|
|
630
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
658
631
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
659
632
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
660
633
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
661
634
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
662
|
-
if (!this.device.humidifier?.hide_temperature &&
|
|
663
|
-
this.TemperatureSensor
|
|
635
|
+
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
636
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
664
637
|
}
|
|
665
638
|
}
|
|
666
639
|
}
|