@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.30
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 +147 -9
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +347 -756
- 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 +582 -759
- 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 +209 -587
- 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 +250 -632
- 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 +204 -531
- 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 +335 -786
- 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 +646 -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 +499 -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 +242 -596
- 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 +207 -571
- 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 +174 -584
- 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 +252 -568
- 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 +210 -542
- 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 +170 -577
- 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 +159 -577
- 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 +136 -518
- 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 +82 -452
- 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 +140 -451
- 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 +121 -664
- package/dist/device/waterdetector.js.map +1 -1
- 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 +509 -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 +237 -94
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +40 -10
- 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 +373 -782
- package/src/device/bot.ts +616 -844
- package/src/device/ceilinglight.ts +222 -607
- package/src/device/colorbulb.ts +264 -656
- package/src/device/contact.ts +229 -553
- package/src/device/curtain.ts +355 -810
- package/src/device/device.ts +673 -0
- package/src/device/fan.ts +548 -0
- package/src/device/hub.ts +268 -623
- package/src/device/humidifier.ts +237 -618
- package/src/device/iosensor.ts +200 -610
- package/src/device/lightstrip.ts +273 -596
- package/src/device/lock.ts +247 -582
- package/src/device/meter.ts +196 -601
- package/src/device/meterplus.ts +184 -602
- package/src/device/motion.ts +156 -541
- package/src/device/plug.ts +92 -480
- package/src/device/robotvacuumcleaner.ts +161 -477
- package/src/device/waterdetector.ts +139 -689
- 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 +526 -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 +247 -102
- package/src/settings.ts +56 -565
- 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,93 @@ 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;
|
|
282
232
|
}
|
|
283
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
284
234
|
// FirmwareRevision
|
|
285
|
-
this.FirmwareRevision =
|
|
286
|
-
this.accessory
|
|
235
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
236
|
+
this.accessory
|
|
237
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
238
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
|
|
239
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
240
|
+
.updateValue(this.accessory.context.FirmwareRevision);
|
|
287
241
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Asks the SwitchBot API for the latest device information
|
|
290
|
-
*/
|
|
291
242
|
async refreshStatus() {
|
|
292
243
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
293
244
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -317,103 +268,42 @@ export class Humidifier {
|
|
|
317
268
|
// Start to monitor advertisement packets
|
|
318
269
|
(async () => {
|
|
319
270
|
// Start to monitor advertisement packets
|
|
320
|
-
await switchbot.startScan({
|
|
321
|
-
model: 'e',
|
|
322
|
-
id: this.device.bleMac,
|
|
323
|
-
});
|
|
271
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
324
272
|
// Set an event handler
|
|
325
273
|
switchbot.onadvertisement = (ad) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
274
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
276
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
329
277
|
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
278
|
}
|
|
334
279
|
else {
|
|
335
280
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
336
281
|
}
|
|
337
282
|
};
|
|
338
|
-
// Wait
|
|
283
|
+
// Wait 10 seconds
|
|
339
284
|
await switchbot.wait(this.scanDuration * 1000);
|
|
340
285
|
// Stop to monitor
|
|
341
286
|
await switchbot.stopScan();
|
|
342
287
|
// Update HomeKit
|
|
343
|
-
await this.BLEparseStatus();
|
|
288
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
344
289
|
await this.updateHomeKitCharacteristics();
|
|
345
290
|
})();
|
|
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
|
-
}*/
|
|
291
|
+
if (switchbot === undefined) {
|
|
292
|
+
await this.BLERefreshConnection(switchbot);
|
|
293
|
+
}
|
|
395
294
|
}
|
|
396
295
|
async openAPIRefreshStatus() {
|
|
397
296
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
398
297
|
try {
|
|
399
|
-
const { body, statusCode } = await
|
|
400
|
-
headers: this.platform.generateHeaders(),
|
|
401
|
-
});
|
|
298
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
402
299
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
403
300
|
const deviceStatus = await body.json();
|
|
404
301
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
405
302
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
406
303
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
407
|
-
this.
|
|
304
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
408
305
|
+ `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();
|
|
306
|
+
this.openAPIparseStatus(deviceStatus);
|
|
417
307
|
this.updateHomeKitCharacteristics();
|
|
418
308
|
}
|
|
419
309
|
else {
|
|
@@ -465,11 +355,13 @@ export class Humidifier {
|
|
|
465
355
|
id: this.device.bleMac,
|
|
466
356
|
})
|
|
467
357
|
.then(async (device_list) => {
|
|
468
|
-
this.infoLog(`${this.accessory.displayName}
|
|
469
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
358
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
359
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
470
360
|
})
|
|
471
361
|
.then(() => {
|
|
472
362
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
363
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
364
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
473
365
|
})
|
|
474
366
|
.catch(async (e) => {
|
|
475
367
|
this.apiError(e);
|
|
@@ -480,12 +372,13 @@ export class Humidifier {
|
|
|
480
372
|
}
|
|
481
373
|
async openAPIpushChanges() {
|
|
482
374
|
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}
|
|
375
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
376
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
377
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
378
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
486
379
|
const bodyChange = JSON.stringify({
|
|
487
380
|
command: 'setMode',
|
|
488
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
381
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
489
382
|
commandType: 'command',
|
|
490
383
|
});
|
|
491
384
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -503,6 +396,8 @@ export class Humidifier {
|
|
|
503
396
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
504
397
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
505
398
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
399
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
400
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
506
401
|
}
|
|
507
402
|
else {
|
|
508
403
|
this.statusCode(statusCode);
|
|
@@ -515,8 +410,9 @@ export class Humidifier {
|
|
|
515
410
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
516
411
|
}
|
|
517
412
|
}
|
|
518
|
-
else if (this.TargetHumidifierDehumidifierState ===
|
|
519
|
-
this.
|
|
413
|
+
else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
414
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
415
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
520
416
|
await this.pushAutoChanges();
|
|
521
417
|
}
|
|
522
418
|
else {
|
|
@@ -528,8 +424,9 @@ export class Humidifier {
|
|
|
528
424
|
*/
|
|
529
425
|
async pushAutoChanges() {
|
|
530
426
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
531
|
-
if (this.TargetHumidifierDehumidifierState ===
|
|
532
|
-
this.
|
|
427
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
428
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
429
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
533
430
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
534
431
|
const bodyChange = JSON.stringify({
|
|
535
432
|
command: 'setMode',
|
|
@@ -551,6 +448,8 @@ export class Humidifier {
|
|
|
551
448
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
552
449
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
553
450
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
451
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
452
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
554
453
|
}
|
|
555
454
|
else {
|
|
556
455
|
this.statusCode(statusCode);
|
|
@@ -564,8 +463,8 @@ export class Humidifier {
|
|
|
564
463
|
}
|
|
565
464
|
}
|
|
566
465
|
else {
|
|
567
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges
|
|
568
|
-
`
|
|
466
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
467
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
569
468
|
}
|
|
570
469
|
}
|
|
571
470
|
/**
|
|
@@ -573,7 +472,7 @@ export class Humidifier {
|
|
|
573
472
|
*/
|
|
574
473
|
async pushActiveChanges() {
|
|
575
474
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
576
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
475
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
577
476
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
578
477
|
const bodyChange = JSON.stringify({
|
|
579
478
|
command: 'turnOff',
|
|
@@ -595,6 +494,8 @@ export class Humidifier {
|
|
|
595
494
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
596
495
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
597
496
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
497
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
498
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
598
499
|
}
|
|
599
500
|
else {
|
|
600
501
|
this.statusCode(statusCode);
|
|
@@ -608,49 +509,49 @@ export class Humidifier {
|
|
|
608
509
|
}
|
|
609
510
|
}
|
|
610
511
|
else {
|
|
611
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
512
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
612
513
|
}
|
|
613
514
|
}
|
|
614
515
|
/**
|
|
615
516
|
* Handle requests to set the "Active" characteristic
|
|
616
517
|
*/
|
|
617
518
|
async ActiveSet(value) {
|
|
618
|
-
if (this.Active === this.accessory.context.Active) {
|
|
519
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
619
520
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
620
521
|
}
|
|
621
522
|
else {
|
|
622
523
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
623
524
|
}
|
|
624
|
-
this.Active = value;
|
|
525
|
+
this.HumidifierDehumidifier.Active = value;
|
|
625
526
|
this.doHumidifierUpdate.next();
|
|
626
527
|
}
|
|
627
528
|
/**
|
|
628
529
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
629
530
|
*/
|
|
630
531
|
async TargetHumidifierDehumidifierStateSet(value) {
|
|
631
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
532
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
632
533
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
633
534
|
}
|
|
634
535
|
else {
|
|
635
536
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
636
537
|
}
|
|
637
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
538
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
638
539
|
this.doHumidifierUpdate.next();
|
|
639
540
|
}
|
|
640
541
|
/**
|
|
641
542
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
642
543
|
*/
|
|
643
544
|
async RelativeHumidityHumidifierThresholdSet(value) {
|
|
644
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
545
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
645
546
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
646
547
|
}
|
|
647
548
|
else {
|
|
648
549
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
649
550
|
}
|
|
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;
|
|
551
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
552
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
553
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
554
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
654
555
|
}
|
|
655
556
|
this.doHumidifierUpdate.next();
|
|
656
557
|
}
|
|
@@ -658,99 +559,77 @@ export class Humidifier {
|
|
|
658
559
|
* Updates the status for each of the HomeKit Characteristics
|
|
659
560
|
*/
|
|
660
561
|
async updateHomeKitCharacteristics() {
|
|
661
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
662
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
562
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
564
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
663
565
|
}
|
|
664
566
|
else {
|
|
665
|
-
this.
|
|
666
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
667
|
-
|
|
567
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
568
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
569
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
570
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
668
571
|
}
|
|
669
572
|
if (this.OpenAPI) {
|
|
670
|
-
if (this.WaterLevel === undefined) {
|
|
671
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
573
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
574
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
672
575
|
}
|
|
673
576
|
else {
|
|
674
|
-
this.
|
|
675
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
676
|
-
|
|
577
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
578
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
579
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
580
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
677
581
|
}
|
|
678
582
|
}
|
|
679
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
583
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
680
584
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
681
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
585
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
682
586
|
}
|
|
683
587
|
else {
|
|
684
|
-
this.
|
|
685
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
686
|
-
`
|
|
687
|
-
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
588
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
589
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
590
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
591
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
688
592
|
}
|
|
689
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
690
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
593
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
594
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
595
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
691
596
|
}
|
|
692
597
|
else {
|
|
693
|
-
this.
|
|
694
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
695
|
-
`
|
|
696
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
598
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
600
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
601
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
697
602
|
}
|
|
698
|
-
if (this.Active === undefined) {
|
|
699
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
603
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
604
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
700
605
|
}
|
|
701
606
|
else {
|
|
702
|
-
this.
|
|
703
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
704
|
-
this.accessory.context.Active = this.Active;
|
|
607
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
608
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
609
|
+
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
705
610
|
}
|
|
706
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
611
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
707
612
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
708
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
613
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
709
614
|
}
|
|
710
615
|
else {
|
|
711
|
-
this.
|
|
712
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
713
|
-
`
|
|
714
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
616
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
617
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
618
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
619
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
715
620
|
}
|
|
716
621
|
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}`);
|
|
622
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
623
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
719
624
|
}
|
|
720
625
|
else {
|
|
721
|
-
this.
|
|
722
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
723
|
-
|
|
626
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
627
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
628
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
629
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
724
630
|
}
|
|
725
631
|
}
|
|
726
632
|
}
|
|
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
633
|
async BLEPushConnection() {
|
|
755
634
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
756
635
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -765,279 +644,36 @@ export class Humidifier {
|
|
|
765
644
|
await this.openAPIRefreshStatus();
|
|
766
645
|
}
|
|
767
646
|
}
|
|
768
|
-
minStep() {
|
|
769
|
-
|
|
770
|
-
|
|
647
|
+
minStep(device) {
|
|
648
|
+
let set_minStep;
|
|
649
|
+
if (device.humidifier?.set_minStep) {
|
|
650
|
+
set_minStep = device.humidifier?.set_minStep;
|
|
771
651
|
}
|
|
772
652
|
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`);
|
|
653
|
+
set_minStep = 1;
|
|
860
654
|
}
|
|
655
|
+
return set_minStep;
|
|
861
656
|
}
|
|
862
657
|
async offlineOff() {
|
|
863
658
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
864
659
|
if (this.device.offline) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
await this.updateHomeKitCharacteristics();
|
|
660
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
661
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
662
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
870
663
|
}
|
|
871
664
|
}
|
|
872
665
|
async apiError(e) {
|
|
873
|
-
this.
|
|
666
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
874
667
|
if (!this.BLE) {
|
|
875
|
-
this.
|
|
668
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
876
669
|
}
|
|
877
|
-
this.
|
|
878
|
-
this.
|
|
879
|
-
this.
|
|
880
|
-
this.
|
|
670
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
671
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
672
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
673
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
881
674
|
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;
|
|
675
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
956
676
|
}
|
|
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
677
|
}
|
|
1042
678
|
}
|
|
1043
679
|
//# sourceMappingURL=humidifier.js.map
|