@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +14 -45
- package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
- package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
- package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
- package/.github/labeler.yml +1 -1
- package/.github/workflows/codeql-analysis.yml +29 -29
- package/.github/workflows/nodejs-beta.yml +1 -1
- package/.github/workflows/prerelease-beta.js +1 -1
- package/.github/workflows/stale.yml +1 -1
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +2 -4
- package/.vscode/settings.json +14 -2
- package/CHANGELOG.md +16 -0
- package/README.md +100 -99
- package/SECURITY.md +2 -2
- package/config.schema.json +17 -0
- package/dist/devices/bots.d.ts +35 -32
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +168 -210
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +35 -35
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +83 -108
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -25
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +110 -131
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -27
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +147 -182
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +31 -31
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +154 -181
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +29 -28
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +98 -120
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +24 -23
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +97 -113
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +16 -16
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +48 -71
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -22
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +7 -4
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +72 -93
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +3 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +32 -51
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +3 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +19 -26
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +3 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +35 -44
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +3 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +25 -32
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +3 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +21 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +3 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +66 -89
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +3 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +18 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +3 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +19 -26
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +163 -233
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +231 -245
- package/homebridge-ui/server.js +2 -4
- package/nodemon.json +2 -4
- package/package.json +17 -12
- package/src/devices/bots.ts +411 -854
- package/src/devices/colorbulb.ts +187 -408
- package/src/devices/contact.ts +210 -376
- package/src/devices/curtains.ts +288 -563
- package/src/devices/humidifiers.ts +291 -537
- package/src/devices/meters.ts +189 -331
- package/src/devices/motion.ts +188 -322
- package/src/devices/plugs.ts +88 -160
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +139 -318
- package/src/irdevices/airpurifiers.ts +71 -170
- package/src/irdevices/cameras.ts +44 -103
- package/src/irdevices/fans.ts +70 -165
- package/src/irdevices/lights.ts +49 -104
- package/src/irdevices/others.ts +55 -131
- package/src/irdevices/tvs.ts +114 -247
- package/src/irdevices/vacuumcleaners.ts +44 -104
- package/src/irdevices/waterheaters.ts +49 -121
- package/src/platform.ts +341 -753
- package/src/settings.ts +8 -11
- package/tsconfig.json +5 -14
- package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { interval, Subject } from 'rxjs';
|
|
3
|
+
import { SwitchBotPlatform } from '../platform';
|
|
4
|
+
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
|
+
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
|
+
import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
@@ -12,34 +12,33 @@ import * as settings from "../settings";
|
|
|
12
12
|
*/
|
|
13
13
|
export class Humidifier {
|
|
14
14
|
// Services
|
|
15
|
-
private service:
|
|
16
|
-
temperatureservice?:
|
|
15
|
+
private service: Service;
|
|
16
|
+
temperatureservice?: Service;
|
|
17
17
|
|
|
18
18
|
// Characteristic Values
|
|
19
|
-
CurrentRelativeHumidity!:
|
|
20
|
-
CurrentTemperature!:
|
|
21
|
-
TargetHumidifierDehumidifierState!:
|
|
22
|
-
CurrentHumidifierDehumidifierState!:
|
|
23
|
-
RelativeHumidityHumidifierThreshold!:
|
|
24
|
-
Active!:
|
|
25
|
-
WaterLevel!:
|
|
19
|
+
CurrentRelativeHumidity!: CharacteristicValue;
|
|
20
|
+
CurrentTemperature!: CharacteristicValue;
|
|
21
|
+
TargetHumidifierDehumidifierState!: CharacteristicValue;
|
|
22
|
+
CurrentHumidifierDehumidifierState!: CharacteristicValue;
|
|
23
|
+
RelativeHumidityHumidifierThreshold!: CharacteristicValue;
|
|
24
|
+
Active!: CharacteristicValue;
|
|
25
|
+
WaterLevel!: CharacteristicValue;
|
|
26
26
|
|
|
27
27
|
// OpenAPI
|
|
28
|
-
auto:
|
|
29
|
-
power:
|
|
30
|
-
humidity:
|
|
31
|
-
lackWater:
|
|
32
|
-
temperature:
|
|
33
|
-
nebulizationEfficiency:
|
|
34
|
-
deviceStatus!:
|
|
28
|
+
auto: deviceStatus['auto'];
|
|
29
|
+
power: deviceStatus['power'];
|
|
30
|
+
humidity: deviceStatus['humidity'];
|
|
31
|
+
lackWater: deviceStatus['lackWater'];
|
|
32
|
+
temperature: deviceStatus['temperature'];
|
|
33
|
+
nebulizationEfficiency: deviceStatus['nebulizationEfficiency'];
|
|
34
|
+
deviceStatus!: deviceStatusResponse;
|
|
35
35
|
|
|
36
36
|
// BLE Others
|
|
37
37
|
connected?: boolean;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
percentage!: settings.serviceData["percentage"];
|
|
38
|
+
serviceData!: serviceData;
|
|
39
|
+
onState!: serviceData['onState'];
|
|
40
|
+
autoMode!: serviceData['autoMode'];
|
|
41
|
+
percentage!: serviceData['percentage'];
|
|
43
42
|
|
|
44
43
|
// Config
|
|
45
44
|
set_minStep?: number;
|
|
@@ -49,30 +48,30 @@ export class Humidifier {
|
|
|
49
48
|
|
|
50
49
|
// Updates
|
|
51
50
|
humidifierUpdateInProgress!: boolean;
|
|
52
|
-
doHumidifierUpdate!:
|
|
51
|
+
doHumidifierUpdate!: Subject<void>;
|
|
53
52
|
|
|
54
|
-
constructor(
|
|
55
|
-
private readonly platform: platform_1.SwitchBotPlatform,
|
|
56
|
-
private accessory: homebridge.PlatformAccessory,
|
|
57
|
-
public device: settings.device & settings.devicesConfig,
|
|
58
|
-
) {
|
|
53
|
+
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
59
54
|
// default placeholders
|
|
60
55
|
this.logs(device);
|
|
61
56
|
this.scan(device);
|
|
62
57
|
this.refreshRate(device);
|
|
63
58
|
this.config(device);
|
|
64
59
|
this.CurrentRelativeHumidity = 0;
|
|
65
|
-
this.TargetHumidifierDehumidifierState =
|
|
66
|
-
|
|
67
|
-
this.CurrentHumidifierDehumidifierState =
|
|
68
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
60
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
61
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
69
62
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
70
63
|
this.RelativeHumidityHumidifierThreshold = 0;
|
|
71
64
|
this.CurrentTemperature = 0;
|
|
72
65
|
this.WaterLevel = 0;
|
|
73
66
|
|
|
67
|
+
// Humidifiers Config
|
|
68
|
+
this.debugLog(
|
|
69
|
+
`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: ` +
|
|
70
|
+
`${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`,
|
|
71
|
+
);
|
|
72
|
+
|
|
74
73
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
75
|
-
this.doHumidifierUpdate = new
|
|
74
|
+
this.doHumidifierUpdate = new Subject();
|
|
76
75
|
this.humidifierUpdateInProgress = false;
|
|
77
76
|
|
|
78
77
|
// Retrieve initial values and updateHomekit
|
|
@@ -81,21 +80,14 @@ export class Humidifier {
|
|
|
81
80
|
// set accessory information
|
|
82
81
|
accessory
|
|
83
82
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
84
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
85
|
-
.setCharacteristic(
|
|
86
|
-
|
|
87
|
-
"SWITCHBOT-HUMIDIFIER-W0801800",
|
|
88
|
-
)
|
|
89
|
-
.setCharacteristic(
|
|
90
|
-
this.platform.Characteristic.SerialNumber,
|
|
91
|
-
device.deviceId!,
|
|
92
|
-
);
|
|
83
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
84
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-HUMIDIFIER-W0801800')
|
|
85
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
93
86
|
|
|
94
87
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
95
88
|
// you can create multiple services for each accessory
|
|
96
89
|
(this.service =
|
|
97
|
-
accessory.getService(this.platform.Service.HumidifierDehumidifier) ||
|
|
98
|
-
accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
90
|
+
accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
|
|
99
91
|
`${accessory.displayName} Humidifier`;
|
|
100
92
|
|
|
101
93
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -104,24 +96,16 @@ export class Humidifier {
|
|
|
104
96
|
|
|
105
97
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
106
98
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
107
|
-
this.service.setCharacteristic(
|
|
108
|
-
this.platform.Characteristic.Name,
|
|
109
|
-
accessory.displayName,
|
|
110
|
-
);
|
|
99
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
111
100
|
|
|
112
101
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
113
102
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
114
103
|
|
|
115
104
|
// create handlers for required characteristics
|
|
116
|
-
this.service.setCharacteristic(
|
|
117
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
118
|
-
this.CurrentHumidifierDehumidifierState,
|
|
119
|
-
);
|
|
105
|
+
this.service.setCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
120
106
|
|
|
121
107
|
this.service
|
|
122
|
-
.getCharacteristic(
|
|
123
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
124
|
-
)
|
|
108
|
+
.getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
|
|
125
109
|
.setProps({
|
|
126
110
|
validValueRanges: [0, 1],
|
|
127
111
|
minValue: 0,
|
|
@@ -130,14 +114,10 @@ export class Humidifier {
|
|
|
130
114
|
})
|
|
131
115
|
.onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
|
|
132
116
|
|
|
133
|
-
this.service
|
|
134
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
135
|
-
.onSet(this.handleActiveSet.bind(this));
|
|
117
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
|
|
136
118
|
|
|
137
119
|
this.service
|
|
138
|
-
.getCharacteristic(
|
|
139
|
-
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
140
|
-
)
|
|
120
|
+
.getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
141
121
|
.setProps({
|
|
142
122
|
validValueRanges: [0, 100],
|
|
143
123
|
minValue: 0,
|
|
@@ -149,26 +129,16 @@ export class Humidifier {
|
|
|
149
129
|
// create a new Temperature Sensor service
|
|
150
130
|
// Temperature Sensor Service
|
|
151
131
|
if (device.humidifier?.hide_temperature || device.ble) {
|
|
152
|
-
this.debugLog(
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
this.temperatureservice = this.accessory.getService(
|
|
156
|
-
this.platform.Service.TemperatureSensor,
|
|
157
|
-
);
|
|
132
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
133
|
+
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
158
134
|
accessory.removeService(this.temperatureservice!);
|
|
159
135
|
} else if (!this.temperatureservice && !device.ble) {
|
|
160
|
-
this.debugLog(
|
|
161
|
-
`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`,
|
|
162
|
-
);
|
|
136
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
163
137
|
(this.temperatureservice =
|
|
164
|
-
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
165
|
-
this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
138
|
+
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
166
139
|
`${accessory.displayName} Temperature Sensor`;
|
|
167
140
|
|
|
168
|
-
this.temperatureservice.setCharacteristic(
|
|
169
|
-
this.platform.Characteristic.Name,
|
|
170
|
-
`${accessory.displayName} Temperature Sensor`,
|
|
171
|
-
);
|
|
141
|
+
this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
172
142
|
|
|
173
143
|
this.temperatureservice
|
|
174
144
|
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
@@ -182,18 +152,15 @@ export class Humidifier {
|
|
|
182
152
|
return this.CurrentTemperature;
|
|
183
153
|
});
|
|
184
154
|
} else {
|
|
185
|
-
this.debugLog(
|
|
186
|
-
`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`,
|
|
187
|
-
);
|
|
155
|
+
this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
188
156
|
}
|
|
189
157
|
|
|
190
158
|
// Retrieve initial values and updateHomekit
|
|
191
159
|
this.updateHomeKitCharacteristics();
|
|
192
160
|
|
|
193
161
|
// Start an update interval
|
|
194
|
-
|
|
195
|
-
.
|
|
196
|
-
.pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
|
|
162
|
+
interval(this.deviceRefreshRate * 1000)
|
|
163
|
+
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
197
164
|
.subscribe(() => {
|
|
198
165
|
this.refreshStatus();
|
|
199
166
|
});
|
|
@@ -202,23 +169,21 @@ export class Humidifier {
|
|
|
202
169
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
203
170
|
this.doHumidifierUpdate
|
|
204
171
|
.pipe(
|
|
205
|
-
|
|
172
|
+
tap(() => {
|
|
206
173
|
this.humidifierUpdateInProgress = true;
|
|
207
174
|
}),
|
|
208
|
-
|
|
175
|
+
debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
209
176
|
)
|
|
210
177
|
.subscribe(async () => {
|
|
211
178
|
try {
|
|
212
179
|
await this.pushChanges();
|
|
213
180
|
} catch (e: any) {
|
|
214
|
-
this.errorLog(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
221
|
-
);
|
|
181
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
|
|
182
|
+
if (this.deviceLogging === 'debug') {
|
|
183
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
184
|
+
}
|
|
185
|
+
if (this.platform.debugMode) {
|
|
186
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
222
187
|
}
|
|
223
188
|
this.apiError(e);
|
|
224
189
|
}
|
|
@@ -229,7 +194,7 @@ export class Humidifier {
|
|
|
229
194
|
/**
|
|
230
195
|
* Parse the device status from the SwitchBot api
|
|
231
196
|
*/
|
|
232
|
-
parseStatus()
|
|
197
|
+
parseStatus() {
|
|
233
198
|
if (this.device.ble) {
|
|
234
199
|
this.BLEparseStatus();
|
|
235
200
|
} else {
|
|
@@ -237,106 +202,74 @@ export class Humidifier {
|
|
|
237
202
|
}
|
|
238
203
|
}
|
|
239
204
|
|
|
240
|
-
private BLEparseStatus()
|
|
205
|
+
private BLEparseStatus() {
|
|
241
206
|
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
|
|
242
207
|
// Current Relative Humidity
|
|
243
208
|
this.CurrentRelativeHumidity = this.percentage!;
|
|
244
|
-
this.debugLog(
|
|
245
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
246
|
-
);
|
|
209
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
247
210
|
// Active
|
|
248
211
|
if (this.onState) {
|
|
249
212
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
250
213
|
} else {
|
|
251
214
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
252
215
|
}
|
|
253
|
-
this.debugLog(
|
|
254
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
255
|
-
);
|
|
216
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
256
217
|
}
|
|
257
218
|
|
|
258
219
|
private openAPIparseStatus() {
|
|
259
220
|
if (this.platform.config.credentials?.openToken) {
|
|
260
|
-
this.debugLog(
|
|
261
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`,
|
|
262
|
-
);
|
|
221
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
263
222
|
// Current Relative Humidity
|
|
264
223
|
this.CurrentRelativeHumidity = this.humidity!;
|
|
265
|
-
this.debugLog(
|
|
266
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
267
|
-
);
|
|
224
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
268
225
|
// Current Temperature
|
|
269
226
|
if (!this.device.humidifier?.hide_temperature) {
|
|
270
227
|
this.CurrentTemperature = this.temperature!;
|
|
271
|
-
this.debugLog(
|
|
272
|
-
`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
|
|
273
|
-
);
|
|
228
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
274
229
|
}
|
|
275
230
|
// Target Humidifier Dehumidifier State
|
|
276
231
|
switch (this.auto) {
|
|
277
232
|
case true:
|
|
278
|
-
this.TargetHumidifierDehumidifierState =
|
|
279
|
-
|
|
280
|
-
this.
|
|
281
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
282
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
283
|
-
this.CurrentRelativeHumidity;
|
|
233
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
234
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
235
|
+
this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
|
|
284
236
|
break;
|
|
285
237
|
default:
|
|
286
|
-
this.TargetHumidifierDehumidifierState =
|
|
287
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
238
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
288
239
|
if (this.nebulizationEfficiency! > 100) {
|
|
289
240
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
290
241
|
} else {
|
|
291
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
292
|
-
this.nebulizationEfficiency!;
|
|
242
|
+
this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
|
|
293
243
|
}
|
|
294
|
-
if (
|
|
295
|
-
this.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
this.CurrentHumidifierDehumidifierState =
|
|
299
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
300
|
-
} else if (
|
|
301
|
-
this.Active === this.platform.Characteristic.Active.INACTIVE
|
|
302
|
-
) {
|
|
303
|
-
this.CurrentHumidifierDehumidifierState =
|
|
304
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
244
|
+
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
245
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
246
|
+
} else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
247
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
305
248
|
} else {
|
|
306
|
-
this.CurrentHumidifierDehumidifierState =
|
|
307
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
249
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
308
250
|
}
|
|
309
251
|
}
|
|
252
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
310
253
|
this.debugLog(
|
|
311
|
-
`Humidifier: ${this.accessory.displayName}
|
|
312
|
-
);
|
|
313
|
-
this.debugLog(
|
|
314
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
315
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
316
|
-
);
|
|
317
|
-
this.debugLog(
|
|
318
|
-
`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
254
|
+
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
319
255
|
);
|
|
256
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
320
257
|
// Active
|
|
321
258
|
switch (this.power) {
|
|
322
|
-
case
|
|
259
|
+
case 'on':
|
|
323
260
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
324
261
|
break;
|
|
325
262
|
default:
|
|
326
263
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
327
264
|
}
|
|
328
|
-
this.debugLog(
|
|
329
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
330
|
-
);
|
|
265
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
331
266
|
// Water Level
|
|
332
267
|
if (this.lackWater) {
|
|
333
268
|
this.WaterLevel = 0;
|
|
334
269
|
} else {
|
|
335
270
|
this.WaterLevel = 100;
|
|
336
271
|
}
|
|
337
|
-
this.debugLog(
|
|
338
|
-
`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
|
|
339
|
-
);
|
|
272
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
340
273
|
}
|
|
341
274
|
}
|
|
342
275
|
|
|
@@ -352,139 +285,113 @@ export class Humidifier {
|
|
|
352
285
|
}
|
|
353
286
|
|
|
354
287
|
private async BLERefreshStatus() {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
`Humidifier: ${this.accessory.displayName} BLE refreshStatus`,
|
|
357
|
-
);
|
|
288
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
|
|
358
289
|
const switchbot = await this.platform.connectBLE();
|
|
359
290
|
// Convert to BLE Address
|
|
360
291
|
this.device.bleMac = this.device
|
|
361
292
|
.deviceId!.match(/.{1,2}/g)!
|
|
362
|
-
.join(
|
|
293
|
+
.join(':')
|
|
363
294
|
.toLowerCase();
|
|
364
|
-
this.debugLog(
|
|
365
|
-
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
`Humidifier: ${
|
|
385
|
-
this.accessory.displayName
|
|
386
|
-
} serviceData: ${JSON.stringify(ad.serviceData)}`,
|
|
387
|
-
);
|
|
388
|
-
this.debugLog(
|
|
389
|
-
`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
390
|
-
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
391
|
-
);
|
|
295
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
296
|
+
// Start to monitor advertisement packets
|
|
297
|
+
if (switchbot !== false) {
|
|
298
|
+
switchbot
|
|
299
|
+
.startScan({
|
|
300
|
+
model: 'e',
|
|
301
|
+
id: this.device.bleMac,
|
|
302
|
+
})
|
|
303
|
+
.then(() => {
|
|
304
|
+
// Set an event hander
|
|
305
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
306
|
+
this.serviceData = ad.serviceData;
|
|
307
|
+
this.autoMode = ad.serviceData.autoMode;
|
|
308
|
+
this.onState = ad.serviceData.onState;
|
|
309
|
+
this.percentage = ad.serviceData.percentage;
|
|
310
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
311
|
+
this.debugLog(
|
|
312
|
+
`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
313
|
+
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
314
|
+
);
|
|
392
315
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
this.apiError(e);
|
|
316
|
+
if (this.serviceData) {
|
|
317
|
+
this.connected = true;
|
|
318
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
319
|
+
} else {
|
|
320
|
+
this.connected = false;
|
|
321
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
// Wait 2 seconds
|
|
325
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
326
|
+
})
|
|
327
|
+
.then(async () => {
|
|
328
|
+
// Stop to monitor
|
|
329
|
+
switchbot.stopScan();
|
|
330
|
+
if (this.connected) {
|
|
331
|
+
this.parseStatus();
|
|
332
|
+
this.updateHomeKitCharacteristics();
|
|
333
|
+
} else {
|
|
334
|
+
await this.BLEconnection(switchbot);
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
.catch(async (e: any) => {
|
|
338
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
339
|
+
if (this.deviceLogging === 'debug') {
|
|
340
|
+
this.errorLog(
|
|
341
|
+
`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (this.platform.debugMode) {
|
|
345
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
346
|
+
}
|
|
347
|
+
if (this.platform.config.credentials?.openToken) {
|
|
348
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
349
|
+
await this.openAPIRefreshStatus();
|
|
350
|
+
}
|
|
351
|
+
this.apiError(e);
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
await this.BLEconnection(switchbot);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public async BLEconnection(switchbot: any) {
|
|
359
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
360
|
+
if (this.platform.config.credentials?.openToken) {
|
|
361
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
362
|
+
await this.openAPIRefreshStatus();
|
|
442
363
|
}
|
|
443
364
|
}
|
|
444
365
|
|
|
445
366
|
private async openAPIRefreshStatus() {
|
|
446
367
|
if (this.platform.config.credentials?.openToken) {
|
|
447
|
-
this.debugLog(
|
|
448
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`,
|
|
449
|
-
);
|
|
368
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
450
369
|
try {
|
|
451
|
-
this.deviceStatus = (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
)
|
|
455
|
-
).data;
|
|
456
|
-
if (this.deviceStatus.message === "success") {
|
|
457
|
-
this.debugLog(
|
|
458
|
-
`Humidifier: ${
|
|
459
|
-
this.accessory.displayName
|
|
460
|
-
} refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
|
|
461
|
-
);
|
|
370
|
+
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
371
|
+
if (this.deviceStatus.message === 'success') {
|
|
372
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
462
373
|
this.auto = this.deviceStatus.body.auto;
|
|
463
374
|
this.power = this.deviceStatus.body.power;
|
|
464
375
|
this.lackWater = this.deviceStatus.body.lackWater;
|
|
465
376
|
this.humidity = this.deviceStatus.body.humidity;
|
|
466
377
|
this.temperature = this.deviceStatus.body.temperature;
|
|
467
|
-
this.nebulizationEfficiency =
|
|
468
|
-
this.deviceStatus.body.nebulizationEfficiency;
|
|
378
|
+
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
469
379
|
this.parseStatus();
|
|
470
380
|
this.updateHomeKitCharacteristics();
|
|
471
381
|
} else {
|
|
472
|
-
this.errorLog(
|
|
473
|
-
`Humidifier: ${
|
|
474
|
-
this.accessory.displayName
|
|
475
|
-
} message: ${JSON.stringify(this.deviceStatus.message)}`,
|
|
476
|
-
);
|
|
382
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} message: ${JSON.stringify(this.deviceStatus.message)}`);
|
|
477
383
|
}
|
|
478
384
|
} catch (e: any) {
|
|
479
|
-
this.errorLog(
|
|
480
|
-
|
|
481
|
-
);
|
|
482
|
-
if (this.deviceLogging.includes("debug")) {
|
|
385
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
386
|
+
if (this.deviceLogging === 'debug') {
|
|
483
387
|
this.errorLog(
|
|
484
388
|
`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
485
389
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
486
390
|
);
|
|
487
391
|
}
|
|
392
|
+
if (this.platform.debugMode) {
|
|
393
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
394
|
+
}
|
|
488
395
|
this.apiError(e);
|
|
489
396
|
}
|
|
490
397
|
}
|
|
@@ -499,10 +406,9 @@ export class Humidifier {
|
|
|
499
406
|
//} else {
|
|
500
407
|
await this.openAPIpushChanges();
|
|
501
408
|
//}
|
|
502
|
-
|
|
503
|
-
.
|
|
504
|
-
.pipe(
|
|
505
|
-
.pipe(operators.take(1))
|
|
409
|
+
interval(5000)
|
|
410
|
+
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
411
|
+
.pipe(take(1))
|
|
506
412
|
.subscribe(() => {
|
|
507
413
|
this.refreshStatus();
|
|
508
414
|
});
|
|
@@ -514,51 +420,39 @@ export class Humidifier {
|
|
|
514
420
|
// Convert to BLE Address
|
|
515
421
|
this.device.bleMac = this.device
|
|
516
422
|
.deviceId!.match(/.{1,2}/g)!
|
|
517
|
-
.join(
|
|
423
|
+
.join(':')
|
|
518
424
|
.toLowerCase();
|
|
519
|
-
this.debugLog(
|
|
520
|
-
`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
|
|
521
|
-
);
|
|
425
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
522
426
|
if (switchbot !== false) {
|
|
523
427
|
switchbot
|
|
524
|
-
.discover({ model:
|
|
428
|
+
.discover({ model: 'e', quick: true, id: this.device.bleMac })
|
|
525
429
|
.then((device_list) => {
|
|
526
|
-
this.infoLog(
|
|
527
|
-
|
|
528
|
-
);
|
|
529
|
-
return device_list[0].percentage(
|
|
530
|
-
this.RelativeHumidityHumidifierThreshold,
|
|
531
|
-
);
|
|
430
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
|
|
431
|
+
return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
532
432
|
})
|
|
533
433
|
.then(() => {
|
|
534
434
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
|
|
535
435
|
})
|
|
536
436
|
.catch(async (e: any) => {
|
|
537
|
-
this.errorLog(
|
|
538
|
-
|
|
539
|
-
);
|
|
540
|
-
if (this.deviceLogging.includes("debug")) {
|
|
437
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
438
|
+
if (this.deviceLogging === 'debug') {
|
|
541
439
|
this.errorLog(
|
|
542
|
-
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
|
|
543
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
440
|
+
`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
544
441
|
);
|
|
545
442
|
}
|
|
443
|
+
if (this.platform.debugMode) {
|
|
444
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
445
|
+
}
|
|
546
446
|
if (this.platform.config.credentials?.openToken) {
|
|
547
|
-
this.warnLog(
|
|
548
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
549
|
-
);
|
|
447
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
550
448
|
await this.openAPIpushChanges();
|
|
551
449
|
}
|
|
552
450
|
this.apiError(e);
|
|
553
451
|
});
|
|
554
452
|
} else {
|
|
555
|
-
this.errorLog(
|
|
556
|
-
`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
|
|
557
|
-
);
|
|
453
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
558
454
|
if (this.platform.config.credentials?.openToken) {
|
|
559
|
-
this.warnLog(
|
|
560
|
-
`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
|
|
561
|
-
);
|
|
455
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
562
456
|
await this.openAPIpushChanges();
|
|
563
457
|
}
|
|
564
458
|
}
|
|
@@ -566,24 +460,18 @@ export class Humidifier {
|
|
|
566
460
|
|
|
567
461
|
private async openAPIpushChanges() {
|
|
568
462
|
if (this.platform.config.credentials?.openToken) {
|
|
569
|
-
this.debugLog(
|
|
570
|
-
`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`,
|
|
571
|
-
);
|
|
463
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
572
464
|
if (
|
|
573
|
-
this.TargetHumidifierDehumidifierState ===
|
|
574
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState
|
|
575
|
-
.HUMIDIFIER &&
|
|
465
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
576
466
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
577
467
|
) {
|
|
578
468
|
try {
|
|
579
|
-
this.debugLog(
|
|
580
|
-
`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`,
|
|
581
|
-
);
|
|
469
|
+
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
582
470
|
const payload = {
|
|
583
|
-
commandType:
|
|
584
|
-
command:
|
|
471
|
+
commandType: 'command',
|
|
472
|
+
command: 'setMode',
|
|
585
473
|
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
586
|
-
} as
|
|
474
|
+
} as payload;
|
|
587
475
|
|
|
588
476
|
this.infoLog(
|
|
589
477
|
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -591,32 +479,24 @@ export class Humidifier {
|
|
|
591
479
|
);
|
|
592
480
|
|
|
593
481
|
// Make the API request
|
|
594
|
-
const push: any = await this.platform.axios.post(
|
|
595
|
-
|
|
596
|
-
payload,
|
|
597
|
-
);
|
|
598
|
-
this.debugLog(
|
|
599
|
-
`Humidifier: ${
|
|
600
|
-
this.accessory.displayName
|
|
601
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
602
|
-
);
|
|
482
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
483
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
603
484
|
this.statusCode(push);
|
|
604
485
|
} catch (e: any) {
|
|
605
|
-
this.errorLog(
|
|
606
|
-
|
|
607
|
-
);
|
|
608
|
-
if (this.deviceLogging.includes("debug")) {
|
|
486
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
487
|
+
if (this.deviceLogging === 'debug') {
|
|
609
488
|
this.errorLog(
|
|
610
489
|
`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
611
490
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
612
491
|
);
|
|
613
492
|
}
|
|
493
|
+
if (this.platform.debugMode) {
|
|
494
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
495
|
+
}
|
|
614
496
|
this.apiError(e);
|
|
615
497
|
}
|
|
616
498
|
} else if (
|
|
617
|
-
this.TargetHumidifierDehumidifierState ===
|
|
618
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState
|
|
619
|
-
.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
499
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
620
500
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
621
501
|
) {
|
|
622
502
|
await this.pushAutoChanges();
|
|
@@ -632,17 +512,15 @@ export class Humidifier {
|
|
|
632
512
|
async pushAutoChanges() {
|
|
633
513
|
try {
|
|
634
514
|
if (
|
|
635
|
-
this.TargetHumidifierDehumidifierState ===
|
|
636
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState
|
|
637
|
-
.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
515
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
638
516
|
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
639
517
|
) {
|
|
640
|
-
this.debugLog(
|
|
518
|
+
this.debugLog('Pushing Auto!');
|
|
641
519
|
const payload = {
|
|
642
|
-
commandType:
|
|
643
|
-
command:
|
|
644
|
-
parameter:
|
|
645
|
-
} as
|
|
520
|
+
commandType: 'command',
|
|
521
|
+
command: 'setMode',
|
|
522
|
+
parameter: 'auto',
|
|
523
|
+
} as payload;
|
|
646
524
|
|
|
647
525
|
this.infoLog(
|
|
648
526
|
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -650,27 +528,21 @@ export class Humidifier {
|
|
|
650
528
|
);
|
|
651
529
|
|
|
652
530
|
// Make the API request
|
|
653
|
-
const push: any = await this.platform.axios.post(
|
|
654
|
-
|
|
655
|
-
payload,
|
|
656
|
-
);
|
|
657
|
-
this.debugLog(
|
|
658
|
-
`Humidifier: ${
|
|
659
|
-
this.accessory.displayName
|
|
660
|
-
} pushAutoChanges: ${JSON.stringify(push.data)}`,
|
|
661
|
-
);
|
|
531
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
532
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
|
|
662
533
|
this.statusCode(push);
|
|
663
534
|
}
|
|
664
535
|
} catch (e: any) {
|
|
665
|
-
this.errorLog(
|
|
666
|
-
|
|
667
|
-
);
|
|
668
|
-
if (this.deviceLogging.includes("debug")) {
|
|
536
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
|
|
537
|
+
if (this.deviceLogging === 'debug') {
|
|
669
538
|
this.errorLog(
|
|
670
539
|
`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
|
|
671
540
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
672
541
|
);
|
|
673
542
|
}
|
|
543
|
+
if (this.platform.debugMode) {
|
|
544
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
545
|
+
}
|
|
674
546
|
this.apiError(e);
|
|
675
547
|
}
|
|
676
548
|
}
|
|
@@ -681,12 +553,12 @@ export class Humidifier {
|
|
|
681
553
|
async pushActiveChanges() {
|
|
682
554
|
try {
|
|
683
555
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
684
|
-
this.debugLog(
|
|
556
|
+
this.debugLog('Pushing Off!');
|
|
685
557
|
const payload = {
|
|
686
|
-
commandType:
|
|
687
|
-
command:
|
|
688
|
-
parameter:
|
|
689
|
-
} as
|
|
558
|
+
commandType: 'command',
|
|
559
|
+
command: 'turnOff',
|
|
560
|
+
parameter: 'default',
|
|
561
|
+
} as payload;
|
|
690
562
|
|
|
691
563
|
this.infoLog(
|
|
692
564
|
`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -694,27 +566,21 @@ export class Humidifier {
|
|
|
694
566
|
);
|
|
695
567
|
|
|
696
568
|
// Make the API request
|
|
697
|
-
const push: any = await this.platform.axios.post(
|
|
698
|
-
|
|
699
|
-
payload,
|
|
700
|
-
);
|
|
701
|
-
this.debugLog(
|
|
702
|
-
`Humidifier: ${
|
|
703
|
-
this.accessory.displayName
|
|
704
|
-
} pushActiveChanges: ${JSON.stringify(push.data)}`,
|
|
705
|
-
);
|
|
569
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
570
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
|
|
706
571
|
this.statusCode(push);
|
|
707
572
|
}
|
|
708
573
|
} catch (e: any) {
|
|
709
|
-
this.errorLog(
|
|
710
|
-
|
|
711
|
-
);
|
|
712
|
-
if (this.deviceLogging.includes("debug")) {
|
|
574
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
|
|
575
|
+
if (this.deviceLogging === 'debug') {
|
|
713
576
|
this.errorLog(
|
|
714
577
|
`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
|
|
715
578
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
716
579
|
);
|
|
717
580
|
}
|
|
581
|
+
if (this.platform.debugMode) {
|
|
582
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
583
|
+
}
|
|
718
584
|
this.apiError(e);
|
|
719
585
|
}
|
|
720
586
|
}
|
|
@@ -724,85 +590,49 @@ export class Humidifier {
|
|
|
724
590
|
*/
|
|
725
591
|
updateHomeKitCharacteristics() {
|
|
726
592
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
727
|
-
this.debugLog(
|
|
728
|
-
`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
729
|
-
);
|
|
593
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
730
594
|
} else {
|
|
731
|
-
this.service.updateCharacteristic(
|
|
732
|
-
|
|
733
|
-
this.CurrentRelativeHumidity,
|
|
734
|
-
);
|
|
735
|
-
this.debugLog(
|
|
736
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
737
|
-
` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
738
|
-
);
|
|
595
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
596
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
739
597
|
}
|
|
740
598
|
if (!this.device.ble) {
|
|
741
599
|
if (this.WaterLevel === undefined) {
|
|
742
|
-
this.debugLog(
|
|
743
|
-
`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
|
|
744
|
-
);
|
|
600
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
745
601
|
} else {
|
|
746
|
-
this.service.updateCharacteristic(
|
|
747
|
-
|
|
748
|
-
this.WaterLevel,
|
|
749
|
-
);
|
|
750
|
-
this.debugLog(
|
|
751
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`,
|
|
752
|
-
);
|
|
602
|
+
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
|
|
603
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
753
604
|
}
|
|
754
605
|
}
|
|
755
606
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
756
|
-
this.debugLog(
|
|
757
|
-
`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
758
|
-
);
|
|
607
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
759
608
|
} else {
|
|
760
|
-
this.service.updateCharacteristic(
|
|
761
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
762
|
-
this.CurrentHumidifierDehumidifierState,
|
|
763
|
-
);
|
|
609
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
764
610
|
this.debugLog(
|
|
765
611
|
`Humidifier: ${this.accessory.displayName}` +
|
|
766
612
|
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
767
613
|
);
|
|
768
614
|
}
|
|
769
615
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
770
|
-
this.debugLog(
|
|
771
|
-
`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
772
|
-
);
|
|
616
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
773
617
|
} else {
|
|
774
|
-
this.service.updateCharacteristic(
|
|
775
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
776
|
-
this.TargetHumidifierDehumidifierState,
|
|
777
|
-
);
|
|
618
|
+
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
778
619
|
this.debugLog(
|
|
779
620
|
`Humidifier: ${this.accessory.displayName}` +
|
|
780
621
|
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
781
622
|
);
|
|
782
623
|
}
|
|
783
624
|
if (this.Active === undefined) {
|
|
784
|
-
this.debugLog(
|
|
785
|
-
`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
786
|
-
);
|
|
625
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
787
626
|
} else {
|
|
788
|
-
this.service.updateCharacteristic(
|
|
789
|
-
|
|
790
|
-
this.Active,
|
|
791
|
-
);
|
|
792
|
-
this.debugLog(
|
|
793
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
794
|
-
);
|
|
627
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
628
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
795
629
|
}
|
|
796
630
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
797
631
|
this.debugLog(
|
|
798
|
-
`Humidifier: ${this.accessory.displayName}` +
|
|
799
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
632
|
+
`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
800
633
|
);
|
|
801
634
|
} else {
|
|
802
|
-
this.service.updateCharacteristic(
|
|
803
|
-
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
804
|
-
this.RelativeHumidityHumidifierThreshold,
|
|
805
|
-
);
|
|
635
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
806
636
|
this.debugLog(
|
|
807
637
|
`Humidifier: ${this.accessory.displayName}` +
|
|
808
638
|
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
@@ -810,81 +640,46 @@ export class Humidifier {
|
|
|
810
640
|
}
|
|
811
641
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
812
642
|
if (this.CurrentTemperature === undefined) {
|
|
813
|
-
this.debugLog(
|
|
814
|
-
`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
|
|
815
|
-
);
|
|
643
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
816
644
|
} else {
|
|
817
|
-
this.temperatureservice?.updateCharacteristic(
|
|
818
|
-
|
|
819
|
-
this.CurrentTemperature,
|
|
820
|
-
);
|
|
821
|
-
this.debugLog(
|
|
822
|
-
`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`,
|
|
823
|
-
);
|
|
645
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
646
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
824
647
|
}
|
|
825
648
|
}
|
|
826
649
|
}
|
|
827
650
|
|
|
828
|
-
public apiError(e: any)
|
|
829
|
-
this.service.updateCharacteristic(
|
|
830
|
-
this.platform.Characteristic.CurrentRelativeHumidity,
|
|
831
|
-
e,
|
|
832
|
-
);
|
|
651
|
+
public apiError(e: any) {
|
|
652
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
|
|
833
653
|
if (!this.device.ble) {
|
|
834
|
-
this.service.updateCharacteristic(
|
|
835
|
-
this.platform.Characteristic.WaterLevel,
|
|
836
|
-
e,
|
|
837
|
-
);
|
|
654
|
+
this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
|
|
838
655
|
}
|
|
839
|
-
this.service.updateCharacteristic(
|
|
840
|
-
|
|
841
|
-
e,
|
|
842
|
-
);
|
|
843
|
-
this.service.updateCharacteristic(
|
|
844
|
-
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
845
|
-
e,
|
|
846
|
-
);
|
|
656
|
+
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
657
|
+
this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
847
658
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
848
|
-
this.service.updateCharacteristic(
|
|
849
|
-
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
850
|
-
e,
|
|
851
|
-
);
|
|
659
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
852
660
|
if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
|
|
853
|
-
this.temperatureservice?.updateCharacteristic(
|
|
854
|
-
this.platform.Characteristic.CurrentTemperature,
|
|
855
|
-
e,
|
|
856
|
-
);
|
|
661
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
857
662
|
}
|
|
858
663
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
859
664
|
}
|
|
860
665
|
|
|
861
|
-
private statusCode(push:
|
|
666
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
862
667
|
switch (push.data.statusCode) {
|
|
863
668
|
case 151:
|
|
864
|
-
this.errorLog(
|
|
865
|
-
`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
866
|
-
);
|
|
669
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
867
670
|
break;
|
|
868
671
|
case 152:
|
|
869
|
-
this.errorLog(
|
|
870
|
-
`Humidifier: ${this.accessory.displayName} Device not found.`,
|
|
871
|
-
);
|
|
672
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
|
|
872
673
|
break;
|
|
873
674
|
case 160:
|
|
874
|
-
this.errorLog(
|
|
875
|
-
`Humidifier: ${this.accessory.displayName} Command is not supported.`,
|
|
876
|
-
);
|
|
675
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
|
|
877
676
|
break;
|
|
878
677
|
case 161:
|
|
879
|
-
this.errorLog(
|
|
880
|
-
`Humidifier: ${this.accessory.displayName} Device is offline.`,
|
|
881
|
-
);
|
|
678
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
|
|
882
679
|
this.offlineOff();
|
|
883
680
|
break;
|
|
884
681
|
case 171:
|
|
885
|
-
this.errorLog(
|
|
886
|
-
`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
887
|
-
);
|
|
682
|
+
this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
888
683
|
this.offlineOff();
|
|
889
684
|
break;
|
|
890
685
|
case 190:
|
|
@@ -894,35 +689,25 @@ export class Humidifier {
|
|
|
894
689
|
);
|
|
895
690
|
break;
|
|
896
691
|
case 100:
|
|
897
|
-
this.debugLog(
|
|
898
|
-
`Humidifier: ${this.accessory.displayName} Command successfully sent.`,
|
|
899
|
-
);
|
|
692
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
|
|
900
693
|
break;
|
|
901
694
|
default:
|
|
902
|
-
this.debugLog(
|
|
903
|
-
`Humidifier: ${this.accessory.displayName} Unknown statusCode.`,
|
|
904
|
-
);
|
|
695
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
|
|
905
696
|
}
|
|
906
697
|
}
|
|
907
698
|
|
|
908
699
|
private offlineOff() {
|
|
909
700
|
if (this.device.offline) {
|
|
910
701
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
911
|
-
this.service
|
|
912
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
913
|
-
.updateValue(this.Active);
|
|
702
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
|
|
914
703
|
}
|
|
915
704
|
}
|
|
916
705
|
|
|
917
706
|
/**
|
|
918
707
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
919
708
|
*/
|
|
920
|
-
private handleTargetHumidifierDehumidifierStateSet(
|
|
921
|
-
|
|
922
|
-
) {
|
|
923
|
-
this.debugLog(
|
|
924
|
-
`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`,
|
|
925
|
-
);
|
|
709
|
+
private handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue) {
|
|
710
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
|
|
926
711
|
|
|
927
712
|
this.TargetHumidifierDehumidifierState = value;
|
|
928
713
|
this.doHumidifierUpdate.next();
|
|
@@ -931,7 +716,7 @@ export class Humidifier {
|
|
|
931
716
|
/**
|
|
932
717
|
* Handle requests to set the "Active" characteristic
|
|
933
718
|
*/
|
|
934
|
-
private handleActiveSet(value:
|
|
719
|
+
private handleActiveSet(value: CharacteristicValue) {
|
|
935
720
|
this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
|
|
936
721
|
this.Active = value;
|
|
937
722
|
this.doHumidifierUpdate.next();
|
|
@@ -940,105 +725,76 @@ export class Humidifier {
|
|
|
940
725
|
/**
|
|
941
726
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
942
727
|
*/
|
|
943
|
-
private handleRelativeHumidityHumidifierThresholdSet(
|
|
944
|
-
|
|
945
|
-
) {
|
|
946
|
-
this.debugLog(
|
|
947
|
-
`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`,
|
|
948
|
-
);
|
|
728
|
+
private handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue) {
|
|
729
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
|
|
949
730
|
|
|
950
731
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
951
732
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
952
733
|
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
953
|
-
this.CurrentHumidifierDehumidifierState =
|
|
954
|
-
this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
734
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
955
735
|
}
|
|
956
736
|
this.doHumidifierUpdate.next();
|
|
957
737
|
}
|
|
958
738
|
|
|
959
|
-
config(device:
|
|
739
|
+
config(device: device & devicesConfig) {
|
|
960
740
|
let config = {};
|
|
961
741
|
if (device.humidifier) {
|
|
962
742
|
config = device.humidifier;
|
|
963
743
|
}
|
|
964
744
|
if (device.ble !== undefined) {
|
|
965
|
-
config[
|
|
745
|
+
config['ble'] = device.ble;
|
|
966
746
|
}
|
|
967
747
|
if (device.logging !== undefined) {
|
|
968
|
-
config[
|
|
748
|
+
config['logging'] = device.logging;
|
|
969
749
|
}
|
|
970
750
|
if (device.refreshRate !== undefined) {
|
|
971
|
-
config[
|
|
751
|
+
config['refreshRate'] = device.refreshRate;
|
|
972
752
|
}
|
|
973
753
|
if (device.scanDuration !== undefined) {
|
|
974
|
-
config[
|
|
754
|
+
config['scanDuration'] = device.scanDuration;
|
|
975
755
|
}
|
|
976
756
|
if (Object.entries(config).length !== 0) {
|
|
977
|
-
this.warnLog(
|
|
978
|
-
`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
979
|
-
config,
|
|
980
|
-
)}`,
|
|
981
|
-
);
|
|
757
|
+
this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
982
758
|
}
|
|
983
759
|
}
|
|
984
760
|
|
|
985
|
-
refreshRate(device:
|
|
761
|
+
refreshRate(device: device & devicesConfig) {
|
|
986
762
|
if (device.refreshRate) {
|
|
987
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
988
|
-
|
|
989
|
-
this.debugLog(
|
|
990
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
991
|
-
);
|
|
763
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
764
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
992
765
|
} else if (this.platform.config.options!.refreshRate) {
|
|
993
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
994
|
-
|
|
995
|
-
this.debugLog(
|
|
996
|
-
`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
997
|
-
);
|
|
766
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
767
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
998
768
|
}
|
|
999
769
|
}
|
|
1000
770
|
|
|
1001
|
-
scan(device:
|
|
771
|
+
scan(device: device & devicesConfig) {
|
|
1002
772
|
if (device.scanDuration) {
|
|
1003
|
-
this.scanDuration = this.accessory.context.scanDuration =
|
|
1004
|
-
device.scanDuration;
|
|
773
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
1005
774
|
if (device.ble) {
|
|
1006
|
-
this.debugLog(
|
|
1007
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
|
|
1008
|
-
);
|
|
775
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
1009
776
|
}
|
|
1010
777
|
} else {
|
|
1011
778
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
1012
779
|
if (this.device.ble) {
|
|
1013
|
-
this.debugLog(
|
|
1014
|
-
`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
|
|
1015
|
-
);
|
|
780
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
1016
781
|
}
|
|
1017
782
|
}
|
|
1018
783
|
}
|
|
1019
784
|
|
|
1020
|
-
logs(device:
|
|
785
|
+
logs(device: device & devicesConfig) {
|
|
1021
786
|
if (this.platform.debugMode) {
|
|
1022
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1023
|
-
this.debugLog(
|
|
1024
|
-
`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
1025
|
-
);
|
|
787
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
788
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1026
789
|
} else if (device.logging) {
|
|
1027
790
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1028
|
-
this.debugLog(
|
|
1029
|
-
`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
1030
|
-
);
|
|
791
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1031
792
|
} else if (this.platform.config.options?.logging) {
|
|
1032
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1033
|
-
|
|
1034
|
-
this.debugLog(
|
|
1035
|
-
`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
1036
|
-
);
|
|
793
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
794
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1037
795
|
} else {
|
|
1038
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
1039
|
-
this.debugLog(
|
|
1040
|
-
`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
1041
|
-
);
|
|
796
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
797
|
+
this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1042
798
|
}
|
|
1043
799
|
}
|
|
1044
800
|
|
|
@@ -1054,28 +810,28 @@ export class Humidifier {
|
|
|
1054
810
|
/**
|
|
1055
811
|
* Logging for Device
|
|
1056
812
|
*/
|
|
1057
|
-
infoLog(...log: any[])
|
|
813
|
+
infoLog(...log: any[]) {
|
|
1058
814
|
if (this.enablingDeviceLogging()) {
|
|
1059
815
|
this.platform.log.info(String(...log));
|
|
1060
816
|
}
|
|
1061
817
|
}
|
|
1062
818
|
|
|
1063
|
-
warnLog(...log: any[])
|
|
819
|
+
warnLog(...log: any[]) {
|
|
1064
820
|
if (this.enablingDeviceLogging()) {
|
|
1065
821
|
this.platform.log.warn(String(...log));
|
|
1066
822
|
}
|
|
1067
823
|
}
|
|
1068
824
|
|
|
1069
|
-
errorLog(...log: any[])
|
|
825
|
+
errorLog(...log: any[]) {
|
|
1070
826
|
if (this.enablingDeviceLogging()) {
|
|
1071
827
|
this.platform.log.error(String(...log));
|
|
1072
828
|
}
|
|
1073
829
|
}
|
|
1074
830
|
|
|
1075
|
-
debugLog(...log: any[])
|
|
831
|
+
debugLog(...log: any[]) {
|
|
1076
832
|
if (this.enablingDeviceLogging()) {
|
|
1077
|
-
if (this.deviceLogging ===
|
|
1078
|
-
this.platform.log.info(
|
|
833
|
+
if (this.deviceLogging === 'debug') {
|
|
834
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
1079
835
|
} else {
|
|
1080
836
|
this.platform.log.debug(String(...log));
|
|
1081
837
|
}
|
|
@@ -1083,8 +839,6 @@ export class Humidifier {
|
|
|
1083
839
|
}
|
|
1084
840
|
|
|
1085
841
|
enablingDeviceLogging(): boolean {
|
|
1086
|
-
return
|
|
1087
|
-
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
1088
|
-
);
|
|
842
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
1089
843
|
}
|
|
1090
844
|
}
|