@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- 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 +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- 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 +335 -421
- 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 +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- 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 +204 -249
- 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 +107 -233
- 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 +193 -235
- 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 +92 -159
- 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 +288 -370
- 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 +172 -219
- 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 +94 -160
- 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 +95 -157
- 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 +85 -144
- 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 +100 -127
- 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 +172 -259
- 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 +106 -131
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- 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 +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- 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,44 +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
|
-
this.apiError(e);
|
|
318
|
-
this.errorLog(
|
|
319
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
345
|
+
await this.apiError(e);
|
|
346
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
320
347
|
}
|
|
321
348
|
}
|
|
322
349
|
|
|
323
|
-
async registerWebhook(
|
|
324
|
-
if (device.webhook) {
|
|
325
|
-
this.debugLog(
|
|
326
|
-
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) => {
|
|
327
354
|
try {
|
|
328
|
-
this.debugLog(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
332
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (temperature, humidity) = Webhook:(${convertUnits(temperature,
|
|
333
|
-
context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
334
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
335
|
-
if (!device.humidifier?.hide_temperature) {
|
|
336
|
-
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
|
337
|
-
}
|
|
338
|
-
this.updateHomeKitCharacteristics();
|
|
355
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
356
|
+
await this.parseStatusWebhook(context);
|
|
357
|
+
await this.updateHomeKitCharacteristics();
|
|
339
358
|
} catch (e: any) {
|
|
340
|
-
this.errorLog(
|
|
341
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
359
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
342
360
|
}
|
|
343
361
|
};
|
|
344
362
|
}
|
|
@@ -349,15 +367,14 @@ export class Humidifier extends deviceBase {
|
|
|
349
367
|
*/
|
|
350
368
|
async pushChanges(): Promise<void> {
|
|
351
369
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
352
|
-
this.errorLog(
|
|
370
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
353
371
|
} else if (this.BLE) {
|
|
354
372
|
await this.BLEpushChanges();
|
|
355
373
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
356
374
|
await this.openAPIpushChanges();
|
|
357
375
|
} else {
|
|
358
376
|
await this.offlineOff();
|
|
359
|
-
this.debugWarnLog(
|
|
360
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
377
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
361
378
|
}
|
|
362
379
|
// Refresh the status from the API
|
|
363
380
|
interval(15000)
|
|
@@ -369,64 +386,69 @@ export class Humidifier extends deviceBase {
|
|
|
369
386
|
}
|
|
370
387
|
|
|
371
388
|
async BLEpushChanges(): Promise<void> {
|
|
372
|
-
this.debugLog(
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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}`);
|
|
391
413
|
await this.BLEPushConnection();
|
|
392
|
-
}
|
|
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
|
+
}
|
|
393
420
|
}
|
|
394
421
|
|
|
395
422
|
async openAPIpushChanges(): Promise<void> {
|
|
396
|
-
this.debugLog(
|
|
397
|
-
if (
|
|
398
|
-
this.HumidifierDehumidifier.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
402
|
-
+ ` 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}!`);
|
|
403
428
|
const bodyChange = JSON.stringify({
|
|
404
429
|
command: 'setMode',
|
|
405
430
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
406
431
|
commandType: 'command',
|
|
407
432
|
});
|
|
408
|
-
this.debugLog(
|
|
433
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
409
434
|
try {
|
|
410
435
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
411
436
|
const deviceStatus: any = await body.json();
|
|
412
|
-
await this.
|
|
413
|
-
if (
|
|
414
|
-
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)}`);
|
|
415
440
|
await this.updateHomeKitCharacteristics();
|
|
416
441
|
} else {
|
|
417
442
|
await this.statusCode(statusCode);
|
|
418
443
|
await this.statusCode(deviceStatus.statusCode);
|
|
419
444
|
}
|
|
420
445
|
} catch (e: any) {
|
|
421
|
-
this.apiError(e);
|
|
422
|
-
this.errorLog(
|
|
423
|
-
+ ` 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)}`);
|
|
424
448
|
}
|
|
425
|
-
} else if (
|
|
426
|
-
this.
|
|
427
|
-
this.hap.Characteristic.
|
|
428
|
-
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
429
|
-
) {
|
|
449
|
+
} else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
450
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
451
|
+
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
430
452
|
await this.pushAutoChanges();
|
|
431
453
|
} else {
|
|
432
454
|
await this.pushActiveChanges();
|
|
@@ -437,37 +459,34 @@ export class Humidifier extends deviceBase {
|
|
|
437
459
|
* Pushes the requested changes to the SwitchBot API
|
|
438
460
|
*/
|
|
439
461
|
async pushAutoChanges(): Promise<void> {
|
|
440
|
-
this.debugLog(
|
|
441
|
-
if (
|
|
442
|
-
this.
|
|
443
|
-
this.hap.Characteristic.
|
|
444
|
-
this.
|
|
445
|
-
) {
|
|
446
|
-
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');
|
|
447
467
|
const bodyChange = JSON.stringify({
|
|
448
468
|
command: 'setMode',
|
|
449
469
|
parameter: 'auto',
|
|
450
470
|
commandType: 'command',
|
|
451
471
|
});
|
|
452
|
-
this.debugLog(
|
|
472
|
+
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
453
473
|
try {
|
|
454
474
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
455
475
|
const deviceStatus: any = await body.json();
|
|
456
|
-
await this.
|
|
457
|
-
if (
|
|
458
|
-
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)}`);
|
|
459
479
|
await this.updateHomeKitCharacteristics();
|
|
460
480
|
} else {
|
|
461
481
|
await this.statusCode(statusCode);
|
|
462
482
|
await this.statusCode(deviceStatus.statusCode);
|
|
463
483
|
}
|
|
464
484
|
} catch (e: any) {
|
|
465
|
-
this.apiError(e);
|
|
466
|
-
this.errorLog(
|
|
467
|
-
+ ` 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)}`);
|
|
468
487
|
}
|
|
469
488
|
} else {
|
|
470
|
-
this.debugLog(
|
|
489
|
+
await this.debugLog('No changes (pushAutoChanges), TargetHumidifierDehumidifierState:'
|
|
471
490
|
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
472
491
|
}
|
|
473
492
|
}
|
|
@@ -476,33 +495,32 @@ export class Humidifier extends deviceBase {
|
|
|
476
495
|
* Pushes the requested changes to the SwitchBot API
|
|
477
496
|
*/
|
|
478
497
|
async pushActiveChanges(): Promise<void> {
|
|
479
|
-
this.debugLog(
|
|
498
|
+
await this.debugLog('pushActiveChanges');
|
|
480
499
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
481
|
-
this.debugLog(
|
|
500
|
+
await this.debugLog('Pushing Off');
|
|
482
501
|
const bodyChange = JSON.stringify({
|
|
483
502
|
command: 'turnOff',
|
|
484
503
|
parameter: 'default',
|
|
485
504
|
commandType: 'command',
|
|
486
505
|
});
|
|
487
|
-
this.debugLog(
|
|
506
|
+
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
488
507
|
try {
|
|
489
508
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
490
509
|
const deviceStatus: any = await body.json();
|
|
491
|
-
await this.
|
|
492
|
-
if (
|
|
493
|
-
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)}`);
|
|
494
513
|
await this.updateHomeKitCharacteristics();
|
|
495
514
|
} else {
|
|
496
515
|
await this.statusCode(statusCode);
|
|
497
516
|
await this.statusCode(deviceStatus.statusCode);
|
|
498
517
|
}
|
|
499
518
|
} catch (e: any) {
|
|
500
|
-
this.apiError(e);
|
|
501
|
-
this.errorLog(
|
|
502
|
-
+ ` 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)}`);
|
|
503
521
|
}
|
|
504
522
|
} else {
|
|
505
|
-
this.debugLog(
|
|
523
|
+
await this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`);
|
|
506
524
|
}
|
|
507
525
|
}
|
|
508
526
|
|
|
@@ -510,10 +528,10 @@ export class Humidifier extends deviceBase {
|
|
|
510
528
|
* Handle requests to set the "Active" characteristic
|
|
511
529
|
*/
|
|
512
530
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
513
|
-
if (this.HumidifierDehumidifier.Active
|
|
514
|
-
this.
|
|
531
|
+
if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
|
|
532
|
+
await this.infoLog(`Set Active: ${value}`);
|
|
515
533
|
} else {
|
|
516
|
-
this.
|
|
534
|
+
await this.debugLog(`No Changes, Active: ${value}`);
|
|
517
535
|
}
|
|
518
536
|
|
|
519
537
|
this.HumidifierDehumidifier.Active = value;
|
|
@@ -525,9 +543,9 @@ export class Humidifier extends deviceBase {
|
|
|
525
543
|
*/
|
|
526
544
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
527
545
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
528
|
-
this.infoLog(
|
|
546
|
+
await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`);
|
|
529
547
|
} else {
|
|
530
|
-
this.debugLog(
|
|
548
|
+
await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`);
|
|
531
549
|
}
|
|
532
550
|
|
|
533
551
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
@@ -539,16 +557,17 @@ export class Humidifier extends deviceBase {
|
|
|
539
557
|
*/
|
|
540
558
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
541
559
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
542
|
-
this.infoLog(
|
|
560
|
+
await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
543
561
|
} else {
|
|
544
|
-
this.debugLog(
|
|
562
|
+
await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`);
|
|
545
563
|
}
|
|
546
|
-
|
|
547
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
564
|
+
// If the Humidifier is off, turn it on
|
|
548
565
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
549
566
|
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
550
567
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
551
568
|
}
|
|
569
|
+
|
|
570
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
552
571
|
this.doHumidifierUpdate.next();
|
|
553
572
|
}
|
|
554
573
|
|
|
@@ -556,93 +575,47 @@ export class Humidifier extends deviceBase {
|
|
|
556
575
|
* Updates the status for each of the HomeKit Characteristics
|
|
557
576
|
*/
|
|
558
577
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
this.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
582
|
-
} else {
|
|
583
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
584
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
585
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
586
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
587
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
588
|
-
}
|
|
589
|
-
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
590
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
591
|
-
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
592
|
-
} else {
|
|
593
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
594
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
595
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
596
|
-
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
597
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
598
|
-
}
|
|
599
|
-
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
600
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
601
|
-
} else {
|
|
602
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
603
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
604
|
-
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
605
|
-
}
|
|
606
|
-
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
607
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
608
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
609
|
-
} else {
|
|
610
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
611
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
612
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
613
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
614
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
615
|
-
}
|
|
616
|
-
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
617
|
-
if (this.TemperatureSensor!.CurrentTemperature === undefined) {
|
|
618
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
619
|
-
} else {
|
|
620
|
-
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
621
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
622
|
-
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
623
|
-
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
624
|
-
}
|
|
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');
|
|
625
600
|
}
|
|
626
601
|
}
|
|
627
602
|
|
|
628
603
|
async BLEPushConnection() {
|
|
629
604
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
630
|
-
this.warnLog(
|
|
605
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
631
606
|
await this.openAPIpushChanges();
|
|
632
607
|
}
|
|
633
608
|
}
|
|
634
609
|
|
|
635
610
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
636
|
-
this.errorLog(
|
|
637
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
611
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
638
612
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
639
|
-
this.warnLog(
|
|
613
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
640
614
|
await this.openAPIRefreshStatus();
|
|
641
615
|
}
|
|
642
616
|
}
|
|
643
617
|
|
|
644
618
|
async offlineOff(): Promise<void> {
|
|
645
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
646
619
|
if (this.device.offline) {
|
|
647
620
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
648
621
|
this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
@@ -654,15 +627,13 @@ export class Humidifier extends deviceBase {
|
|
|
654
627
|
|
|
655
628
|
async apiError(e: any): Promise<void> {
|
|
656
629
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
657
|
-
|
|
658
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
659
|
-
}
|
|
630
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
660
631
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
661
632
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
662
633
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
663
634
|
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
664
|
-
if (!this.device.humidifier?.hide_temperature &&
|
|
665
|
-
this.TemperatureSensor
|
|
635
|
+
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
636
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
666
637
|
}
|
|
667
638
|
}
|
|
668
639
|
}
|