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