@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.0
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/.eslintrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +8 -0
- package/config.schema.json +9 -0
- package/dist/devices/bots.d.ts +37 -34
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +196 -243
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +131 -145
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +29 -27
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +115 -138
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +31 -29
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +176 -211
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +189 -214
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +31 -30
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +100 -124
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +26 -25
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +102 -120
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +63 -81
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -22
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +79 -105
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +42 -56
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +27 -31
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +38 -45
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +33 -37
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +29 -34
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +76 -91
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +27 -31
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +27 -31
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +172 -241
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +71 -72
- package/src/devices/bots.ts +455 -929
- package/src/devices/colorbulb.ts +246 -473
- package/src/devices/contact.ts +208 -381
- package/src/devices/curtains.ts +321 -613
- package/src/devices/humidifiers.ts +323 -594
- package/src/devices/meters.ts +186 -331
- package/src/devices/motion.ts +184 -327
- package/src/devices/plugs.ts +107 -175
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +149 -360
- package/src/irdevices/airpurifiers.ts +80 -178
- package/src/irdevices/cameras.ts +51 -109
- package/src/irdevices/fans.ts +77 -174
- package/src/irdevices/lights.ts +57 -110
- package/src/irdevices/others.ts +62 -137
- package/src/irdevices/tvs.ts +124 -249
- package/src/irdevices/vacuumcleaners.ts +52 -112
- package/src/irdevices/waterheaters.ts +53 -115
- package/src/platform.ts +357 -768
- package/src/settings.ts +24 -17
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { interval, Subject } from 'rxjs';
|
|
3
|
+
import { SwitchBotPlatform } from '../platform';
|
|
4
|
+
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
|
+
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
|
+
import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
@@ -12,34 +12,33 @@ import * as settings from "../settings";
|
|
|
12
12
|
*/
|
|
13
13
|
export class Humidifier {
|
|
14
14
|
// Services
|
|
15
|
-
private service:
|
|
16
|
-
temperatureservice?:
|
|
15
|
+
private service: Service;
|
|
16
|
+
temperatureservice?: Service;
|
|
17
17
|
|
|
18
18
|
// Characteristic Values
|
|
19
|
-
CurrentRelativeHumidity!:
|
|
20
|
-
CurrentTemperature!:
|
|
21
|
-
TargetHumidifierDehumidifierState!:
|
|
22
|
-
CurrentHumidifierDehumidifierState!:
|
|
23
|
-
RelativeHumidityHumidifierThreshold!:
|
|
24
|
-
Active!:
|
|
25
|
-
WaterLevel!:
|
|
19
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
20
|
+
CurrentTemperature!: CharacteristicValue;
|
|
21
|
+
TargetHumidifierDehumidifierState!: CharacteristicValue;
|
|
22
|
+
CurrentHumidifierDehumidifierState!: CharacteristicValue;
|
|
23
|
+
RelativeHumidityHumidifierThreshold!: CharacteristicValue;
|
|
24
|
+
Active!: CharacteristicValue;
|
|
25
|
+
WaterLevel!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI
|
|
28
|
-
auto:
|
|
29
|
-
power:
|
|
30
|
-
humidity:
|
|
31
|
-
lackWater:
|
|
32
|
-
temperature:
|
|
33
|
-
nebulizationEfficiency:
|
|
34
|
-
deviceStatus!:
|
|
28
|
+
auto: deviceStatus['auto'];
|
|
29
|
+
power: deviceStatus['power'];
|
|
30
|
+
humidity: deviceStatus['humidity'];
|
|
31
|
+
lackWater: deviceStatus['lackWater'];
|
|
32
|
+
temperature: deviceStatus['temperature'];
|
|
33
|
+
nebulizationEfficiency: deviceStatus['nebulizationEfficiency'];
|
|
34
|
+
deviceStatus!: deviceStatusResponse;
|
|
35
35
|
|
|
36
36
|
// BLE Others
|
|
37
37
|
connected?: boolean;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
percentage!: settings.serviceData["percentage"];
|
|
38
|
+
serviceData!: serviceData;
|
|
39
|
+
onState!: serviceData['onState'];
|
|
40
|
+
autoMode!: serviceData['autoMode'];
|
|
41
|
+
percentage!: serviceData['percentage'];
|
|
43
42
|
|
|
44
43
|
// Config
|
|
45
44
|
set_minStep?: number;
|
|
@@ -49,12 +48,12 @@ export class Humidifier {
|
|
|
49
48
|
|
|
50
49
|
// Updates
|
|
51
50
|
humidifierUpdateInProgress!: boolean;
|
|
52
|
-
doHumidifierUpdate!:
|
|
51
|
+
doHumidifierUpdate!: Subject<void>;
|
|
53
52
|
|
|
54
53
|
constructor(
|
|
55
|
-
private readonly platform:
|
|
56
|
-
private accessory:
|
|
57
|
-
public device:
|
|
54
|
+
private readonly platform: SwitchBotPlatform,
|
|
55
|
+
private accessory: PlatformAccessory,
|
|
56
|
+
public device: device & devicesConfig,
|
|
58
57
|
) {
|
|
59
58
|
// default placeholders
|
|
60
59
|
this.logs(device);
|
|
@@ -62,17 +61,19 @@ export class Humidifier {
|
|
|
62
61
|
this.refreshRate(device);
|
|
63
62
|
this.config(device);
|
|
64
63
|
this.CurrentRelativeHumidity = 0;
|
|
65
|
-
this.TargetHumidifierDehumidifierState =
|
|
66
|
-
|
|
67
|
-
this.CurrentHumidifierDehumidifierState =
|
|
68
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
64
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
65
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
69
66
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
70
67
|
this.RelativeHumidityHumidifierThreshold = 0;
|
|
71
68
|
this.CurrentTemperature = 0;
|
|
72
69
|
this.WaterLevel = 0;
|
|
73
70
|
|
|
71
|
+
// Humidifiers Config
|
|
72
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
|
|
73
|
+
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
|
|
74
|
+
|
|
74
75
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
75
|
-
this.doHumidifierUpdate = new
|
|
76
|
+
this.doHumidifierUpdate = new Subject();
|
|
76
77
|
this.humidifierUpdateInProgress = false;
|
|
77
78
|
|
|
78
79
|
// Retrieve initial values and updateHomekit
|
|
@@ -81,22 +82,15 @@ export class Humidifier {
|
|
|
81
82
|
// set accessory information
|
|
82
83
|
accessory
|
|
83
84
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
84
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
85
|
-
.setCharacteristic(
|
|
86
|
-
|
|
87
|
-
"SWITCHBOT-HUMIDIFIER-W0801800",
|
|
88
|
-
)
|
|
89
|
-
.setCharacteristic(
|
|
90
|
-
this.platform.Characteristic.SerialNumber,
|
|
91
|
-
device.deviceId!,
|
|
92
|
-
);
|
|
85
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
86
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-HUMIDIFIER-W0801800')
|
|
87
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
93
88
|
|
|
94
89
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
95
90
|
// you can create multiple services for each accessory
|
|
96
91
|
(this.service =
|
|
97
92
|
accessory.getService(this.platform.Service.HumidifierDehumidifier) ||
|
|
98
|
-
accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
99
|
-
`${accessory.displayName} Humidifier`;
|
|
93
|
+
accessory.addService(this.platform.Service.HumidifierDehumidifier)), `${accessory.displayName} Humidifier`;
|
|
100
94
|
|
|
101
95
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
102
96
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -104,10 +98,7 @@ export class Humidifier {
|
|
|
104
98
|
|
|
105
99
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
106
100
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
107
|
-
this.service.setCharacteristic(
|
|
108
|
-
this.platform.Characteristic.Name,
|
|
109
|
-
accessory.displayName,
|
|
110
|
-
);
|
|
101
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
111
102
|
|
|
112
103
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
113
104
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
@@ -119,9 +110,7 @@ export class Humidifier {
|
|
|
119
110
|
);
|
|
120
111
|
|
|
121
112
|
this.service
|
|
122
|
-
.getCharacteristic(
|
|
123
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
124
|
-
)
|
|
113
|
+
.getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
|
|
125
114
|
.setProps({
|
|
126
115
|
validValueRanges: [0, 1],
|
|
127
116
|
minValue: 0,
|
|
@@ -130,14 +119,10 @@ export class Humidifier {
|
|
|
130
119
|
})
|
|
131
120
|
.onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
|
|
132
121
|
|
|
133
|
-
this.service
|
|
134
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
135
|
-
.onSet(this.handleActiveSet.bind(this));
|
|
122
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
|
|
136
123
|
|
|
137
124
|
this.service
|
|
138
|
-
.getCharacteristic(
|
|
139
|
-
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
140
|
-
)
|
|
125
|
+
.getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
141
126
|
.setProps({
|
|
142
127
|
validValueRanges: [0, 100],
|
|
143
128
|
minValue: 0,
|
|
@@ -149,26 +134,16 @@ export class Humidifier {
|
|
|
149
134
|
// create a new Temperature Sensor service
|
|
150
135
|
// Temperature Sensor Service
|
|
151
136
|
if (device.humidifier?.hide_temperature || device.ble) {
|
|
152
|
-
this.debugLog(
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
this.temperatureservice = this.accessory.getService(
|
|
156
|
-
this.platform.Service.TemperatureSensor,
|
|
157
|
-
);
|
|
137
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
138
|
+
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
158
139
|
accessory.removeService(this.temperatureservice!);
|
|
159
140
|
} else if (!this.temperatureservice && !device.ble) {
|
|
160
|
-
this.debugLog(
|
|
161
|
-
`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`,
|
|
162
|
-
);
|
|
141
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
163
142
|
(this.temperatureservice =
|
|
164
143
|
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
165
|
-
this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
166
|
-
`${accessory.displayName} Temperature Sensor`;
|
|
144
|
+
this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
|
|
167
145
|
|
|
168
|
-
this.temperatureservice.setCharacteristic(
|
|
169
|
-
this.platform.Characteristic.Name,
|
|
170
|
-
`${accessory.displayName} Temperature Sensor`,
|
|
171
|
-
);
|
|
146
|
+
this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
172
147
|
|
|
173
148
|
this.temperatureservice
|
|
174
149
|
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
@@ -182,18 +157,15 @@ export class Humidifier {
|
|
|
182
157
|
return this.CurrentTemperature;
|
|
183
158
|
});
|
|
184
159
|
} else {
|
|
185
|
-
this.debugLog(
|
|
186
|
-
`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`,
|
|
187
|
-
);
|
|
160
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
188
161
|
}
|
|
189
162
|
|
|
190
163
|
// Retrieve initial values and updateHomekit
|
|
191
164
|
this.updateHomeKitCharacteristics();
|
|
192
165
|
|
|
193
166
|
// Start an update interval
|
|
194
|
-
|
|
195
|
-
.
|
|
196
|
-
.pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
|
|
167
|
+
interval(this.deviceRefreshRate * 1000)
|
|
168
|
+
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
197
169
|
.subscribe(() => {
|
|
198
170
|
this.refreshStatus();
|
|
199
171
|
});
|
|
@@ -202,23 +174,23 @@ export class Humidifier {
|
|
|
202
174
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
203
175
|
this.doHumidifierUpdate
|
|
204
176
|
.pipe(
|
|
205
|
-
|
|
177
|
+
tap(() => {
|
|
206
178
|
this.humidifierUpdateInProgress = true;
|
|
207
179
|
}),
|
|
208
|
-
|
|
180
|
+
debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
209
181
|
)
|
|
210
182
|
.subscribe(async () => {
|
|
211
183
|
try {
|
|
212
184
|
await this.pushChanges();
|
|
213
185
|
} catch (e: any) {
|
|
214
|
-
this.errorLog(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
186
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
187
|
+
if (this.deviceLogging === 'debug') {
|
|
188
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
189
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
190
|
+
}
|
|
191
|
+
if (this.platform.debugMode) {
|
|
192
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
|
|
193
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
222
194
|
}
|
|
223
195
|
this.apiError(e);
|
|
224
196
|
}
|
|
@@ -229,7 +201,7 @@ export class Humidifier {
|
|
|
229
201
|
/**
|
|
230
202
|
* Parse the device status from the SwitchBot api
|
|
231
203
|
*/
|
|
232
|
-
parseStatus()
|
|
204
|
+
parseStatus() {
|
|
233
205
|
if (this.device.ble) {
|
|
234
206
|
this.BLEparseStatus();
|
|
235
207
|
} else {
|
|
@@ -237,106 +209,73 @@ export class Humidifier {
|
|
|
237
209
|
}
|
|
238
210
|
}
|
|
239
211
|
|
|
240
|
-
private BLEparseStatus()
|
|
212
|
+
private BLEparseStatus() {
|
|
241
213
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
|
|
242
214
|
// Current Relative Humidity
|
|
243
215
|
this.CurrentRelativeHumidity = this.percentage!;
|
|
244
|
-
this.debugLog(
|
|
245
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
246
|
-
);
|
|
216
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
247
217
|
// Active
|
|
248
218
|
if (this.onState) {
|
|
249
219
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
250
220
|
} else {
|
|
251
221
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
252
222
|
}
|
|
253
|
-
this.debugLog(
|
|
254
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
255
|
-
);
|
|
223
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
256
224
|
}
|
|
257
225
|
|
|
258
226
|
private openAPIparseStatus() {
|
|
259
227
|
if (this.platform.config.credentials?.openToken) {
|
|
260
|
-
this.debugLog(
|
|
261
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`,
|
|
262
|
-
);
|
|
228
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
263
229
|
// Current Relative Humidity
|
|
264
230
|
this.CurrentRelativeHumidity = this.humidity!;
|
|
265
|
-
this.debugLog(
|
|
266
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
267
|
-
);
|
|
231
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
268
232
|
// Current Temperature
|
|
269
233
|
if (!this.device.humidifier?.hide_temperature) {
|
|
270
234
|
this.CurrentTemperature = this.temperature!;
|
|
271
|
-
this.debugLog(
|
|
272
|
-
`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
|
|
273
|
-
);
|
|
235
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
274
236
|
}
|
|
275
237
|
// Target Humidifier Dehumidifier State
|
|
276
238
|
switch (this.auto) {
|
|
277
239
|
case true:
|
|
278
|
-
this.TargetHumidifierDehumidifierState =
|
|
279
|
-
|
|
280
|
-
this.
|
|
281
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
282
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
283
|
-
this.CurrentRelativeHumidity;
|
|
240
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
241
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
242
|
+
this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
|
|
284
243
|
break;
|
|
285
244
|
default:
|
|
286
|
-
this.TargetHumidifierDehumidifierState =
|
|
287
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
245
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
288
246
|
if (this.nebulizationEfficiency! > 100) {
|
|
289
247
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
290
248
|
} else {
|
|
291
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
292
|
-
this.nebulizationEfficiency!;
|
|
249
|
+
this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
|
|
293
250
|
}
|
|
294
|
-
if (
|
|
295
|
-
this.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
this.CurrentHumidifierDehumidifierState =
|
|
299
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
300
|
-
} else if (
|
|
301
|
-
this.Active === this.platform.Characteristic.Active.INACTIVE
|
|
302
|
-
) {
|
|
303
|
-
this.CurrentHumidifierDehumidifierState =
|
|
304
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
251
|
+
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
252
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
253
|
+
} else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
254
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
305
255
|
} else {
|
|
306
|
-
this.CurrentHumidifierDehumidifierState =
|
|
307
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
256
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
308
257
|
}
|
|
309
258
|
}
|
|
310
|
-
this.debugLog(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.debugLog(
|
|
314
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
315
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
316
|
-
);
|
|
317
|
-
this.debugLog(
|
|
318
|
-
`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
319
|
-
);
|
|
259
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
260
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
261
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
262
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
320
263
|
// Active
|
|
321
264
|
switch (this.power) {
|
|
322
|
-
case
|
|
265
|
+
case 'on':
|
|
323
266
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
324
267
|
break;
|
|
325
268
|
default:
|
|
326
269
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
327
270
|
}
|
|
328
|
-
this.debugLog(
|
|
329
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
330
|
-
);
|
|
271
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
331
272
|
// Water Level
|
|
332
273
|
if (this.lackWater) {
|
|
333
274
|
this.WaterLevel = 0;
|
|
334
275
|
} else {
|
|
335
276
|
this.WaterLevel = 100;
|
|
336
277
|
}
|
|
337
|
-
this.debugLog(
|
|
338
|
-
`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
|
|
339
|
-
);
|
|
278
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
340
279
|
}
|
|
341
280
|
}
|
|
342
281
|
|
|
@@ -352,138 +291,102 @@ export class Humidifier {
|
|
|
352
291
|
}
|
|
353
292
|
|
|
354
293
|
private async BLERefreshStatus() {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
`Humidifier: ${this.accessory.displayName} BLE refreshStatus`,
|
|
357
|
-
);
|
|
294
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
358
295
|
const switchbot = await this.platform.connectBLE();
|
|
359
296
|
// Convert to BLE Address
|
|
360
|
-
this.device.bleMac = this.device
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
);
|
|
367
|
-
try {
|
|
368
|
-
await switchbot.discover({
|
|
369
|
-
model: "e",
|
|
370
|
-
quick: false,
|
|
371
|
-
});
|
|
372
|
-
// Start to monitor advertisement packets
|
|
373
|
-
await switchbot.startScan({
|
|
374
|
-
model: "e",
|
|
297
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
298
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
299
|
+
// Start to monitor advertisement packets
|
|
300
|
+
if (switchbot !== false) {
|
|
301
|
+
switchbot.startScan({
|
|
302
|
+
model: 'e',
|
|
375
303
|
id: this.device.bleMac,
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
`Humidifier: ${
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
304
|
+
}).then(() => {
|
|
305
|
+
// Set an event hander
|
|
306
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
307
|
+
this.serviceData = ad.serviceData;
|
|
308
|
+
this.autoMode = ad.serviceData.autoMode;
|
|
309
|
+
this.onState = ad.serviceData.onState;
|
|
310
|
+
this.percentage = ad.serviceData.percentage;
|
|
311
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
312
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
|
|
313
|
+
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
|
|
314
|
+
|
|
315
|
+
if (this.serviceData) {
|
|
316
|
+
this.connected = true;
|
|
317
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
318
|
+
} else {
|
|
319
|
+
this.connected = false;
|
|
320
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
// Wait 2 seconds
|
|
324
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
325
|
+
}).then(async () => {
|
|
326
|
+
// Stop to monitor
|
|
327
|
+
switchbot.stopScan();
|
|
328
|
+
if (this.connected) {
|
|
329
|
+
this.parseStatus();
|
|
330
|
+
this.updateHomeKitCharacteristics();
|
|
398
331
|
} else {
|
|
399
|
-
this.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
332
|
+
await this.BLEconnection(switchbot);
|
|
333
|
+
}
|
|
334
|
+
}).catch(async (e: any) => {
|
|
335
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
336
|
+
if (this.deviceLogging === 'debug') {
|
|
337
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
338
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
339
|
+
}
|
|
340
|
+
if (this.platform.debugMode) {
|
|
341
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
342
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
403
343
|
}
|
|
404
|
-
};
|
|
405
|
-
// Wait 2 seconds
|
|
406
|
-
await switchbot.wait(this.scanDuration * 1000);
|
|
407
|
-
// Stop to monitor
|
|
408
|
-
switchbot.stopScan();
|
|
409
|
-
if (this.connected) {
|
|
410
|
-
this.parseStatus();
|
|
411
|
-
this.updateHomeKitCharacteristics();
|
|
412
|
-
} else {
|
|
413
|
-
this.errorLog(
|
|
414
|
-
`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
415
|
-
);
|
|
416
344
|
if (this.platform.config.credentials?.openToken) {
|
|
417
|
-
this.warnLog(
|
|
418
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
419
|
-
);
|
|
420
|
-
this.SwitchToOpenAPI = true;
|
|
345
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
421
346
|
await this.openAPIRefreshStatus();
|
|
422
347
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
this.warnLog(
|
|
436
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
437
|
-
);
|
|
438
|
-
this.SwitchToOpenAPI = true;
|
|
439
|
-
await this.openAPIRefreshStatus();
|
|
440
|
-
}
|
|
441
|
-
this.apiError(e);
|
|
348
|
+
this.apiError(e);
|
|
349
|
+
});
|
|
350
|
+
} else {
|
|
351
|
+
await this.BLEconnection(switchbot);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public async BLEconnection(switchbot: any) {
|
|
356
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
357
|
+
if (this.platform.config.credentials?.openToken) {
|
|
358
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
359
|
+
await this.openAPIRefreshStatus();
|
|
442
360
|
}
|
|
443
361
|
}
|
|
444
362
|
|
|
445
363
|
private async openAPIRefreshStatus() {
|
|
446
364
|
if (this.platform.config.credentials?.openToken) {
|
|
447
|
-
this.debugLog(
|
|
448
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`,
|
|
449
|
-
);
|
|
365
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
450
366
|
try {
|
|
451
|
-
this.deviceStatus = (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
)
|
|
455
|
-
).data;
|
|
456
|
-
if (this.deviceStatus.message === "success") {
|
|
457
|
-
this.debugLog(
|
|
458
|
-
`Humidifier: ${
|
|
459
|
-
this.accessory.displayName
|
|
460
|
-
} refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
|
|
461
|
-
);
|
|
367
|
+
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
368
|
+
if (this.deviceStatus.message === 'success') {
|
|
369
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
462
370
|
this.auto = this.deviceStatus.body.auto;
|
|
463
371
|
this.power = this.deviceStatus.body.power;
|
|
464
372
|
this.lackWater = this.deviceStatus.body.lackWater;
|
|
465
373
|
this.humidity = this.deviceStatus.body.humidity;
|
|
466
374
|
this.temperature = this.deviceStatus.body.temperature;
|
|
467
|
-
this.nebulizationEfficiency =
|
|
468
|
-
this.deviceStatus.body.nebulizationEfficiency;
|
|
375
|
+
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
469
376
|
this.parseStatus();
|
|
470
377
|
this.updateHomeKitCharacteristics();
|
|
471
378
|
} else {
|
|
472
|
-
this.errorLog(
|
|
473
|
-
`Humidifier: ${
|
|
474
|
-
this.accessory.displayName
|
|
475
|
-
} message: ${JSON.stringify(this.deviceStatus.message)}`,
|
|
476
|
-
);
|
|
379
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} message: ${JSON.stringify(this.deviceStatus.message)}`);
|
|
477
380
|
}
|
|
478
381
|
} catch (e: any) {
|
|
479
|
-
this.errorLog(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
382
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
383
|
+
if (this.deviceLogging === 'debug') {
|
|
384
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
385
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
386
|
+
}
|
|
387
|
+
if (this.platform.debugMode) {
|
|
388
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
389
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
487
390
|
}
|
|
488
391
|
this.apiError(e);
|
|
489
392
|
}
|
|
@@ -499,10 +402,9 @@ export class Humidifier {
|
|
|
499
402
|
//} else {
|
|
500
403
|
await this.openAPIpushChanges();
|
|
501
404
|
//}
|
|
502
|
-
|
|
503
|
-
.
|
|
504
|
-
.pipe(
|
|
505
|
-
.pipe(operators.take(1))
|
|
405
|
+
interval(5000)
|
|
406
|
+
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
407
|
+
.pipe(take(1))
|
|
506
408
|
.subscribe(() => {
|
|
507
409
|
this.refreshStatus();
|
|
508
410
|
});
|
|
@@ -512,53 +414,34 @@ export class Humidifier {
|
|
|
512
414
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
|
|
513
415
|
const switchbot = await this.platform.connectBLE();
|
|
514
416
|
// Convert to BLE Address
|
|
515
|
-
this.device.bleMac = this.device
|
|
516
|
-
|
|
517
|
-
.join(":")
|
|
518
|
-
.toLowerCase();
|
|
519
|
-
this.debugLog(
|
|
520
|
-
`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
521
|
-
);
|
|
417
|
+
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
418
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
522
419
|
if (switchbot !== false) {
|
|
523
|
-
switchbot
|
|
524
|
-
.
|
|
525
|
-
.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
);
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
if (this.platform.config.credentials?.openToken) {
|
|
547
|
-
this.warnLog(
|
|
548
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
549
|
-
);
|
|
550
|
-
await this.openAPIpushChanges();
|
|
551
|
-
}
|
|
552
|
-
this.apiError(e);
|
|
553
|
-
});
|
|
420
|
+
switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
421
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
422
|
+
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
423
|
+
}).then(() => {
|
|
424
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
|
|
425
|
+
}).catch(async (e: any) => {
|
|
426
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
427
|
+
if (this.deviceLogging === 'debug') {
|
|
428
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
429
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
430
|
+
}
|
|
431
|
+
if (this.platform.debugMode) {
|
|
432
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
433
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
434
|
+
}
|
|
435
|
+
if (this.platform.config.credentials?.openToken) {
|
|
436
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
437
|
+
await this.openAPIpushChanges();
|
|
438
|
+
}
|
|
439
|
+
this.apiError(e);
|
|
440
|
+
});
|
|
554
441
|
} else {
|
|
555
|
-
this.errorLog(
|
|
556
|
-
`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
557
|
-
);
|
|
442
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
558
443
|
if (this.platform.config.credentials?.openToken) {
|
|
559
|
-
this.warnLog(
|
|
560
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
561
|
-
);
|
|
444
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
562
445
|
await this.openAPIpushChanges();
|
|
563
446
|
}
|
|
564
447
|
}
|
|
@@ -566,57 +449,42 @@ export class Humidifier {
|
|
|
566
449
|
|
|
567
450
|
private async openAPIpushChanges() {
|
|
568
451
|
if (this.platform.config.credentials?.openToken) {
|
|
569
|
-
this.debugLog(
|
|
570
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`,
|
|
571
|
-
);
|
|
452
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
572
453
|
if (
|
|
573
454
|
this.TargetHumidifierDehumidifierState ===
|
|
574
|
-
|
|
575
|
-
.HUMIDIFIER &&
|
|
455
|
+
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
576
456
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
577
457
|
) {
|
|
578
458
|
try {
|
|
579
|
-
this.debugLog(
|
|
580
|
-
`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`,
|
|
581
|
-
);
|
|
459
|
+
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
582
460
|
const payload = {
|
|
583
|
-
commandType:
|
|
584
|
-
command:
|
|
461
|
+
commandType: 'command',
|
|
462
|
+
command: 'setMode',
|
|
585
463
|
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
586
|
-
} as
|
|
464
|
+
} as payload;
|
|
587
465
|
|
|
588
|
-
this.infoLog(
|
|
589
|
-
`
|
|
590
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
591
|
-
);
|
|
466
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
467
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
592
468
|
|
|
593
469
|
// Make the API request
|
|
594
|
-
const push: any = await this.platform.axios.post(
|
|
595
|
-
|
|
596
|
-
payload,
|
|
597
|
-
);
|
|
598
|
-
this.debugLog(
|
|
599
|
-
`Humidifier: ${
|
|
600
|
-
this.accessory.displayName
|
|
601
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
602
|
-
);
|
|
470
|
+
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
471
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
603
472
|
this.statusCode(push);
|
|
604
473
|
} catch (e: any) {
|
|
605
|
-
this.errorLog(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
474
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
475
|
+
if (this.deviceLogging === 'debug') {
|
|
476
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
477
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
478
|
+
}
|
|
479
|
+
if (this.platform.debugMode) {
|
|
480
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
481
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
613
482
|
}
|
|
614
483
|
this.apiError(e);
|
|
615
484
|
}
|
|
616
485
|
} else if (
|
|
617
486
|
this.TargetHumidifierDehumidifierState ===
|
|
618
|
-
|
|
619
|
-
.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
487
|
+
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
620
488
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
621
489
|
) {
|
|
622
490
|
await this.pushAutoChanges();
|
|
@@ -633,43 +501,33 @@ export class Humidifier {
|
|
|
633
501
|
try {
|
|
634
502
|
if (
|
|
635
503
|
this.TargetHumidifierDehumidifierState ===
|
|
636
|
-
|
|
637
|
-
.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
504
|
+
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
638
505
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
639
506
|
) {
|
|
640
|
-
this.debugLog(
|
|
507
|
+
this.debugLog('Pushing Auto!');
|
|
641
508
|
const payload = {
|
|
642
|
-
commandType:
|
|
643
|
-
command:
|
|
644
|
-
parameter:
|
|
645
|
-
} as
|
|
509
|
+
commandType: 'command',
|
|
510
|
+
command: 'setMode',
|
|
511
|
+
parameter: 'auto',
|
|
512
|
+
} as payload;
|
|
646
513
|
|
|
647
|
-
this.infoLog(
|
|
648
|
-
`
|
|
649
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
650
|
-
);
|
|
514
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
515
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
651
516
|
|
|
652
517
|
// Make the API request
|
|
653
|
-
const push: any = await this.platform.axios.post(
|
|
654
|
-
|
|
655
|
-
payload,
|
|
656
|
-
);
|
|
657
|
-
this.debugLog(
|
|
658
|
-
`Humidifier: ${
|
|
659
|
-
this.accessory.displayName
|
|
660
|
-
} pushAutoChanges: ${JSON.stringify(push.data)}`,
|
|
661
|
-
);
|
|
518
|
+
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
519
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
|
|
662
520
|
this.statusCode(push);
|
|
663
521
|
}
|
|
664
522
|
} catch (e: any) {
|
|
665
|
-
this.errorLog(
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
523
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
524
|
+
if (this.deviceLogging === 'debug') {
|
|
525
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
526
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
527
|
+
}
|
|
528
|
+
if (this.platform.debugMode) {
|
|
529
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
|
|
530
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
673
531
|
}
|
|
674
532
|
this.apiError(e);
|
|
675
533
|
}
|
|
@@ -681,39 +539,30 @@ export class Humidifier {
|
|
|
681
539
|
async pushActiveChanges() {
|
|
682
540
|
try {
|
|
683
541
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
684
|
-
this.debugLog(
|
|
542
|
+
this.debugLog('Pushing Off!');
|
|
685
543
|
const payload = {
|
|
686
|
-
commandType:
|
|
687
|
-
command:
|
|
688
|
-
parameter:
|
|
689
|
-
} as
|
|
544
|
+
commandType: 'command',
|
|
545
|
+
command: 'turnOff',
|
|
546
|
+
parameter: 'default',
|
|
547
|
+
} as payload;
|
|
690
548
|
|
|
691
|
-
this.infoLog(
|
|
692
|
-
`
|
|
693
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
694
|
-
);
|
|
549
|
+
this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
550
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
695
551
|
|
|
696
552
|
// Make the API request
|
|
697
|
-
const push: any = await this.platform.axios.post(
|
|
698
|
-
|
|
699
|
-
payload,
|
|
700
|
-
);
|
|
701
|
-
this.debugLog(
|
|
702
|
-
`Humidifier: ${
|
|
703
|
-
this.accessory.displayName
|
|
704
|
-
} pushActiveChanges: ${JSON.stringify(push.data)}`,
|
|
705
|
-
);
|
|
553
|
+
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
554
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
|
|
706
555
|
this.statusCode(push);
|
|
707
556
|
}
|
|
708
557
|
} catch (e: any) {
|
|
709
|
-
this.errorLog(
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
558
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
559
|
+
if (this.deviceLogging === 'debug') {
|
|
560
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
561
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
562
|
+
}
|
|
563
|
+
if (this.platform.debugMode) {
|
|
564
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
|
|
565
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
717
566
|
}
|
|
718
567
|
this.apiError(e);
|
|
719
568
|
}
|
|
@@ -724,205 +573,116 @@ export class Humidifier {
|
|
|
724
573
|
*/
|
|
725
574
|
updateHomeKitCharacteristics() {
|
|
726
575
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
727
|
-
this.debugLog(
|
|
728
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
729
|
-
);
|
|
576
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
730
577
|
} else {
|
|
731
|
-
this.service.updateCharacteristic(
|
|
732
|
-
|
|
733
|
-
this.CurrentRelativeHumidity
|
|
734
|
-
);
|
|
735
|
-
this.debugLog(
|
|
736
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
737
|
-
` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
738
|
-
);
|
|
578
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
579
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
580
|
+
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
739
581
|
}
|
|
740
582
|
if (!this.device.ble) {
|
|
741
583
|
if (this.WaterLevel === undefined) {
|
|
742
|
-
this.debugLog(
|
|
743
|
-
`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
|
|
744
|
-
);
|
|
584
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
745
585
|
} else {
|
|
746
|
-
this.service.updateCharacteristic(
|
|
747
|
-
|
|
748
|
-
this.WaterLevel,
|
|
749
|
-
);
|
|
750
|
-
this.debugLog(
|
|
751
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`,
|
|
752
|
-
);
|
|
586
|
+
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
587
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
753
588
|
}
|
|
754
589
|
}
|
|
755
590
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
756
|
-
this.debugLog(
|
|
757
|
-
`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
758
|
-
);
|
|
591
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
759
592
|
} else {
|
|
760
|
-
this.service.updateCharacteristic(
|
|
761
|
-
|
|
762
|
-
this.CurrentHumidifierDehumidifierState
|
|
763
|
-
);
|
|
764
|
-
this.debugLog(
|
|
765
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
766
|
-
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
767
|
-
);
|
|
593
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
594
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
595
|
+
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
768
596
|
}
|
|
769
597
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
770
|
-
this.debugLog(
|
|
771
|
-
`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
772
|
-
);
|
|
598
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
773
599
|
} else {
|
|
774
|
-
this.service.updateCharacteristic(
|
|
775
|
-
|
|
776
|
-
this.TargetHumidifierDehumidifierState
|
|
777
|
-
);
|
|
778
|
-
this.debugLog(
|
|
779
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
780
|
-
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
781
|
-
);
|
|
600
|
+
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
601
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
602
|
+
+ ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
782
603
|
}
|
|
783
604
|
if (this.Active === undefined) {
|
|
784
|
-
this.debugLog(
|
|
785
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
786
|
-
);
|
|
605
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
787
606
|
} else {
|
|
788
|
-
this.service.updateCharacteristic(
|
|
789
|
-
|
|
790
|
-
this.Active,
|
|
791
|
-
);
|
|
792
|
-
this.debugLog(
|
|
793
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
794
|
-
);
|
|
607
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
608
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
795
609
|
}
|
|
796
610
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
797
|
-
this.debugLog(
|
|
798
|
-
`
|
|
799
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
800
|
-
);
|
|
611
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
612
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
801
613
|
} else {
|
|
802
|
-
this.service.updateCharacteristic(
|
|
803
|
-
|
|
804
|
-
this.RelativeHumidityHumidifierThreshold
|
|
805
|
-
);
|
|
806
|
-
this.debugLog(
|
|
807
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
808
|
-
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
809
|
-
);
|
|
614
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
615
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}`
|
|
616
|
+
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
810
617
|
}
|
|
811
618
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
812
619
|
if (this.CurrentTemperature === undefined) {
|
|
813
|
-
this.debugLog(
|
|
814
|
-
`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
|
|
815
|
-
);
|
|
620
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
816
621
|
} else {
|
|
817
|
-
this.temperatureservice?.updateCharacteristic(
|
|
818
|
-
|
|
819
|
-
this.CurrentTemperature,
|
|
820
|
-
);
|
|
821
|
-
this.debugLog(
|
|
822
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`,
|
|
823
|
-
);
|
|
622
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
623
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
824
624
|
}
|
|
825
625
|
}
|
|
826
626
|
}
|
|
827
627
|
|
|
828
|
-
public apiError(e: any)
|
|
829
|
-
this.service.updateCharacteristic(
|
|
830
|
-
this.platform.Characteristic.CurrentRelativeHumidity,
|
|
831
|
-
e,
|
|
832
|
-
);
|
|
628
|
+
public apiError(e: any) {
|
|
629
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
833
630
|
if (!this.device.ble) {
|
|
834
|
-
this.service.updateCharacteristic(
|
|
835
|
-
this.platform.Characteristic.WaterLevel,
|
|
836
|
-
e,
|
|
837
|
-
);
|
|
631
|
+
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
838
632
|
}
|
|
839
|
-
this.service.updateCharacteristic(
|
|
840
|
-
|
|
841
|
-
e,
|
|
842
|
-
);
|
|
843
|
-
this.service.updateCharacteristic(
|
|
844
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
845
|
-
e,
|
|
846
|
-
);
|
|
633
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
634
|
+
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
847
635
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
848
|
-
this.service.updateCharacteristic(
|
|
849
|
-
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
850
|
-
e,
|
|
851
|
-
);
|
|
636
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
852
637
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
853
|
-
this.temperatureservice?.updateCharacteristic(
|
|
854
|
-
this.platform.Characteristic.CurrentTemperature,
|
|
855
|
-
e,
|
|
856
|
-
);
|
|
638
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
857
639
|
}
|
|
858
640
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
859
641
|
}
|
|
860
642
|
|
|
861
|
-
private statusCode(push:
|
|
643
|
+
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
862
644
|
switch (push.data.statusCode) {
|
|
863
645
|
case 151:
|
|
864
|
-
this.errorLog(
|
|
865
|
-
`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
866
|
-
);
|
|
646
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
867
647
|
break;
|
|
868
648
|
case 152:
|
|
869
|
-
this.errorLog(
|
|
870
|
-
`Humidifier: ${this.accessory.displayName} Device not found.`,
|
|
871
|
-
);
|
|
649
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
|
|
872
650
|
break;
|
|
873
651
|
case 160:
|
|
874
|
-
this.errorLog(
|
|
875
|
-
`Humidifier: ${this.accessory.displayName} Command is not supported.`,
|
|
876
|
-
);
|
|
652
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
|
|
877
653
|
break;
|
|
878
654
|
case 161:
|
|
879
|
-
this.errorLog(
|
|
880
|
-
`Humidifier: ${this.accessory.displayName} Device is offline.`,
|
|
881
|
-
);
|
|
655
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
|
|
882
656
|
this.offlineOff();
|
|
883
657
|
break;
|
|
884
658
|
case 171:
|
|
885
|
-
this.errorLog(
|
|
886
|
-
`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
887
|
-
);
|
|
659
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
888
660
|
this.offlineOff();
|
|
889
661
|
break;
|
|
890
662
|
case 190:
|
|
891
|
-
this.errorLog(
|
|
892
|
-
`
|
|
893
|
-
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
894
|
-
);
|
|
663
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
664
|
+
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
895
665
|
break;
|
|
896
666
|
case 100:
|
|
897
|
-
this.debugLog(
|
|
898
|
-
`Humidifier: ${this.accessory.displayName} Command successfully sent.`,
|
|
899
|
-
);
|
|
667
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
|
|
900
668
|
break;
|
|
901
669
|
default:
|
|
902
|
-
this.debugLog(
|
|
903
|
-
`Humidifier: ${this.accessory.displayName} Unknown statusCode.`,
|
|
904
|
-
);
|
|
670
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
|
|
905
671
|
}
|
|
906
672
|
}
|
|
907
673
|
|
|
908
674
|
private offlineOff() {
|
|
909
675
|
if (this.device.offline) {
|
|
910
676
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
911
|
-
this.service
|
|
912
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
913
|
-
.updateValue(this.Active);
|
|
677
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
|
|
914
678
|
}
|
|
915
679
|
}
|
|
916
680
|
|
|
917
681
|
/**
|
|
918
682
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
919
683
|
*/
|
|
920
|
-
private handleTargetHumidifierDehumidifierStateSet(
|
|
921
|
-
|
|
922
|
-
) {
|
|
923
|
-
this.debugLog(
|
|
924
|
-
`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`,
|
|
925
|
-
);
|
|
684
|
+
private handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue) {
|
|
685
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
|
|
926
686
|
|
|
927
687
|
this.TargetHumidifierDehumidifierState = value;
|
|
928
688
|
this.doHumidifierUpdate.next();
|
|
@@ -931,7 +691,7 @@ export class Humidifier {
|
|
|
931
691
|
/**
|
|
932
692
|
* Handle requests to set the "Active" characteristic
|
|
933
693
|
*/
|
|
934
|
-
private handleActiveSet(value:
|
|
694
|
+
private handleActiveSet(value: CharacteristicValue) {
|
|
935
695
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
|
|
936
696
|
this.Active = value;
|
|
937
697
|
this.doHumidifierUpdate.next();
|
|
@@ -940,105 +700,76 @@ export class Humidifier {
|
|
|
940
700
|
/**
|
|
941
701
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
942
702
|
*/
|
|
943
|
-
private handleRelativeHumidityHumidifierThresholdSet(
|
|
944
|
-
|
|
945
|
-
) {
|
|
946
|
-
this.debugLog(
|
|
947
|
-
`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`,
|
|
948
|
-
);
|
|
703
|
+
private handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue) {
|
|
704
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
949
705
|
|
|
950
706
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
951
707
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
952
708
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
953
|
-
this.CurrentHumidifierDehumidifierState =
|
|
954
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
709
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
955
710
|
}
|
|
956
711
|
this.doHumidifierUpdate.next();
|
|
957
712
|
}
|
|
958
713
|
|
|
959
|
-
config(device:
|
|
714
|
+
config(device: device & devicesConfig) {
|
|
960
715
|
let config = {};
|
|
961
716
|
if (device.humidifier) {
|
|
962
717
|
config = device.humidifier;
|
|
963
718
|
}
|
|
964
719
|
if (device.ble !== undefined) {
|
|
965
|
-
config[
|
|
720
|
+
config['ble'] = device.ble;
|
|
966
721
|
}
|
|
967
722
|
if (device.logging !== undefined) {
|
|
968
|
-
config[
|
|
723
|
+
config['logging'] = device.logging;
|
|
969
724
|
}
|
|
970
725
|
if (device.refreshRate !== undefined) {
|
|
971
|
-
config[
|
|
726
|
+
config['refreshRate'] = device.refreshRate;
|
|
972
727
|
}
|
|
973
728
|
if (device.scanDuration !== undefined) {
|
|
974
|
-
config[
|
|
729
|
+
config['scanDuration'] = device.scanDuration;
|
|
975
730
|
}
|
|
976
731
|
if (Object.entries(config).length !== 0) {
|
|
977
|
-
this.warnLog(
|
|
978
|
-
`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
979
|
-
config,
|
|
980
|
-
)}`,
|
|
981
|
-
);
|
|
732
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
982
733
|
}
|
|
983
734
|
}
|
|
984
735
|
|
|
985
|
-
refreshRate(device:
|
|
736
|
+
refreshRate(device: device & devicesConfig) {
|
|
986
737
|
if (device.refreshRate) {
|
|
987
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
988
|
-
|
|
989
|
-
this.debugLog(
|
|
990
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
991
|
-
);
|
|
738
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
739
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
992
740
|
} else if (this.platform.config.options!.refreshRate) {
|
|
993
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
994
|
-
|
|
995
|
-
this.debugLog(
|
|
996
|
-
`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
997
|
-
);
|
|
741
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
742
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
998
743
|
}
|
|
999
744
|
}
|
|
1000
745
|
|
|
1001
|
-
scan(device:
|
|
746
|
+
scan(device: device & devicesConfig) {
|
|
1002
747
|
if (device.scanDuration) {
|
|
1003
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
1004
|
-
device.scanDuration;
|
|
748
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1005
749
|
if (device.ble) {
|
|
1006
|
-
this.debugLog(
|
|
1007
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
1008
|
-
);
|
|
750
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1009
751
|
}
|
|
1010
752
|
} else {
|
|
1011
753
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
1012
754
|
if (this.device.ble) {
|
|
1013
|
-
this.debugLog(
|
|
1014
|
-
`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
1015
|
-
);
|
|
755
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
1016
756
|
}
|
|
1017
757
|
}
|
|
1018
758
|
}
|
|
1019
759
|
|
|
1020
|
-
logs(device:
|
|
760
|
+
logs(device: device & devicesConfig) {
|
|
1021
761
|
if (this.platform.debugMode) {
|
|
1022
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1023
|
-
this.debugLog(
|
|
1024
|
-
`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
1025
|
-
);
|
|
762
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
763
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1026
764
|
} else if (device.logging) {
|
|
1027
765
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1028
|
-
this.debugLog(
|
|
1029
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
1030
|
-
);
|
|
766
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1031
767
|
} else if (this.platform.config.options?.logging) {
|
|
1032
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1033
|
-
|
|
1034
|
-
this.debugLog(
|
|
1035
|
-
`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
1036
|
-
);
|
|
768
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
769
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1037
770
|
} else {
|
|
1038
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1039
|
-
this.debugLog(
|
|
1040
|
-
`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
1041
|
-
);
|
|
771
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
772
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1042
773
|
}
|
|
1043
774
|
}
|
|
1044
775
|
|
|
@@ -1052,30 +783,30 @@ export class Humidifier {
|
|
|
1052
783
|
}
|
|
1053
784
|
|
|
1054
785
|
/**
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
infoLog(...log: any[])
|
|
786
|
+
* Logging for Device
|
|
787
|
+
*/
|
|
788
|
+
infoLog(...log: any[]) {
|
|
1058
789
|
if (this.enablingDeviceLogging()) {
|
|
1059
790
|
this.platform.log.info(String(...log));
|
|
1060
791
|
}
|
|
1061
792
|
}
|
|
1062
793
|
|
|
1063
|
-
warnLog(...log: any[])
|
|
794
|
+
warnLog(...log: any[]) {
|
|
1064
795
|
if (this.enablingDeviceLogging()) {
|
|
1065
796
|
this.platform.log.warn(String(...log));
|
|
1066
797
|
}
|
|
1067
798
|
}
|
|
1068
799
|
|
|
1069
|
-
errorLog(...log: any[])
|
|
800
|
+
errorLog(...log: any[]) {
|
|
1070
801
|
if (this.enablingDeviceLogging()) {
|
|
1071
802
|
this.platform.log.error(String(...log));
|
|
1072
803
|
}
|
|
1073
804
|
}
|
|
1074
805
|
|
|
1075
|
-
debugLog(...log: any[])
|
|
806
|
+
debugLog(...log: any[]) {
|
|
1076
807
|
if (this.enablingDeviceLogging()) {
|
|
1077
|
-
if (this.deviceLogging ===
|
|
1078
|
-
this.platform.log.info(
|
|
808
|
+
if (this.deviceLogging === 'debug') {
|
|
809
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
1079
810
|
} else {
|
|
1080
811
|
this.platform.log.debug(String(...log));
|
|
1081
812
|
}
|
|
@@ -1083,8 +814,6 @@ export class Humidifier {
|
|
|
1083
814
|
}
|
|
1084
815
|
|
|
1085
816
|
enablingDeviceLogging(): boolean {
|
|
1086
|
-
return
|
|
1087
|
-
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
1088
|
-
);
|
|
817
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
1089
818
|
}
|
|
1090
819
|
}
|