@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
2
|
+
import { deviceBase } from './device.js';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Devices } from '../settings.js';
|
|
@@ -8,96 +8,52 @@ import { Devices } from '../settings.js';
|
|
|
8
8
|
* An instance of this class is created for each accessory your platform registers
|
|
9
9
|
* Each accessory may expose multiple services of different service types.
|
|
10
10
|
*/
|
|
11
|
-
export class Humidifier {
|
|
11
|
+
export class Humidifier extends deviceBase {
|
|
12
12
|
platform;
|
|
13
|
-
accessory;
|
|
14
|
-
device;
|
|
15
|
-
api;
|
|
16
|
-
log;
|
|
17
|
-
config;
|
|
18
|
-
hap;
|
|
19
13
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Characteristic Values
|
|
23
|
-
Active;
|
|
24
|
-
WaterLevel;
|
|
25
|
-
FirmwareRevision;
|
|
26
|
-
CurrentTemperature;
|
|
27
|
-
CurrentRelativeHumidity;
|
|
28
|
-
TargetHumidifierDehumidifierState;
|
|
29
|
-
CurrentHumidifierDehumidifierState;
|
|
30
|
-
RelativeHumidityHumidifierThreshold;
|
|
31
|
-
// OpenAPI
|
|
32
|
-
OpenAPI_Active;
|
|
33
|
-
OpenAPI_WaterLevel;
|
|
34
|
-
OpenAPI_FirmwareRevision;
|
|
35
|
-
OpenAPI_CurrentTemperature;
|
|
36
|
-
OpenAPI_CurrentRelativeHumidity;
|
|
37
|
-
OpenAPI_CurrentHumidifierDehumidifierState;
|
|
38
|
-
OpenAPI_RelativeHumidityHumidifierThreshold;
|
|
39
|
-
// BLE Others
|
|
40
|
-
connected;
|
|
41
|
-
onState;
|
|
42
|
-
autoMode;
|
|
43
|
-
percentage;
|
|
44
|
-
// Config
|
|
45
|
-
set_minStep;
|
|
46
|
-
scanDuration;
|
|
47
|
-
deviceLogging;
|
|
48
|
-
deviceRefreshRate;
|
|
49
|
-
maxRetries;
|
|
50
|
-
delayBetweenRetries;
|
|
14
|
+
HumidifierDehumidifier;
|
|
15
|
+
TemperatureSensor;
|
|
51
16
|
// Updates
|
|
52
17
|
humidifierUpdateInProgress;
|
|
53
18
|
doHumidifierUpdate;
|
|
54
|
-
// Connection
|
|
55
|
-
OpenAPI;
|
|
56
|
-
BLE;
|
|
57
19
|
constructor(platform, accessory, device) {
|
|
20
|
+
super(platform, accessory, device);
|
|
58
21
|
this.platform = platform;
|
|
59
|
-
this.accessory = accessory;
|
|
60
|
-
this.device = device;
|
|
61
|
-
this.api = this.platform.api;
|
|
62
|
-
this.log = this.platform.log;
|
|
63
|
-
this.config = this.platform.config;
|
|
64
|
-
this.hap = this.api.hap;
|
|
65
|
-
// Connection
|
|
66
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
67
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
68
|
-
// default placeholders
|
|
69
|
-
this.deviceLogs(device);
|
|
70
|
-
this.scan(device);
|
|
71
|
-
this.refreshRate(device);
|
|
72
|
-
this.deviceContext();
|
|
73
|
-
this.deviceRetry(device);
|
|
74
|
-
this.deviceConfig(device);
|
|
75
22
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
76
23
|
this.doHumidifierUpdate = new Subject();
|
|
77
24
|
this.humidifierUpdateInProgress = false;
|
|
78
25
|
// Retrieve initial values and updateHomekit
|
|
79
26
|
this.refreshStatus();
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
|
|
27
|
+
// Initialize the HumidifierDehumidifier Service
|
|
28
|
+
this.HumidifierDehumidifier = {
|
|
29
|
+
Service: accessory.addService(this.hap.Service.HumidifierDehumidifier),
|
|
30
|
+
Active: accessory.context.Active || this.hap.Characteristic.Active.ACTIVE,
|
|
31
|
+
WaterLevel: accessory.context.WaterLevel || 100,
|
|
32
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
33
|
+
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
34
|
+
|| this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
35
|
+
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
36
|
+
|| this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
37
|
+
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold || 50,
|
|
38
|
+
};
|
|
39
|
+
// Initialize the Temperature Sensor Service
|
|
40
|
+
if (!device.humidifier?.hide_temperature) {
|
|
41
|
+
this.TemperatureSensor = {
|
|
42
|
+
Service: accessory.addService(this.hap.Service.TemperatureSensor),
|
|
43
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
87
46
|
// get the service if it exists, otherwise create a new service
|
|
88
47
|
// you can create multiple services for each accessory
|
|
89
|
-
const
|
|
90
|
-
(this.
|
|
91
|
-
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)),
|
|
92
|
-
this.
|
|
93
|
-
if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
94
|
-
this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
95
|
-
}
|
|
48
|
+
const HumidifierDehumidifierService = `${accessory.displayName} Humidifier`;
|
|
49
|
+
(this.HumidifierDehumidifier.Service = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
50
|
+
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), HumidifierDehumidifierService;
|
|
51
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
96
52
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
97
53
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
98
54
|
// create handlers for required characteristics
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
55
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
56
|
+
this.HumidifierDehumidifier.Service
|
|
101
57
|
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
102
58
|
.setProps({
|
|
103
59
|
validValueRanges: [0, 1],
|
|
@@ -106,32 +62,29 @@ export class Humidifier {
|
|
|
106
62
|
validValues: [0, 1],
|
|
107
63
|
})
|
|
108
64
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
65
|
+
this.HumidifierDehumidifier.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
66
|
+
this.HumidifierDehumidifier.Service
|
|
111
67
|
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
112
68
|
.setProps({
|
|
113
69
|
validValueRanges: [0, 100],
|
|
114
70
|
minValue: 0,
|
|
115
71
|
maxValue: 100,
|
|
116
|
-
minStep: this.minStep(),
|
|
72
|
+
minStep: this.minStep(device),
|
|
117
73
|
})
|
|
118
74
|
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
119
75
|
// Temperature Sensor Service
|
|
120
76
|
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
121
77
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
122
|
-
this.
|
|
123
|
-
accessory.removeService(this.
|
|
78
|
+
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
79
|
+
accessory.removeService(this.TemperatureSensor.Service);
|
|
124
80
|
}
|
|
125
|
-
else if (!this.
|
|
81
|
+
else if (!this.TemperatureSensor.Service && !this.BLE) {
|
|
126
82
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
127
|
-
const
|
|
128
|
-
(this.
|
|
129
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)),
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
133
|
-
}
|
|
134
|
-
this.temperatureservice
|
|
83
|
+
const TemperatureSensorService = `${accessory.displayName} Temperature Sensor`;
|
|
84
|
+
(this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
85
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), TemperatureSensorService;
|
|
86
|
+
this.TemperatureSensor.Service.setCharacteristic(this.hap.Characteristic.Name, TemperatureSensorService);
|
|
87
|
+
this.TemperatureSensor.Service
|
|
135
88
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
136
89
|
.setProps({
|
|
137
90
|
validValueRanges: [-273.15, 100],
|
|
@@ -140,7 +93,7 @@ export class Humidifier {
|
|
|
140
93
|
minStep: 0.1,
|
|
141
94
|
})
|
|
142
95
|
.onGet(() => {
|
|
143
|
-
return this.CurrentTemperature;
|
|
96
|
+
return this.TemperatureSensor.CurrentTemperature;
|
|
144
97
|
});
|
|
145
98
|
}
|
|
146
99
|
else {
|
|
@@ -162,13 +115,16 @@ export class Humidifier {
|
|
|
162
115
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
163
116
|
if (context.scale === 'CELSIUS') {
|
|
164
117
|
const { temperature, humidity } = context;
|
|
165
|
-
const {
|
|
118
|
+
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
119
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
166
120
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
167
121
|
'(temperature, humidity) = ' +
|
|
168
122
|
`Webhook:(${temperature}, ${humidity}), ` +
|
|
169
123
|
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
170
|
-
this.CurrentRelativeHumidity = humidity;
|
|
171
|
-
this.
|
|
124
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
125
|
+
if (!this.device.humidifier?.hide_temperature) {
|
|
126
|
+
this.TemperatureSensor.CurrentTemperature = temperature;
|
|
127
|
+
}
|
|
172
128
|
this.updateHomeKitCharacteristics();
|
|
173
129
|
}
|
|
174
130
|
}
|
|
@@ -196,101 +152,88 @@ export class Humidifier {
|
|
|
196
152
|
this.humidifierUpdateInProgress = false;
|
|
197
153
|
});
|
|
198
154
|
}
|
|
199
|
-
|
|
200
|
-
* Parse the device status from the SwitchBot api
|
|
201
|
-
*/
|
|
202
|
-
async parseStatus() {
|
|
203
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
204
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
205
|
-
}
|
|
206
|
-
else if (this.BLE) {
|
|
207
|
-
await this.BLEparseStatus();
|
|
208
|
-
}
|
|
209
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
210
|
-
await this.openAPIparseStatus();
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
await this.offlineOff();
|
|
214
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async BLEparseStatus() {
|
|
155
|
+
async BLEparseStatus(serviceData) {
|
|
218
156
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
157
|
+
// Target Humidifier Dehumidifier State
|
|
158
|
+
if (serviceData.autoMode) {
|
|
159
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
160
|
+
}
|
|
219
161
|
// Current Relative Humidity
|
|
220
|
-
this.CurrentRelativeHumidity =
|
|
221
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
162
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
164
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
222
165
|
// Active
|
|
223
|
-
if (
|
|
224
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
166
|
+
if (serviceData.onState) {
|
|
167
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
225
168
|
}
|
|
226
169
|
else {
|
|
227
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
170
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
228
171
|
}
|
|
229
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
230
173
|
}
|
|
231
|
-
async openAPIparseStatus() {
|
|
174
|
+
async openAPIparseStatus(deviceStatus) {
|
|
232
175
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
233
176
|
// Current Relative Humidity
|
|
234
|
-
this.CurrentRelativeHumidity =
|
|
235
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
177
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature;
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
179
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
236
180
|
// Current Temperature
|
|
237
181
|
if (!this.device.humidifier?.hide_temperature) {
|
|
238
|
-
this.CurrentTemperature =
|
|
239
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
182
|
+
this.TemperatureSensor.CurrentTemperature = deviceStatus.body.temperature;
|
|
183
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
240
184
|
}
|
|
241
185
|
// Target Humidifier Dehumidifier State
|
|
242
|
-
switch (
|
|
186
|
+
switch (deviceStatus.body.auto) {
|
|
243
187
|
case true:
|
|
244
|
-
this.TargetHumidifierDehumidifierState =
|
|
245
|
-
|
|
246
|
-
this.
|
|
188
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
189
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
190
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
191
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
247
192
|
break;
|
|
248
193
|
default:
|
|
249
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
250
|
-
if (
|
|
251
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
194
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
195
|
+
if (deviceStatus.body.nebulizationEfficiency > 100) {
|
|
196
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
252
197
|
}
|
|
253
198
|
else {
|
|
254
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
199
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
255
200
|
}
|
|
256
|
-
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
257
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
201
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
202
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
258
203
|
}
|
|
259
|
-
else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
260
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
204
|
+
else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
205
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
261
206
|
}
|
|
262
207
|
else {
|
|
263
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
208
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
264
209
|
}
|
|
265
210
|
}
|
|
266
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
212
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
213
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
214
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
215
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
216
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
270
217
|
// Active
|
|
271
|
-
switch (
|
|
218
|
+
switch (deviceStatus.body.power) {
|
|
272
219
|
case 'on':
|
|
273
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
220
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
274
221
|
break;
|
|
275
222
|
default:
|
|
276
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
223
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
277
224
|
}
|
|
278
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
279
226
|
// Water Level
|
|
280
|
-
if (
|
|
281
|
-
this.WaterLevel = 0;
|
|
227
|
+
if (deviceStatus.body.lackWater) {
|
|
228
|
+
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
282
229
|
}
|
|
283
230
|
else {
|
|
284
|
-
this.WaterLevel = 100;
|
|
231
|
+
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
285
232
|
}
|
|
286
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
287
234
|
// FirmwareRevision
|
|
288
|
-
this.FirmwareRevision =
|
|
289
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
235
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
290
236
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Asks the SwitchBot API for the latest device information
|
|
293
|
-
*/
|
|
294
237
|
async refreshStatus() {
|
|
295
238
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
296
239
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -320,88 +263,34 @@ export class Humidifier {
|
|
|
320
263
|
// Start to monitor advertisement packets
|
|
321
264
|
(async () => {
|
|
322
265
|
// Start to monitor advertisement packets
|
|
323
|
-
await switchbot.startScan({
|
|
324
|
-
model: 'e',
|
|
325
|
-
id: this.device.bleMac,
|
|
326
|
-
});
|
|
266
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
327
267
|
// Set an event handler
|
|
328
268
|
switchbot.onadvertisement = (ad) => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
269
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
270
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
332
272
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
333
|
-
this.autoMode = ad.serviceData.autoMode;
|
|
334
|
-
this.onState = ad.serviceData.onState;
|
|
335
|
-
this.percentage = ad.serviceData.percentage > 100 ? 100 : ad.serviceData.percentage;
|
|
336
273
|
}
|
|
337
274
|
else {
|
|
338
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
339
276
|
}
|
|
340
277
|
};
|
|
341
|
-
// Wait
|
|
278
|
+
// Wait 10 seconds
|
|
342
279
|
await switchbot.wait(this.scanDuration * 1000);
|
|
343
280
|
// Stop to monitor
|
|
344
281
|
await switchbot.stopScan();
|
|
345
282
|
// Update HomeKit
|
|
346
|
-
await this.BLEparseStatus();
|
|
283
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
347
284
|
await this.updateHomeKitCharacteristics();
|
|
348
285
|
})();
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
model: 'e',
|
|
353
|
-
id: this.device.bleMac,
|
|
354
|
-
})
|
|
355
|
-
.then(async () => {
|
|
356
|
-
// Set an event handler
|
|
357
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
358
|
-
this.debugLog(
|
|
359
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
360
|
-
` BLE Address Found: ${ad.address}`,
|
|
361
|
-
);
|
|
362
|
-
this.autoMode = ad.serviceData.autoMode;
|
|
363
|
-
this.onState = ad.serviceData.onState;
|
|
364
|
-
this.percentage = ad.serviceData.percentage;
|
|
365
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
366
|
-
this.debugLog(
|
|
367
|
-
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
368
|
-
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
if (ad.serviceData) {
|
|
372
|
-
this.connected = true;
|
|
373
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
374
|
-
await this.stopScanning(switchbot);
|
|
375
|
-
} else {
|
|
376
|
-
this.connected = false;
|
|
377
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
// Wait
|
|
381
|
-
return await sleep(this.scanDuration * 1000);
|
|
382
|
-
})
|
|
383
|
-
.then(async () => {
|
|
384
|
-
// Stop to monitor
|
|
385
|
-
await this.stopScanning(switchbot);
|
|
386
|
-
})
|
|
387
|
-
.catch(async (e: any) => {
|
|
388
|
-
this.apiError(e);
|
|
389
|
-
this.errorLog(
|
|
390
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
391
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
392
|
-
);
|
|
393
|
-
await this.BLERefreshConnection(switchbot);
|
|
394
|
-
});
|
|
395
|
-
} else {
|
|
396
|
-
await this.BLERefreshConnection(switchbot);
|
|
397
|
-
}*/
|
|
286
|
+
if (switchbot === undefined) {
|
|
287
|
+
await this.BLERefreshConnection(switchbot);
|
|
288
|
+
}
|
|
398
289
|
}
|
|
399
290
|
async openAPIRefreshStatus() {
|
|
400
291
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
401
292
|
try {
|
|
402
|
-
const { body, statusCode } = await this.platform.retryRequest(this.
|
|
403
|
-
headers: this.platform.generateHeaders(),
|
|
404
|
-
});
|
|
293
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
405
294
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
406
295
|
const deviceStatus = await body.json();
|
|
407
296
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -409,14 +298,7 @@ export class Humidifier {
|
|
|
409
298
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
410
299
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
411
300
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
412
|
-
this.
|
|
413
|
-
this.OpenAPI_Active = deviceStatus.body.power;
|
|
414
|
-
this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
|
|
415
|
-
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
416
|
-
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
417
|
-
this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
418
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
419
|
-
this.openAPIparseStatus();
|
|
301
|
+
this.openAPIparseStatus(deviceStatus);
|
|
420
302
|
this.updateHomeKitCharacteristics();
|
|
421
303
|
}
|
|
422
304
|
else {
|
|
@@ -468,13 +350,13 @@ export class Humidifier {
|
|
|
468
350
|
id: this.device.bleMac,
|
|
469
351
|
})
|
|
470
352
|
.then(async (device_list) => {
|
|
471
|
-
this.infoLog(`${this.accessory.displayName} Active: ${this.Active}`);
|
|
472
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
353
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
354
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
473
355
|
})
|
|
474
356
|
.then(() => {
|
|
475
357
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
476
358
|
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
477
|
-
+ `Active: ${this.Active} sent over BLE, sent successfully`);
|
|
359
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
478
360
|
})
|
|
479
361
|
.catch(async (e) => {
|
|
480
362
|
this.apiError(e);
|
|
@@ -485,12 +367,13 @@ export class Humidifier {
|
|
|
485
367
|
}
|
|
486
368
|
async openAPIpushChanges() {
|
|
487
369
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
488
|
-
if (this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
489
|
-
this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
490
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
370
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
371
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
373
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
491
374
|
const bodyChange = JSON.stringify({
|
|
492
375
|
command: 'setMode',
|
|
493
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
376
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
494
377
|
commandType: 'command',
|
|
495
378
|
});
|
|
496
379
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -522,8 +405,9 @@ export class Humidifier {
|
|
|
522
405
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
523
406
|
}
|
|
524
407
|
}
|
|
525
|
-
else if (this.TargetHumidifierDehumidifierState ===
|
|
526
|
-
this.
|
|
408
|
+
else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
409
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
410
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
527
411
|
await this.pushAutoChanges();
|
|
528
412
|
}
|
|
529
413
|
else {
|
|
@@ -535,8 +419,9 @@ export class Humidifier {
|
|
|
535
419
|
*/
|
|
536
420
|
async pushAutoChanges() {
|
|
537
421
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
538
|
-
if (this.TargetHumidifierDehumidifierState ===
|
|
539
|
-
this.
|
|
422
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
423
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
424
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
540
425
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
541
426
|
const bodyChange = JSON.stringify({
|
|
542
427
|
command: 'setMode',
|
|
@@ -573,8 +458,8 @@ export class Humidifier {
|
|
|
573
458
|
}
|
|
574
459
|
}
|
|
575
460
|
else {
|
|
576
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges
|
|
577
|
-
`
|
|
461
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
462
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
578
463
|
}
|
|
579
464
|
}
|
|
580
465
|
/**
|
|
@@ -582,7 +467,7 @@ export class Humidifier {
|
|
|
582
467
|
*/
|
|
583
468
|
async pushActiveChanges() {
|
|
584
469
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
585
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
470
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
586
471
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
587
472
|
const bodyChange = JSON.stringify({
|
|
588
473
|
command: 'turnOff',
|
|
@@ -619,49 +504,49 @@ export class Humidifier {
|
|
|
619
504
|
}
|
|
620
505
|
}
|
|
621
506
|
else {
|
|
622
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
507
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
623
508
|
}
|
|
624
509
|
}
|
|
625
510
|
/**
|
|
626
511
|
* Handle requests to set the "Active" characteristic
|
|
627
512
|
*/
|
|
628
513
|
async ActiveSet(value) {
|
|
629
|
-
if (this.Active === this.accessory.context.Active) {
|
|
514
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
630
515
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
631
516
|
}
|
|
632
517
|
else {
|
|
633
518
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
634
519
|
}
|
|
635
|
-
this.Active = value;
|
|
520
|
+
this.HumidifierDehumidifier.Active = value;
|
|
636
521
|
this.doHumidifierUpdate.next();
|
|
637
522
|
}
|
|
638
523
|
/**
|
|
639
524
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
640
525
|
*/
|
|
641
526
|
async TargetHumidifierDehumidifierStateSet(value) {
|
|
642
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
527
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
643
528
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
644
529
|
}
|
|
645
530
|
else {
|
|
646
531
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
647
532
|
}
|
|
648
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
533
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
649
534
|
this.doHumidifierUpdate.next();
|
|
650
535
|
}
|
|
651
536
|
/**
|
|
652
537
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
653
538
|
*/
|
|
654
539
|
async RelativeHumidityHumidifierThresholdSet(value) {
|
|
655
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
540
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
656
541
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
657
542
|
}
|
|
658
543
|
else {
|
|
659
544
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
660
545
|
}
|
|
661
|
-
this.RelativeHumidityHumidifierThreshold = value;
|
|
662
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
663
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
664
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
546
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
547
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
548
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
549
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
665
550
|
}
|
|
666
551
|
this.doHumidifierUpdate.next();
|
|
667
552
|
}
|
|
@@ -669,99 +554,77 @@ export class Humidifier {
|
|
|
669
554
|
* Updates the status for each of the HomeKit Characteristics
|
|
670
555
|
*/
|
|
671
556
|
async updateHomeKitCharacteristics() {
|
|
672
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
673
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
557
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
558
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
559
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
674
560
|
}
|
|
675
561
|
else {
|
|
676
|
-
this.
|
|
677
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
678
|
-
|
|
562
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
564
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
565
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
679
566
|
}
|
|
680
567
|
if (this.OpenAPI) {
|
|
681
|
-
if (this.WaterLevel === undefined) {
|
|
682
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
568
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
569
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
683
570
|
}
|
|
684
571
|
else {
|
|
685
|
-
this.
|
|
686
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
687
|
-
|
|
572
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
573
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
574
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
575
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
688
576
|
}
|
|
689
577
|
}
|
|
690
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
578
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
691
579
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
692
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
580
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
693
581
|
}
|
|
694
582
|
else {
|
|
695
|
-
this.
|
|
696
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
697
|
-
`
|
|
698
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
583
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
584
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
585
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
586
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
699
587
|
}
|
|
700
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
701
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
588
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
589
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
590
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
702
591
|
}
|
|
703
592
|
else {
|
|
704
|
-
this.
|
|
705
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
706
|
-
`
|
|
707
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
593
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
594
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
595
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
596
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
708
597
|
}
|
|
709
|
-
if (this.Active === undefined) {
|
|
710
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
598
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
711
600
|
}
|
|
712
601
|
else {
|
|
713
|
-
this.
|
|
714
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
715
|
-
this.accessory.context.Active = this.Active;
|
|
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;
|
|
716
605
|
}
|
|
717
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
606
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
718
607
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
719
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
608
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
720
609
|
}
|
|
721
610
|
else {
|
|
722
|
-
this.
|
|
723
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
724
|
-
`
|
|
725
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
611
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, 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;
|
|
726
615
|
}
|
|
727
616
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
728
|
-
if (this.CurrentTemperature === undefined) {
|
|
729
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
617
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
618
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
730
619
|
}
|
|
731
620
|
else {
|
|
732
|
-
this.
|
|
733
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
734
|
-
|
|
621
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
622
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
623
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
624
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
735
625
|
}
|
|
736
626
|
}
|
|
737
627
|
}
|
|
738
|
-
async stopScanning(switchbot) {
|
|
739
|
-
switchbot.stopScan();
|
|
740
|
-
if (this.connected) {
|
|
741
|
-
await this.BLEparseStatus();
|
|
742
|
-
await this.updateHomeKitCharacteristics();
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
await this.BLERefreshConnection(switchbot);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
async getCustomBLEAddress(switchbot) {
|
|
749
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
750
|
-
(async () => {
|
|
751
|
-
// Start to monitor advertisement packets
|
|
752
|
-
await switchbot.startScan({
|
|
753
|
-
model: 'e',
|
|
754
|
-
});
|
|
755
|
-
// Set an event handler
|
|
756
|
-
switchbot.onadvertisement = (ad) => {
|
|
757
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
758
|
-
};
|
|
759
|
-
await sleep(10000);
|
|
760
|
-
// Stop to monitor
|
|
761
|
-
switchbot.stopScan();
|
|
762
|
-
})();
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
628
|
async BLEPushConnection() {
|
|
766
629
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
767
630
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -776,302 +639,36 @@ export class Humidifier {
|
|
|
776
639
|
await this.openAPIRefreshStatus();
|
|
777
640
|
}
|
|
778
641
|
}
|
|
779
|
-
minStep() {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
else {
|
|
784
|
-
this.set_minStep = 1;
|
|
785
|
-
}
|
|
786
|
-
return this.set_minStep;
|
|
787
|
-
}
|
|
788
|
-
async scan(device) {
|
|
789
|
-
if (device.scanDuration) {
|
|
790
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
791
|
-
if (this.BLE) {
|
|
792
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
793
|
-
}
|
|
642
|
+
minStep(device) {
|
|
643
|
+
let set_minStep;
|
|
644
|
+
if (device.humidifier?.set_minStep) {
|
|
645
|
+
set_minStep = device.humidifier?.set_minStep;
|
|
794
646
|
}
|
|
795
647
|
else {
|
|
796
|
-
|
|
797
|
-
if (this.BLE) {
|
|
798
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
async statusCode(statusCode) {
|
|
803
|
-
switch (statusCode) {
|
|
804
|
-
case 151:
|
|
805
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
806
|
-
break;
|
|
807
|
-
case 152:
|
|
808
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
809
|
-
break;
|
|
810
|
-
case 160:
|
|
811
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
812
|
-
break;
|
|
813
|
-
case 161:
|
|
814
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
815
|
-
this.offlineOff();
|
|
816
|
-
break;
|
|
817
|
-
case 171:
|
|
818
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
819
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
820
|
-
this.offlineOff();
|
|
821
|
-
break;
|
|
822
|
-
case 190:
|
|
823
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
824
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
825
|
-
break;
|
|
826
|
-
case 100:
|
|
827
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
828
|
-
break;
|
|
829
|
-
case 200:
|
|
830
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
831
|
-
break;
|
|
832
|
-
case 400:
|
|
833
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
834
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
835
|
-
break;
|
|
836
|
-
case 401:
|
|
837
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
838
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
839
|
-
break;
|
|
840
|
-
case 403:
|
|
841
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
842
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
843
|
-
break;
|
|
844
|
-
case 404:
|
|
845
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
846
|
-
+ `statusCode: ${statusCode}`);
|
|
847
|
-
break;
|
|
848
|
-
case 406:
|
|
849
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
850
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
851
|
-
break;
|
|
852
|
-
case 415:
|
|
853
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
854
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
855
|
-
break;
|
|
856
|
-
case 422:
|
|
857
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
858
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
859
|
-
break;
|
|
860
|
-
case 429:
|
|
861
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
862
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
863
|
-
break;
|
|
864
|
-
case 500:
|
|
865
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
866
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
867
|
-
break;
|
|
868
|
-
default:
|
|
869
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
870
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
648
|
+
set_minStep = 1;
|
|
871
649
|
}
|
|
650
|
+
return set_minStep;
|
|
872
651
|
}
|
|
873
652
|
async offlineOff() {
|
|
874
653
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
875
654
|
if (this.device.offline) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
}
|
|
880
|
-
await this.updateHomeKitCharacteristics();
|
|
655
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
656
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
657
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
881
658
|
}
|
|
882
659
|
}
|
|
883
660
|
async apiError(e) {
|
|
884
|
-
this.
|
|
661
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
885
662
|
if (!this.BLE) {
|
|
886
|
-
this.
|
|
663
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
887
664
|
}
|
|
888
|
-
this.
|
|
889
|
-
this.
|
|
890
|
-
this.
|
|
891
|
-
this.
|
|
665
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
666
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
667
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
668
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
892
669
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
893
|
-
this.
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
async deviceContext() {
|
|
897
|
-
if (this.Active === undefined) {
|
|
898
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
670
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
899
671
|
}
|
|
900
|
-
else {
|
|
901
|
-
this.Active = this.accessory.context.Active;
|
|
902
|
-
}
|
|
903
|
-
if (this.CurrentTemperature === undefined) {
|
|
904
|
-
this.CurrentTemperature = 30;
|
|
905
|
-
}
|
|
906
|
-
else {
|
|
907
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
908
|
-
}
|
|
909
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
910
|
-
this.CurrentRelativeHumidity = 0;
|
|
911
|
-
}
|
|
912
|
-
else {
|
|
913
|
-
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
914
|
-
}
|
|
915
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
916
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
917
|
-
}
|
|
918
|
-
else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
919
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
920
|
-
}
|
|
921
|
-
else {
|
|
922
|
-
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
923
|
-
}
|
|
924
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
925
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
926
|
-
}
|
|
927
|
-
else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
|
|
928
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
929
|
-
}
|
|
930
|
-
else {
|
|
931
|
-
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
932
|
-
}
|
|
933
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
934
|
-
this.RelativeHumidityHumidifierThreshold = 0;
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
|
|
938
|
-
}
|
|
939
|
-
if (this.WaterLevel === undefined) {
|
|
940
|
-
this.WaterLevel = 0;
|
|
941
|
-
}
|
|
942
|
-
else {
|
|
943
|
-
this.WaterLevel = this.accessory.context.WaterLevel;
|
|
944
|
-
}
|
|
945
|
-
if (this.FirmwareRevision === undefined) {
|
|
946
|
-
this.FirmwareRevision = this.platform.version;
|
|
947
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
async refreshRate(device) {
|
|
951
|
-
if (device.refreshRate) {
|
|
952
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
953
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
954
|
-
}
|
|
955
|
-
else if (this.platform.config.options.refreshRate) {
|
|
956
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
957
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
async deviceRetry(device) {
|
|
961
|
-
if (!device.maxRetries) {
|
|
962
|
-
this.maxRetries = 5; // Maximum number of retries
|
|
963
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
964
|
-
}
|
|
965
|
-
else {
|
|
966
|
-
this.maxRetries = device.maxRetries;
|
|
967
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
968
|
-
}
|
|
969
|
-
if (!device.delayBetweenRetries) {
|
|
970
|
-
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
971
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
972
|
-
}
|
|
973
|
-
else {
|
|
974
|
-
this.delayBetweenRetries = device.delayBetweenRetries * 1000;
|
|
975
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
async deviceConfig(device) {
|
|
979
|
-
let config = {};
|
|
980
|
-
if (device.humidifier) {
|
|
981
|
-
config = device.humidifier;
|
|
982
|
-
}
|
|
983
|
-
if (device.connectionType !== undefined) {
|
|
984
|
-
config['connectionType'] = device.connectionType;
|
|
985
|
-
}
|
|
986
|
-
if (device.external !== undefined) {
|
|
987
|
-
config['external'] = device.external;
|
|
988
|
-
}
|
|
989
|
-
if (device.logging !== undefined) {
|
|
990
|
-
config['logging'] = device.logging;
|
|
991
|
-
}
|
|
992
|
-
if (device.refreshRate !== undefined) {
|
|
993
|
-
config['refreshRate'] = device.refreshRate;
|
|
994
|
-
}
|
|
995
|
-
if (device.scanDuration !== undefined) {
|
|
996
|
-
config['scanDuration'] = device.scanDuration;
|
|
997
|
-
}
|
|
998
|
-
if (device.offline !== undefined) {
|
|
999
|
-
config['offline'] = device.offline;
|
|
1000
|
-
}
|
|
1001
|
-
if (device.webhook !== undefined) {
|
|
1002
|
-
config['webhook'] = device.webhook;
|
|
1003
|
-
}
|
|
1004
|
-
if (Object.entries(config).length !== 0) {
|
|
1005
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
async deviceLogs(device) {
|
|
1009
|
-
if (this.platform.debugMode) {
|
|
1010
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1011
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1012
|
-
}
|
|
1013
|
-
else if (device.logging) {
|
|
1014
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1015
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1016
|
-
}
|
|
1017
|
-
else if (this.platform.config.options?.logging) {
|
|
1018
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1019
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1020
|
-
}
|
|
1021
|
-
else {
|
|
1022
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1023
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Logging for Device
|
|
1028
|
-
*/
|
|
1029
|
-
successLog(...log) {
|
|
1030
|
-
if (this.enablingDeviceLogging()) {
|
|
1031
|
-
this.platform.log.success(String(...log));
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
async infoLog(...log) {
|
|
1035
|
-
if (this.enablingDeviceLogging()) {
|
|
1036
|
-
this.platform.log.info(String(...log));
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
async warnLog(...log) {
|
|
1040
|
-
if (this.enablingDeviceLogging()) {
|
|
1041
|
-
this.platform.log.warn(String(...log));
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
async debugWarnLog(...log) {
|
|
1045
|
-
if (this.enablingDeviceLogging()) {
|
|
1046
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1047
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
async errorLog(...log) {
|
|
1052
|
-
if (this.enablingDeviceLogging()) {
|
|
1053
|
-
this.platform.log.error(String(...log));
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
async debugErrorLog(...log) {
|
|
1057
|
-
if (this.enablingDeviceLogging()) {
|
|
1058
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1059
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
async debugLog(...log) {
|
|
1064
|
-
if (this.enablingDeviceLogging()) {
|
|
1065
|
-
if (this.deviceLogging === 'debug') {
|
|
1066
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1067
|
-
}
|
|
1068
|
-
else {
|
|
1069
|
-
this.platform.log.debug(String(...log));
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
enablingDeviceLogging() {
|
|
1074
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1075
672
|
}
|
|
1076
673
|
}
|
|
1077
674
|
//# sourceMappingURL=humidifier.js.map
|