@switchbot/homebridge-switchbot 3.5.0-beta.7 → 3.5.0-beta.70
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 +120 -17
- package/dist/device/blindtilt.d.ts +23 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +425 -778
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +26 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +803 -837
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -68
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +241 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +14 -75
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +283 -658
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +254 -545
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -88
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +412 -806
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +711 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +540 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +16 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +261 -616
- 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 +240 -594
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +196 -600
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +11 -69
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +281 -586
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +16 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +252 -560
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +14 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +191 -593
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +14 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +180 -593
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +188 -532
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +96 -458
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +202 -521
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +10 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +146 -475
- 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 +324 -452
- 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 +93 -307
- 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 +39 -281
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +113 -341
- 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 +330 -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 +87 -335
- 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 +19 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +310 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +62 -19
- 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 +19 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +462 -817
- package/src/device/bot.ts +862 -931
- package/src/device/ceilinglight.ts +259 -633
- package/src/device/colorbulb.ts +300 -688
- package/src/device/contact.ts +288 -571
- package/src/device/curtain.ts +441 -838
- package/src/device/device.ts +734 -0
- package/src/device/fan.ts +596 -0
- package/src/device/hub.ts +299 -645
- package/src/device/humidifier.ts +274 -647
- package/src/device/iosensor.ts +233 -626
- package/src/device/lightstrip.ts +309 -620
- package/src/device/lock.ts +292 -601
- package/src/device/meter.ts +228 -619
- package/src/device/meterplus.ts +216 -619
- package/src/device/motion.ts +218 -559
- package/src/device/plug.ts +111 -490
- package/src/device/robotvacuumcleaner.ts +228 -550
- package/src/device/waterdetector.ts +169 -501
- 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 +350 -477
- package/src/irdevice/airpurifier.ts +120 -330
- package/src/irdevice/camera.ts +53 -301
- package/src/irdevice/fan.ts +130 -360
- package/src/irdevice/irdevice.ts +346 -0
- package/src/irdevice/light.ts +157 -412
- package/src/irdevice/other.ts +507 -648
- package/src/irdevice/tv.ts +117 -367
- package/src/irdevice/vacuumcleaner.ts +59 -311
- package/src/irdevice/waterheater.ts +61 -320
- package/src/platform.ts +355 -219
- package/src/settings.ts +116 -611
- package/src/utils.ts +642 -1
- 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: this.minStep(),
|
|
69
|
+
minStep: this.minStep(device),
|
|
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,12 +99,11 @@ 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
|
|
@@ -152,22 +113,23 @@ export class Humidifier {
|
|
|
152
113
|
this.refreshStatus();
|
|
153
114
|
});
|
|
154
115
|
//regisiter webhook event handler
|
|
155
|
-
if (
|
|
156
|
-
this.
|
|
116
|
+
if (device.webhook) {
|
|
117
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
157
118
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
158
119
|
try {
|
|
159
120
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.
|
|
121
|
+
const { temperature, humidity } = context;
|
|
122
|
+
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
123
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
124
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
125
|
+
'(temperature, humidity) = ' +
|
|
126
|
+
`Webhook:(${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), ` +
|
|
127
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
128
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
129
|
+
if (!this.device.humidifier?.hide_temperature) {
|
|
130
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
|
170
131
|
}
|
|
132
|
+
this.updateHomeKitCharacteristics();
|
|
171
133
|
}
|
|
172
134
|
catch (e) {
|
|
173
135
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -193,101 +155,100 @@ export class Humidifier {
|
|
|
193
155
|
this.humidifierUpdateInProgress = false;
|
|
194
156
|
});
|
|
195
157
|
}
|
|
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() {
|
|
158
|
+
async BLEparseStatus(serviceData) {
|
|
215
159
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
160
|
+
// Target Humidifier Dehumidifier State
|
|
161
|
+
if (serviceData.autoMode) {
|
|
162
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
163
|
+
}
|
|
216
164
|
// Current Relative Humidity
|
|
217
|
-
this.CurrentRelativeHumidity =
|
|
218
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
165
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
|
|
166
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
167
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
219
168
|
// Active
|
|
220
|
-
if (
|
|
221
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
169
|
+
if (serviceData.onState) {
|
|
170
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
222
171
|
}
|
|
223
172
|
else {
|
|
224
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
173
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
225
174
|
}
|
|
226
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
175
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
227
176
|
}
|
|
228
|
-
async openAPIparseStatus() {
|
|
177
|
+
async openAPIparseStatus(deviceStatus) {
|
|
229
178
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
230
179
|
// Current Relative Humidity
|
|
231
|
-
this.CurrentRelativeHumidity =
|
|
232
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
180
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature;
|
|
181
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
182
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
233
183
|
// Current Temperature
|
|
234
184
|
if (!this.device.humidifier?.hide_temperature) {
|
|
235
|
-
this.CurrentTemperature =
|
|
236
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
185
|
+
this.TemperatureSensor.CurrentTemperature = deviceStatus.body.temperature;
|
|
186
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
237
187
|
}
|
|
238
188
|
// Target Humidifier Dehumidifier State
|
|
239
|
-
switch (
|
|
189
|
+
switch (deviceStatus.body.auto) {
|
|
240
190
|
case true:
|
|
241
|
-
this.TargetHumidifierDehumidifierState =
|
|
242
|
-
|
|
243
|
-
this.
|
|
191
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
192
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
193
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
194
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
244
195
|
break;
|
|
245
196
|
default:
|
|
246
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
247
|
-
if (
|
|
248
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
197
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
198
|
+
if (deviceStatus.body.nebulizationEfficiency > 100) {
|
|
199
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
249
200
|
}
|
|
250
201
|
else {
|
|
251
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
202
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
252
203
|
}
|
|
253
|
-
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
254
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
204
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
205
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
255
206
|
}
|
|
256
|
-
else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
257
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
207
|
+
else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
208
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
258
209
|
}
|
|
259
210
|
else {
|
|
260
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
211
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
261
212
|
}
|
|
262
213
|
}
|
|
263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
215
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
217
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
219
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
267
220
|
// Active
|
|
268
|
-
switch (
|
|
221
|
+
switch (deviceStatus.body.power) {
|
|
269
222
|
case 'on':
|
|
270
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
223
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
271
224
|
break;
|
|
272
225
|
default:
|
|
273
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
226
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
274
227
|
}
|
|
275
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
228
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
276
229
|
// Water Level
|
|
277
|
-
if (
|
|
278
|
-
this.WaterLevel = 0;
|
|
230
|
+
if (deviceStatus.body.lackWater) {
|
|
231
|
+
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
279
232
|
}
|
|
280
233
|
else {
|
|
281
|
-
this.WaterLevel = 100;
|
|
234
|
+
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
235
|
+
}
|
|
236
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
237
|
+
// Firmware Version
|
|
238
|
+
const version = deviceStatus.body.version?.toString();
|
|
239
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
240
|
+
if (deviceStatus.body.version) {
|
|
241
|
+
const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
242
|
+
this.accessory
|
|
243
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
244
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
245
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
246
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
247
|
+
.updateValue(deviceVersion);
|
|
248
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
249
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
282
250
|
}
|
|
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
251
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Asks the SwitchBot API for the latest device information
|
|
290
|
-
*/
|
|
291
252
|
async refreshStatus() {
|
|
292
253
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
293
254
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -317,103 +278,42 @@ export class Humidifier {
|
|
|
317
278
|
// Start to monitor advertisement packets
|
|
318
279
|
(async () => {
|
|
319
280
|
// Start to monitor advertisement packets
|
|
320
|
-
await switchbot.startScan({
|
|
321
|
-
model: 'e',
|
|
322
|
-
id: this.device.bleMac,
|
|
323
|
-
});
|
|
281
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
324
282
|
// Set an event handler
|
|
325
283
|
switchbot.onadvertisement = (ad) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
284
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
285
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
286
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
329
287
|
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
288
|
}
|
|
334
289
|
else {
|
|
335
290
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
336
291
|
}
|
|
337
292
|
};
|
|
338
|
-
// Wait
|
|
293
|
+
// Wait 10 seconds
|
|
339
294
|
await switchbot.wait(this.scanDuration * 1000);
|
|
340
295
|
// Stop to monitor
|
|
341
296
|
await switchbot.stopScan();
|
|
342
297
|
// Update HomeKit
|
|
343
|
-
await this.BLEparseStatus();
|
|
298
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
344
299
|
await this.updateHomeKitCharacteristics();
|
|
345
300
|
})();
|
|
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
|
-
}*/
|
|
301
|
+
if (switchbot === undefined) {
|
|
302
|
+
await this.BLERefreshConnection(switchbot);
|
|
303
|
+
}
|
|
395
304
|
}
|
|
396
305
|
async openAPIRefreshStatus() {
|
|
397
306
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
398
307
|
try {
|
|
399
|
-
const { body, statusCode } = await
|
|
400
|
-
headers: this.platform.generateHeaders(),
|
|
401
|
-
});
|
|
308
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
402
309
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
403
310
|
const deviceStatus = await body.json();
|
|
404
311
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
405
312
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
406
313
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
407
|
-
this.
|
|
314
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
408
315
|
+ `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();
|
|
316
|
+
this.openAPIparseStatus(deviceStatus);
|
|
417
317
|
this.updateHomeKitCharacteristics();
|
|
418
318
|
}
|
|
419
319
|
else {
|
|
@@ -465,11 +365,13 @@ export class Humidifier {
|
|
|
465
365
|
id: this.device.bleMac,
|
|
466
366
|
})
|
|
467
367
|
.then(async (device_list) => {
|
|
468
|
-
this.infoLog(`${this.accessory.displayName}
|
|
469
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
368
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
369
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
470
370
|
})
|
|
471
371
|
.then(() => {
|
|
472
372
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
373
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
374
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
473
375
|
})
|
|
474
376
|
.catch(async (e) => {
|
|
475
377
|
this.apiError(e);
|
|
@@ -480,12 +382,13 @@ export class Humidifier {
|
|
|
480
382
|
}
|
|
481
383
|
async openAPIpushChanges() {
|
|
482
384
|
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}
|
|
385
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
386
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
388
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
486
389
|
const bodyChange = JSON.stringify({
|
|
487
390
|
command: 'setMode',
|
|
488
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
391
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
489
392
|
commandType: 'command',
|
|
490
393
|
});
|
|
491
394
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -503,6 +406,8 @@ export class Humidifier {
|
|
|
503
406
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
504
407
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
505
408
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
409
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
410
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
506
411
|
}
|
|
507
412
|
else {
|
|
508
413
|
this.statusCode(statusCode);
|
|
@@ -515,8 +420,9 @@ export class Humidifier {
|
|
|
515
420
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
516
421
|
}
|
|
517
422
|
}
|
|
518
|
-
else if (this.TargetHumidifierDehumidifierState ===
|
|
519
|
-
this.
|
|
423
|
+
else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
424
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
425
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
520
426
|
await this.pushAutoChanges();
|
|
521
427
|
}
|
|
522
428
|
else {
|
|
@@ -528,8 +434,9 @@ export class Humidifier {
|
|
|
528
434
|
*/
|
|
529
435
|
async pushAutoChanges() {
|
|
530
436
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
531
|
-
if (this.TargetHumidifierDehumidifierState ===
|
|
532
|
-
this.
|
|
437
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
438
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
439
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
533
440
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
534
441
|
const bodyChange = JSON.stringify({
|
|
535
442
|
command: 'setMode',
|
|
@@ -551,6 +458,8 @@ export class Humidifier {
|
|
|
551
458
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
552
459
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
553
460
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
461
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
462
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
554
463
|
}
|
|
555
464
|
else {
|
|
556
465
|
this.statusCode(statusCode);
|
|
@@ -564,8 +473,8 @@ export class Humidifier {
|
|
|
564
473
|
}
|
|
565
474
|
}
|
|
566
475
|
else {
|
|
567
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges
|
|
568
|
-
`
|
|
476
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
477
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
569
478
|
}
|
|
570
479
|
}
|
|
571
480
|
/**
|
|
@@ -573,7 +482,7 @@ export class Humidifier {
|
|
|
573
482
|
*/
|
|
574
483
|
async pushActiveChanges() {
|
|
575
484
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
576
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
485
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
577
486
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
578
487
|
const bodyChange = JSON.stringify({
|
|
579
488
|
command: 'turnOff',
|
|
@@ -595,6 +504,8 @@ export class Humidifier {
|
|
|
595
504
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
596
505
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
597
506
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
507
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
508
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
598
509
|
}
|
|
599
510
|
else {
|
|
600
511
|
this.statusCode(statusCode);
|
|
@@ -608,49 +519,49 @@ export class Humidifier {
|
|
|
608
519
|
}
|
|
609
520
|
}
|
|
610
521
|
else {
|
|
611
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
522
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
612
523
|
}
|
|
613
524
|
}
|
|
614
525
|
/**
|
|
615
526
|
* Handle requests to set the "Active" characteristic
|
|
616
527
|
*/
|
|
617
528
|
async ActiveSet(value) {
|
|
618
|
-
if (this.Active === this.accessory.context.Active) {
|
|
529
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
619
530
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
620
531
|
}
|
|
621
532
|
else {
|
|
622
533
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
623
534
|
}
|
|
624
|
-
this.Active = value;
|
|
535
|
+
this.HumidifierDehumidifier.Active = value;
|
|
625
536
|
this.doHumidifierUpdate.next();
|
|
626
537
|
}
|
|
627
538
|
/**
|
|
628
539
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
629
540
|
*/
|
|
630
541
|
async TargetHumidifierDehumidifierStateSet(value) {
|
|
631
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
542
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
632
543
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
633
544
|
}
|
|
634
545
|
else {
|
|
635
546
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
636
547
|
}
|
|
637
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
548
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
638
549
|
this.doHumidifierUpdate.next();
|
|
639
550
|
}
|
|
640
551
|
/**
|
|
641
552
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
642
553
|
*/
|
|
643
554
|
async RelativeHumidityHumidifierThresholdSet(value) {
|
|
644
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
555
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
645
556
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
646
557
|
}
|
|
647
558
|
else {
|
|
648
559
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
649
560
|
}
|
|
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;
|
|
561
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
562
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
563
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
564
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
654
565
|
}
|
|
655
566
|
this.doHumidifierUpdate.next();
|
|
656
567
|
}
|
|
@@ -658,99 +569,77 @@ export class Humidifier {
|
|
|
658
569
|
* Updates the status for each of the HomeKit Characteristics
|
|
659
570
|
*/
|
|
660
571
|
async updateHomeKitCharacteristics() {
|
|
661
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
662
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
572
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
573
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
574
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
663
575
|
}
|
|
664
576
|
else {
|
|
665
|
-
this.
|
|
666
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
667
|
-
|
|
577
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
578
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
579
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
580
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
668
581
|
}
|
|
669
582
|
if (this.OpenAPI) {
|
|
670
|
-
if (this.WaterLevel === undefined) {
|
|
671
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
583
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
584
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
672
585
|
}
|
|
673
586
|
else {
|
|
674
|
-
this.
|
|
675
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
676
|
-
|
|
587
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
588
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
589
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
590
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
677
591
|
}
|
|
678
592
|
}
|
|
679
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
593
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
680
594
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
681
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
595
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
682
596
|
}
|
|
683
597
|
else {
|
|
684
|
-
this.
|
|
685
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
686
|
-
`
|
|
687
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
598
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
600
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
601
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
688
602
|
}
|
|
689
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
690
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
603
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
604
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
605
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
691
606
|
}
|
|
692
607
|
else {
|
|
693
|
-
this.
|
|
694
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
695
|
-
`
|
|
696
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
608
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
609
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
610
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
611
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
697
612
|
}
|
|
698
|
-
if (this.Active === undefined) {
|
|
699
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
613
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
614
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
700
615
|
}
|
|
701
616
|
else {
|
|
702
|
-
this.
|
|
703
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
704
|
-
this.accessory.context.Active = this.Active;
|
|
617
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
618
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
619
|
+
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
705
620
|
}
|
|
706
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
621
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
707
622
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
708
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
623
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
709
624
|
}
|
|
710
625
|
else {
|
|
711
|
-
this.
|
|
712
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
713
|
-
`
|
|
714
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
626
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
627
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
628
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
629
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
715
630
|
}
|
|
716
631
|
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}`);
|
|
632
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
633
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
719
634
|
}
|
|
720
635
|
else {
|
|
721
|
-
this.
|
|
722
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
723
|
-
|
|
636
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
637
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
638
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
639
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
724
640
|
}
|
|
725
641
|
}
|
|
726
642
|
}
|
|
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
643
|
async BLEPushConnection() {
|
|
755
644
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
756
645
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -765,279 +654,36 @@ export class Humidifier {
|
|
|
765
654
|
await this.openAPIRefreshStatus();
|
|
766
655
|
}
|
|
767
656
|
}
|
|
768
|
-
minStep() {
|
|
769
|
-
|
|
770
|
-
|
|
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
|
-
}
|
|
657
|
+
minStep(device) {
|
|
658
|
+
let set_minStep;
|
|
659
|
+
if (device.humidifier?.set_minStep) {
|
|
660
|
+
set_minStep = device.humidifier?.set_minStep;
|
|
783
661
|
}
|
|
784
662
|
else {
|
|
785
|
-
|
|
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`);
|
|
663
|
+
set_minStep = 1;
|
|
860
664
|
}
|
|
665
|
+
return set_minStep;
|
|
861
666
|
}
|
|
862
667
|
async offlineOff() {
|
|
863
668
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
864
669
|
if (this.device.offline) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
await this.updateHomeKitCharacteristics();
|
|
670
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
671
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
672
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
870
673
|
}
|
|
871
674
|
}
|
|
872
675
|
async apiError(e) {
|
|
873
|
-
this.
|
|
676
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
874
677
|
if (!this.BLE) {
|
|
875
|
-
this.
|
|
678
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
876
679
|
}
|
|
877
|
-
this.
|
|
878
|
-
this.
|
|
879
|
-
this.
|
|
880
|
-
this.
|
|
680
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
681
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
682
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
683
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
881
684
|
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}`);
|
|
685
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
947
686
|
}
|
|
948
687
|
}
|
|
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}`);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
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
688
|
}
|
|
1043
689
|
//# sourceMappingURL=humidifier.js.map
|