@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.41
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/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +351 -757
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +587 -761
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +213 -588
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +255 -634
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +208 -532
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +339 -787
- 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 +671 -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 +504 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +246 -597
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +211 -572
- 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 +178 -585
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +256 -569
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +214 -543
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +174 -578
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +163 -578
- 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 +141 -520
- 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 +86 -453
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +144 -452
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +125 -665
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- 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 +512 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +343 -198
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +41 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -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/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +377 -783
- package/src/device/bot.ts +620 -845
- package/src/device/ceilinglight.ts +226 -608
- package/src/device/colorbulb.ts +268 -657
- package/src/device/contact.ts +233 -554
- package/src/device/curtain.ts +359 -811
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +553 -0
- package/src/device/hub.ts +273 -625
- package/src/device/humidifier.ts +241 -619
- package/src/device/iosensor.ts +204 -611
- package/src/device/lightstrip.ts +277 -597
- package/src/device/lock.ts +251 -583
- package/src/device/meter.ts +199 -601
- package/src/device/meterplus.ts +188 -603
- package/src/device/motion.ts +160 -542
- package/src/device/plug.ts +96 -481
- package/src/device/robotvacuumcleaner.ts +165 -478
- package/src/device/waterdetector.ts +142 -689
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +528 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +353 -206
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
2
|
+
import { deviceBase } from './device.js';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Devices } from '../settings.js';
|
|
@@ -8,93 +8,52 @@ import { Devices } from '../settings.js';
|
|
|
8
8
|
* An instance of this class is created for each accessory your platform registers
|
|
9
9
|
* Each accessory may expose multiple services of different service types.
|
|
10
10
|
*/
|
|
11
|
-
export class Humidifier {
|
|
11
|
+
export class Humidifier extends deviceBase {
|
|
12
12
|
platform;
|
|
13
|
-
accessory;
|
|
14
|
-
device;
|
|
15
|
-
api;
|
|
16
|
-
log;
|
|
17
|
-
config;
|
|
18
|
-
hap;
|
|
19
13
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Characteristic Values
|
|
23
|
-
Active;
|
|
24
|
-
WaterLevel;
|
|
25
|
-
FirmwareRevision;
|
|
26
|
-
CurrentTemperature;
|
|
27
|
-
CurrentRelativeHumidity;
|
|
28
|
-
TargetHumidifierDehumidifierState;
|
|
29
|
-
CurrentHumidifierDehumidifierState;
|
|
30
|
-
RelativeHumidityHumidifierThreshold;
|
|
31
|
-
// OpenAPI
|
|
32
|
-
OpenAPI_Active;
|
|
33
|
-
OpenAPI_WaterLevel;
|
|
34
|
-
OpenAPI_FirmwareRevision;
|
|
35
|
-
OpenAPI_CurrentTemperature;
|
|
36
|
-
OpenAPI_CurrentRelativeHumidity;
|
|
37
|
-
OpenAPI_CurrentHumidifierDehumidifierState;
|
|
38
|
-
OpenAPI_RelativeHumidityHumidifierThreshold;
|
|
39
|
-
// BLE Others
|
|
40
|
-
connected;
|
|
41
|
-
onState;
|
|
42
|
-
autoMode;
|
|
43
|
-
percentage;
|
|
44
|
-
// Config
|
|
45
|
-
set_minStep;
|
|
46
|
-
scanDuration;
|
|
47
|
-
deviceLogging;
|
|
48
|
-
deviceRefreshRate;
|
|
14
|
+
HumidifierDehumidifier;
|
|
15
|
+
TemperatureSensor;
|
|
49
16
|
// Updates
|
|
50
17
|
humidifierUpdateInProgress;
|
|
51
18
|
doHumidifierUpdate;
|
|
52
|
-
// Connection
|
|
53
|
-
OpenAPI;
|
|
54
|
-
BLE;
|
|
55
19
|
constructor(platform, accessory, device) {
|
|
20
|
+
super(platform, accessory, device);
|
|
56
21
|
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
22
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
73
23
|
this.doHumidifierUpdate = new Subject();
|
|
74
24
|
this.humidifierUpdateInProgress = false;
|
|
25
|
+
// Initialize the HumidifierDehumidifier Service
|
|
26
|
+
this.HumidifierDehumidifier = {
|
|
27
|
+
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier),
|
|
28
|
+
Active: accessory.context.Active || this.hap.Characteristic.Active.ACTIVE,
|
|
29
|
+
WaterLevel: accessory.context.WaterLevel || 100,
|
|
30
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
31
|
+
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
32
|
+
|| this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
33
|
+
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
34
|
+
|| this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
35
|
+
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold || 50,
|
|
36
|
+
};
|
|
37
|
+
// Initialize the Temperature Sensor Service
|
|
38
|
+
if (!device.humidifier?.hide_temperature) {
|
|
39
|
+
this.TemperatureSensor = {
|
|
40
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor),
|
|
41
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
75
44
|
// Retrieve initial values and updateHomekit
|
|
76
45
|
this.refreshStatus();
|
|
77
|
-
// set accessory information
|
|
78
|
-
accessory
|
|
79
|
-
.getService(this.hap.Service.AccessoryInformation)
|
|
80
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
81
|
-
.setCharacteristic(this.hap.Characteristic.Model, 'W0801800')
|
|
82
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
83
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
84
46
|
// get the service if it exists, otherwise create a new service
|
|
85
47
|
// you can create multiple services for each accessory
|
|
86
|
-
const
|
|
87
|
-
(this.
|
|
88
|
-
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)),
|
|
89
|
-
this.
|
|
90
|
-
if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
91
|
-
this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
92
|
-
}
|
|
48
|
+
const HumidifierDehumidifierService = `${accessory.displayName} Humidifier`;
|
|
49
|
+
(this.HumidifierDehumidifier.Service = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
50
|
+
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), HumidifierDehumidifierService;
|
|
51
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
93
52
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
94
53
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
95
54
|
// create handlers for required characteristics
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
55
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
56
|
+
this.HumidifierDehumidifier.Service
|
|
98
57
|
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
99
58
|
.setProps({
|
|
100
59
|
validValueRanges: [0, 1],
|
|
@@ -103,32 +62,29 @@ export class Humidifier {
|
|
|
103
62
|
validValues: [0, 1],
|
|
104
63
|
})
|
|
105
64
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
65
|
+
this.HumidifierDehumidifier.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
66
|
+
this.HumidifierDehumidifier.Service
|
|
108
67
|
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
109
68
|
.setProps({
|
|
110
69
|
validValueRanges: [0, 100],
|
|
111
70
|
minValue: 0,
|
|
112
71
|
maxValue: 100,
|
|
113
|
-
minStep: this.minStep(),
|
|
72
|
+
minStep: this.minStep(device),
|
|
114
73
|
})
|
|
115
74
|
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
116
75
|
// Temperature Sensor Service
|
|
117
76
|
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
118
77
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
119
|
-
this.
|
|
120
|
-
accessory.removeService(this.
|
|
78
|
+
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
79
|
+
accessory.removeService(this.TemperatureSensor.Service);
|
|
121
80
|
}
|
|
122
|
-
else if (!this.
|
|
81
|
+
else if (!this.TemperatureSensor?.Service && !this.BLE) {
|
|
123
82
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
124
|
-
const
|
|
125
|
-
(this.
|
|
126
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)),
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
130
|
-
}
|
|
131
|
-
this.temperatureservice
|
|
83
|
+
const TemperatureSensorService = `${accessory.displayName} Temperature Sensor`;
|
|
84
|
+
(this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
85
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), TemperatureSensorService;
|
|
86
|
+
this.TemperatureSensor.Service.setCharacteristic(this.hap.Characteristic.Name, TemperatureSensorService);
|
|
87
|
+
this.TemperatureSensor.Service
|
|
132
88
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
133
89
|
.setProps({
|
|
134
90
|
validValueRanges: [-273.15, 100],
|
|
@@ -137,7 +93,7 @@ export class Humidifier {
|
|
|
137
93
|
minStep: 0.1,
|
|
138
94
|
})
|
|
139
95
|
.onGet(() => {
|
|
140
|
-
return this.CurrentTemperature;
|
|
96
|
+
return this.TemperatureSensor.CurrentTemperature;
|
|
141
97
|
});
|
|
142
98
|
}
|
|
143
99
|
else {
|
|
@@ -152,20 +108,23 @@ export class Humidifier {
|
|
|
152
108
|
this.refreshStatus();
|
|
153
109
|
});
|
|
154
110
|
//regisiter webhook event handler
|
|
155
|
-
if (
|
|
156
|
-
this.
|
|
111
|
+
if (device.webhook) {
|
|
112
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
157
113
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
158
114
|
try {
|
|
159
115
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
160
116
|
if (context.scale === 'CELSIUS') {
|
|
161
117
|
const { temperature, humidity } = context;
|
|
162
|
-
const {
|
|
118
|
+
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
119
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
163
120
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
164
121
|
'(temperature, humidity) = ' +
|
|
165
122
|
`Webhook:(${temperature}, ${humidity}), ` +
|
|
166
123
|
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
167
|
-
this.CurrentRelativeHumidity = humidity;
|
|
168
|
-
this.
|
|
124
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
125
|
+
if (!this.device.humidifier?.hide_temperature) {
|
|
126
|
+
this.TemperatureSensor.CurrentTemperature = temperature;
|
|
127
|
+
}
|
|
169
128
|
this.updateHomeKitCharacteristics();
|
|
170
129
|
}
|
|
171
130
|
}
|
|
@@ -193,101 +152,96 @@ export class Humidifier {
|
|
|
193
152
|
this.humidifierUpdateInProgress = false;
|
|
194
153
|
});
|
|
195
154
|
}
|
|
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() {
|
|
155
|
+
async BLEparseStatus(serviceData) {
|
|
215
156
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
157
|
+
// Target Humidifier Dehumidifier State
|
|
158
|
+
if (serviceData.autoMode) {
|
|
159
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
160
|
+
}
|
|
216
161
|
// Current Relative Humidity
|
|
217
|
-
this.CurrentRelativeHumidity =
|
|
218
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
162
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
164
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
219
165
|
// Active
|
|
220
|
-
if (
|
|
221
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
166
|
+
if (serviceData.onState) {
|
|
167
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
222
168
|
}
|
|
223
169
|
else {
|
|
224
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
170
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
225
171
|
}
|
|
226
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
227
173
|
}
|
|
228
|
-
async openAPIparseStatus() {
|
|
174
|
+
async openAPIparseStatus(deviceStatus) {
|
|
229
175
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
230
176
|
// Current Relative Humidity
|
|
231
|
-
this.CurrentRelativeHumidity =
|
|
232
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
177
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature;
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
179
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
233
180
|
// Current Temperature
|
|
234
181
|
if (!this.device.humidifier?.hide_temperature) {
|
|
235
|
-
this.CurrentTemperature =
|
|
236
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
182
|
+
this.TemperatureSensor.CurrentTemperature = deviceStatus.body.temperature;
|
|
183
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
237
184
|
}
|
|
238
185
|
// Target Humidifier Dehumidifier State
|
|
239
|
-
switch (
|
|
186
|
+
switch (deviceStatus.body.auto) {
|
|
240
187
|
case true:
|
|
241
|
-
this.TargetHumidifierDehumidifierState =
|
|
242
|
-
|
|
243
|
-
this.
|
|
188
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
189
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
190
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
191
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
244
192
|
break;
|
|
245
193
|
default:
|
|
246
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
247
|
-
if (
|
|
248
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
194
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
195
|
+
if (deviceStatus.body.nebulizationEfficiency > 100) {
|
|
196
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
249
197
|
}
|
|
250
198
|
else {
|
|
251
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
199
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
252
200
|
}
|
|
253
|
-
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
254
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
201
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
202
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
255
203
|
}
|
|
256
|
-
else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
257
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
204
|
+
else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
205
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
258
206
|
}
|
|
259
207
|
else {
|
|
260
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
208
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
261
209
|
}
|
|
262
210
|
}
|
|
263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
212
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
213
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
214
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
215
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
216
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
267
217
|
// Active
|
|
268
|
-
switch (
|
|
218
|
+
switch (deviceStatus.body.power) {
|
|
269
219
|
case 'on':
|
|
270
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
220
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
271
221
|
break;
|
|
272
222
|
default:
|
|
273
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
223
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
274
224
|
}
|
|
275
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
276
226
|
// Water Level
|
|
277
|
-
if (
|
|
278
|
-
this.WaterLevel = 0;
|
|
227
|
+
if (deviceStatus.body.lackWater) {
|
|
228
|
+
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
279
229
|
}
|
|
280
230
|
else {
|
|
281
|
-
this.WaterLevel = 100;
|
|
231
|
+
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
232
|
+
}
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
234
|
+
// Firmware Version
|
|
235
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${deviceStatus.body.version}`);
|
|
236
|
+
if (deviceStatus.body.version) {
|
|
237
|
+
this.accessory.context.version = deviceStatus.body.version;
|
|
238
|
+
this.accessory
|
|
239
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
240
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
241
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
242
|
+
.updateValue(this.accessory.context.version);
|
|
282
243
|
}
|
|
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
244
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Asks the SwitchBot API for the latest device information
|
|
290
|
-
*/
|
|
291
245
|
async refreshStatus() {
|
|
292
246
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
293
247
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -317,103 +271,42 @@ export class Humidifier {
|
|
|
317
271
|
// Start to monitor advertisement packets
|
|
318
272
|
(async () => {
|
|
319
273
|
// Start to monitor advertisement packets
|
|
320
|
-
await switchbot.startScan({
|
|
321
|
-
model: 'e',
|
|
322
|
-
id: this.device.bleMac,
|
|
323
|
-
});
|
|
274
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
324
275
|
// Set an event handler
|
|
325
276
|
switchbot.onadvertisement = (ad) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
277
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
279
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
329
280
|
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
281
|
}
|
|
334
282
|
else {
|
|
335
283
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
336
284
|
}
|
|
337
285
|
};
|
|
338
|
-
// Wait
|
|
286
|
+
// Wait 10 seconds
|
|
339
287
|
await switchbot.wait(this.scanDuration * 1000);
|
|
340
288
|
// Stop to monitor
|
|
341
289
|
await switchbot.stopScan();
|
|
342
290
|
// Update HomeKit
|
|
343
|
-
await this.BLEparseStatus();
|
|
291
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
344
292
|
await this.updateHomeKitCharacteristics();
|
|
345
293
|
})();
|
|
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
|
-
}*/
|
|
294
|
+
if (switchbot === undefined) {
|
|
295
|
+
await this.BLERefreshConnection(switchbot);
|
|
296
|
+
}
|
|
395
297
|
}
|
|
396
298
|
async openAPIRefreshStatus() {
|
|
397
299
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
398
300
|
try {
|
|
399
|
-
const { body, statusCode } = await
|
|
400
|
-
headers: this.platform.generateHeaders(),
|
|
401
|
-
});
|
|
301
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
402
302
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
403
303
|
const deviceStatus = await body.json();
|
|
404
304
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
405
305
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
406
306
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
407
|
-
this.
|
|
307
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
408
308
|
+ `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();
|
|
309
|
+
this.openAPIparseStatus(deviceStatus);
|
|
417
310
|
this.updateHomeKitCharacteristics();
|
|
418
311
|
}
|
|
419
312
|
else {
|
|
@@ -465,11 +358,13 @@ export class Humidifier {
|
|
|
465
358
|
id: this.device.bleMac,
|
|
466
359
|
})
|
|
467
360
|
.then(async (device_list) => {
|
|
468
|
-
this.infoLog(`${this.accessory.displayName}
|
|
469
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
361
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
362
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
470
363
|
})
|
|
471
364
|
.then(() => {
|
|
472
365
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
366
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
367
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
473
368
|
})
|
|
474
369
|
.catch(async (e) => {
|
|
475
370
|
this.apiError(e);
|
|
@@ -480,12 +375,13 @@ export class Humidifier {
|
|
|
480
375
|
}
|
|
481
376
|
async openAPIpushChanges() {
|
|
482
377
|
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}
|
|
378
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
379
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
380
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
381
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
486
382
|
const bodyChange = JSON.stringify({
|
|
487
383
|
command: 'setMode',
|
|
488
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
384
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
489
385
|
commandType: 'command',
|
|
490
386
|
});
|
|
491
387
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -503,6 +399,8 @@ export class Humidifier {
|
|
|
503
399
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
504
400
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
505
401
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
402
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
403
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
506
404
|
}
|
|
507
405
|
else {
|
|
508
406
|
this.statusCode(statusCode);
|
|
@@ -515,8 +413,9 @@ export class Humidifier {
|
|
|
515
413
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
516
414
|
}
|
|
517
415
|
}
|
|
518
|
-
else if (this.TargetHumidifierDehumidifierState ===
|
|
519
|
-
this.
|
|
416
|
+
else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
417
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
418
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
520
419
|
await this.pushAutoChanges();
|
|
521
420
|
}
|
|
522
421
|
else {
|
|
@@ -528,8 +427,9 @@ export class Humidifier {
|
|
|
528
427
|
*/
|
|
529
428
|
async pushAutoChanges() {
|
|
530
429
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
531
|
-
if (this.TargetHumidifierDehumidifierState ===
|
|
532
|
-
this.
|
|
430
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
431
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
432
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
533
433
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
534
434
|
const bodyChange = JSON.stringify({
|
|
535
435
|
command: 'setMode',
|
|
@@ -551,6 +451,8 @@ export class Humidifier {
|
|
|
551
451
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
552
452
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
553
453
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
454
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
455
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
554
456
|
}
|
|
555
457
|
else {
|
|
556
458
|
this.statusCode(statusCode);
|
|
@@ -564,8 +466,8 @@ export class Humidifier {
|
|
|
564
466
|
}
|
|
565
467
|
}
|
|
566
468
|
else {
|
|
567
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges
|
|
568
|
-
`
|
|
469
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
470
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
569
471
|
}
|
|
570
472
|
}
|
|
571
473
|
/**
|
|
@@ -573,7 +475,7 @@ export class Humidifier {
|
|
|
573
475
|
*/
|
|
574
476
|
async pushActiveChanges() {
|
|
575
477
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
576
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
478
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
577
479
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
578
480
|
const bodyChange = JSON.stringify({
|
|
579
481
|
command: 'turnOff',
|
|
@@ -595,6 +497,8 @@ export class Humidifier {
|
|
|
595
497
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
596
498
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
597
499
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
500
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
501
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
598
502
|
}
|
|
599
503
|
else {
|
|
600
504
|
this.statusCode(statusCode);
|
|
@@ -608,49 +512,49 @@ export class Humidifier {
|
|
|
608
512
|
}
|
|
609
513
|
}
|
|
610
514
|
else {
|
|
611
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
515
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
612
516
|
}
|
|
613
517
|
}
|
|
614
518
|
/**
|
|
615
519
|
* Handle requests to set the "Active" characteristic
|
|
616
520
|
*/
|
|
617
521
|
async ActiveSet(value) {
|
|
618
|
-
if (this.Active === this.accessory.context.Active) {
|
|
522
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
619
523
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
620
524
|
}
|
|
621
525
|
else {
|
|
622
526
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
623
527
|
}
|
|
624
|
-
this.Active = value;
|
|
528
|
+
this.HumidifierDehumidifier.Active = value;
|
|
625
529
|
this.doHumidifierUpdate.next();
|
|
626
530
|
}
|
|
627
531
|
/**
|
|
628
532
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
629
533
|
*/
|
|
630
534
|
async TargetHumidifierDehumidifierStateSet(value) {
|
|
631
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
535
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
632
536
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
633
537
|
}
|
|
634
538
|
else {
|
|
635
539
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
636
540
|
}
|
|
637
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
541
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
638
542
|
this.doHumidifierUpdate.next();
|
|
639
543
|
}
|
|
640
544
|
/**
|
|
641
545
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
642
546
|
*/
|
|
643
547
|
async RelativeHumidityHumidifierThresholdSet(value) {
|
|
644
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
548
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
645
549
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
646
550
|
}
|
|
647
551
|
else {
|
|
648
552
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
649
553
|
}
|
|
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;
|
|
554
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
555
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
556
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
557
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
654
558
|
}
|
|
655
559
|
this.doHumidifierUpdate.next();
|
|
656
560
|
}
|
|
@@ -658,99 +562,77 @@ export class Humidifier {
|
|
|
658
562
|
* Updates the status for each of the HomeKit Characteristics
|
|
659
563
|
*/
|
|
660
564
|
async updateHomeKitCharacteristics() {
|
|
661
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
662
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
565
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
566
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
567
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
663
568
|
}
|
|
664
569
|
else {
|
|
665
|
-
this.
|
|
666
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
667
|
-
|
|
570
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
571
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
572
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
573
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
668
574
|
}
|
|
669
575
|
if (this.OpenAPI) {
|
|
670
|
-
if (this.WaterLevel === undefined) {
|
|
671
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
576
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
577
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
672
578
|
}
|
|
673
579
|
else {
|
|
674
|
-
this.
|
|
675
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
676
|
-
|
|
580
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
581
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
582
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
583
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
677
584
|
}
|
|
678
585
|
}
|
|
679
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
586
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
680
587
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
681
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
588
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
682
589
|
}
|
|
683
590
|
else {
|
|
684
|
-
this.
|
|
685
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
686
|
-
`
|
|
687
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
591
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
592
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
593
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
594
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
688
595
|
}
|
|
689
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
690
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
596
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
597
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
598
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
691
599
|
}
|
|
692
600
|
else {
|
|
693
|
-
this.
|
|
694
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
695
|
-
`
|
|
696
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
601
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
602
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
603
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
604
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
697
605
|
}
|
|
698
|
-
if (this.Active === undefined) {
|
|
699
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
606
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
607
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
700
608
|
}
|
|
701
609
|
else {
|
|
702
|
-
this.
|
|
703
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
704
|
-
this.accessory.context.Active = this.Active;
|
|
610
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
611
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
612
|
+
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
705
613
|
}
|
|
706
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
614
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
707
615
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
708
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
616
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
709
617
|
}
|
|
710
618
|
else {
|
|
711
|
-
this.
|
|
712
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
713
|
-
`
|
|
714
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
619
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
620
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
621
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
622
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
715
623
|
}
|
|
716
624
|
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}`);
|
|
625
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
626
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
719
627
|
}
|
|
720
628
|
else {
|
|
721
|
-
this.
|
|
722
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
723
|
-
|
|
629
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
630
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
631
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
632
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
724
633
|
}
|
|
725
634
|
}
|
|
726
635
|
}
|
|
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
636
|
async BLEPushConnection() {
|
|
755
637
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
756
638
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -765,279 +647,36 @@ export class Humidifier {
|
|
|
765
647
|
await this.openAPIRefreshStatus();
|
|
766
648
|
}
|
|
767
649
|
}
|
|
768
|
-
minStep() {
|
|
769
|
-
|
|
770
|
-
|
|
650
|
+
minStep(device) {
|
|
651
|
+
let set_minStep;
|
|
652
|
+
if (device.humidifier?.set_minStep) {
|
|
653
|
+
set_minStep = device.humidifier?.set_minStep;
|
|
771
654
|
}
|
|
772
655
|
else {
|
|
773
|
-
|
|
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`);
|
|
656
|
+
set_minStep = 1;
|
|
860
657
|
}
|
|
658
|
+
return set_minStep;
|
|
861
659
|
}
|
|
862
660
|
async offlineOff() {
|
|
863
661
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
864
662
|
if (this.device.offline) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
await this.updateHomeKitCharacteristics();
|
|
663
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
664
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
665
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
870
666
|
}
|
|
871
667
|
}
|
|
872
668
|
async apiError(e) {
|
|
873
|
-
this.
|
|
669
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
874
670
|
if (!this.BLE) {
|
|
875
|
-
this.
|
|
671
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
876
672
|
}
|
|
877
|
-
this.
|
|
878
|
-
this.
|
|
879
|
-
this.
|
|
880
|
-
this.
|
|
673
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
674
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
675
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
676
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
881
677
|
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;
|
|
678
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
956
679
|
}
|
|
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
680
|
}
|
|
1042
681
|
}
|
|
1043
682
|
//# sourceMappingURL=humidifier.js.map
|