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