@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
|
@@ -1,57 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
const operators_1 = require("rxjs/operators");
|
|
8
|
-
const settings_1 = require("../settings");
|
|
1
|
+
import { request } from 'undici';
|
|
2
|
+
import { sleep } from '../utils';
|
|
3
|
+
import { interval, Subject } from 'rxjs';
|
|
4
|
+
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
|
+
import { Devices } from '../settings';
|
|
9
6
|
/**
|
|
10
7
|
* Platform Accessory
|
|
11
8
|
* An instance of this class is created for each accessory your platform registers
|
|
12
9
|
* Each accessory may expose multiple services of different service types.
|
|
13
10
|
*/
|
|
14
|
-
class Humidifier {
|
|
11
|
+
export class Humidifier {
|
|
12
|
+
platform;
|
|
13
|
+
accessory;
|
|
14
|
+
device;
|
|
15
|
+
api;
|
|
16
|
+
log;
|
|
17
|
+
config;
|
|
18
|
+
hap;
|
|
19
|
+
// Services
|
|
20
|
+
humidifierService;
|
|
21
|
+
temperatureservice;
|
|
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;
|
|
49
|
+
// Updates
|
|
50
|
+
humidifierUpdateInProgress;
|
|
51
|
+
doHumidifierUpdate;
|
|
52
|
+
// Connection
|
|
53
|
+
OpenAPI;
|
|
54
|
+
BLE;
|
|
15
55
|
constructor(platform, accessory, device) {
|
|
16
56
|
this.platform = platform;
|
|
17
57
|
this.accessory = accessory;
|
|
18
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;
|
|
19
63
|
// Connection
|
|
20
64
|
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
21
65
|
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
22
66
|
// default placeholders
|
|
23
|
-
this.
|
|
67
|
+
this.deviceLogs(device);
|
|
24
68
|
this.scan(device);
|
|
25
69
|
this.refreshRate(device);
|
|
26
70
|
this.context();
|
|
27
|
-
this.
|
|
71
|
+
this.deviceConfig(device);
|
|
28
72
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
29
|
-
this.doHumidifierUpdate = new
|
|
73
|
+
this.doHumidifierUpdate = new Subject();
|
|
30
74
|
this.humidifierUpdateInProgress = false;
|
|
31
75
|
// Retrieve initial values and updateHomekit
|
|
32
76
|
this.refreshStatus();
|
|
33
77
|
// set accessory information
|
|
34
78
|
accessory
|
|
35
|
-
.getService(this.
|
|
36
|
-
.setCharacteristic(this.
|
|
37
|
-
.setCharacteristic(this.
|
|
38
|
-
.setCharacteristic(this.
|
|
39
|
-
.setCharacteristic(this.
|
|
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);
|
|
40
84
|
// get the service if it exists, otherwise create a new service
|
|
41
85
|
// you can create multiple services for each accessory
|
|
42
86
|
const humidifierService = `${accessory.displayName} Humidifier`;
|
|
43
|
-
(this.humidifierService = accessory.getService(this.
|
|
44
|
-
|| accessory.addService(this.
|
|
45
|
-
this.humidifierService.setCharacteristic(this.
|
|
46
|
-
if (!this.humidifierService.testCharacteristic(this.
|
|
47
|
-
this.humidifierService.addCharacteristic(this.
|
|
87
|
+
(this.humidifierService = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
88
|
+
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), humidifierService;
|
|
89
|
+
this.humidifierService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
90
|
+
if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
91
|
+
this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
48
92
|
}
|
|
49
93
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
50
94
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
51
95
|
// create handlers for required characteristics
|
|
52
|
-
this.humidifierService.setCharacteristic(this.
|
|
96
|
+
this.humidifierService.setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
53
97
|
this.humidifierService
|
|
54
|
-
.getCharacteristic(this.
|
|
98
|
+
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
55
99
|
.setProps({
|
|
56
100
|
validValueRanges: [0, 1],
|
|
57
101
|
minValue: 0,
|
|
@@ -59,9 +103,9 @@ class Humidifier {
|
|
|
59
103
|
validValues: [0, 1],
|
|
60
104
|
})
|
|
61
105
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
62
|
-
this.humidifierService.getCharacteristic(this.
|
|
106
|
+
this.humidifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
63
107
|
this.humidifierService
|
|
64
|
-
.getCharacteristic(this.
|
|
108
|
+
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
65
109
|
.setProps({
|
|
66
110
|
validValueRanges: [0, 100],
|
|
67
111
|
minValue: 0,
|
|
@@ -72,20 +116,20 @@ class Humidifier {
|
|
|
72
116
|
// Temperature Sensor Service
|
|
73
117
|
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
74
118
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
75
|
-
this.temperatureservice = this.accessory.getService(this.
|
|
119
|
+
this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
76
120
|
accessory.removeService(this.temperatureservice);
|
|
77
121
|
}
|
|
78
122
|
else if (!this.temperatureservice && !this.BLE) {
|
|
79
123
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
80
124
|
const temperatureservice = `${accessory.displayName} Temperature Sensor`;
|
|
81
|
-
(this.temperatureservice = this.accessory.getService(this.
|
|
82
|
-
|| this.accessory.addService(this.
|
|
83
|
-
this.temperatureservice.setCharacteristic(this.
|
|
84
|
-
if (!this.temperatureservice.testCharacteristic(this.
|
|
85
|
-
this.temperatureservice.addCharacteristic(this.
|
|
125
|
+
(this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
126
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureservice;
|
|
127
|
+
this.temperatureservice.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
128
|
+
if (!this.temperatureservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
129
|
+
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
86
130
|
}
|
|
87
131
|
this.temperatureservice
|
|
88
|
-
.getCharacteristic(this.
|
|
132
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
89
133
|
.setProps({
|
|
90
134
|
validValueRanges: [-273.15, 100],
|
|
91
135
|
minValue: -273.15,
|
|
@@ -102,8 +146,8 @@ class Humidifier {
|
|
|
102
146
|
// Retrieve initial values and updateHomekit
|
|
103
147
|
this.updateHomeKitCharacteristics();
|
|
104
148
|
// Start an update interval
|
|
105
|
-
|
|
106
|
-
.pipe(
|
|
149
|
+
interval(this.deviceRefreshRate * 1000)
|
|
150
|
+
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
107
151
|
.subscribe(() => {
|
|
108
152
|
this.refreshStatus();
|
|
109
153
|
});
|
|
@@ -134,9 +178,9 @@ class Humidifier {
|
|
|
134
178
|
// Watch for Humidifier change events
|
|
135
179
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
136
180
|
this.doHumidifierUpdate
|
|
137
|
-
.pipe(
|
|
181
|
+
.pipe(tap(() => {
|
|
138
182
|
this.humidifierUpdateInProgress = true;
|
|
139
|
-
}),
|
|
183
|
+
}), debounceTime(this.platform.config.options.pushRate * 1000))
|
|
140
184
|
.subscribe(async () => {
|
|
141
185
|
try {
|
|
142
186
|
await this.pushChanges();
|
|
@@ -174,10 +218,10 @@ class Humidifier {
|
|
|
174
218
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
175
219
|
// Active
|
|
176
220
|
if (this.onState) {
|
|
177
|
-
this.Active = this.
|
|
221
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
178
222
|
}
|
|
179
223
|
else {
|
|
180
|
-
this.Active = this.
|
|
224
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
181
225
|
}
|
|
182
226
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
183
227
|
}
|
|
@@ -194,12 +238,12 @@ class Humidifier {
|
|
|
194
238
|
// Target Humidifier Dehumidifier State
|
|
195
239
|
switch (this.OpenAPI_CurrentHumidifierDehumidifierState) {
|
|
196
240
|
case true:
|
|
197
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
198
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
241
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
242
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
199
243
|
this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
|
|
200
244
|
break;
|
|
201
245
|
default:
|
|
202
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
246
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
203
247
|
if (this.OpenAPI_RelativeHumidityHumidifierThreshold > 100) {
|
|
204
248
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
205
249
|
}
|
|
@@ -207,13 +251,13 @@ class Humidifier {
|
|
|
207
251
|
this.RelativeHumidityHumidifierThreshold = this.OpenAPI_RelativeHumidityHumidifierThreshold;
|
|
208
252
|
}
|
|
209
253
|
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
210
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
254
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
211
255
|
}
|
|
212
|
-
else if (this.Active === this.
|
|
213
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
256
|
+
else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
257
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
214
258
|
}
|
|
215
259
|
else {
|
|
216
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
260
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
217
261
|
}
|
|
218
262
|
}
|
|
219
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
@@ -223,10 +267,10 @@ class Humidifier {
|
|
|
223
267
|
// Active
|
|
224
268
|
switch (this.OpenAPI_Active) {
|
|
225
269
|
case 'on':
|
|
226
|
-
this.Active = this.
|
|
270
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
227
271
|
break;
|
|
228
272
|
default:
|
|
229
|
-
this.Active = this.
|
|
273
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
230
274
|
}
|
|
231
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
232
276
|
// Water Level
|
|
@@ -299,7 +343,7 @@ class Humidifier {
|
|
|
299
343
|
}
|
|
300
344
|
};
|
|
301
345
|
// Wait
|
|
302
|
-
return await
|
|
346
|
+
return await sleep(this.scanDuration * 1000);
|
|
303
347
|
})
|
|
304
348
|
.then(async () => {
|
|
305
349
|
// Stop to monitor
|
|
@@ -319,7 +363,7 @@ class Humidifier {
|
|
|
319
363
|
async openAPIRefreshStatus() {
|
|
320
364
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
321
365
|
try {
|
|
322
|
-
const { body, statusCode, headers } = await
|
|
366
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
323
367
|
headers: this.platform.generateHeaders(),
|
|
324
368
|
});
|
|
325
369
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
@@ -369,8 +413,8 @@ class Humidifier {
|
|
|
369
413
|
await this.offlineOff();
|
|
370
414
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
371
415
|
}
|
|
372
|
-
|
|
373
|
-
.pipe(
|
|
416
|
+
interval(5000)
|
|
417
|
+
.pipe(take(1))
|
|
374
418
|
.subscribe(async () => {
|
|
375
419
|
await this.refreshStatus();
|
|
376
420
|
});
|
|
@@ -406,8 +450,8 @@ class Humidifier {
|
|
|
406
450
|
}
|
|
407
451
|
async openAPIpushChanges() {
|
|
408
452
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
409
|
-
if (this.TargetHumidifierDehumidifierState === this.
|
|
410
|
-
this.Active === this.
|
|
453
|
+
if (this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
454
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
411
455
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
412
456
|
const bodyChange = JSON.stringify({
|
|
413
457
|
command: 'setMode',
|
|
@@ -416,7 +460,7 @@ class Humidifier {
|
|
|
416
460
|
});
|
|
417
461
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
418
462
|
try {
|
|
419
|
-
const { body, statusCode, headers } = await
|
|
463
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
420
464
|
body: bodyChange,
|
|
421
465
|
method: 'POST',
|
|
422
466
|
headers: this.platform.generateHeaders(),
|
|
@@ -443,8 +487,8 @@ class Humidifier {
|
|
|
443
487
|
` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
444
488
|
}
|
|
445
489
|
}
|
|
446
|
-
else if (this.TargetHumidifierDehumidifierState === this.
|
|
447
|
-
this.Active === this.
|
|
490
|
+
else if (this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
491
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
448
492
|
await this.pushAutoChanges();
|
|
449
493
|
}
|
|
450
494
|
else {
|
|
@@ -456,8 +500,8 @@ class Humidifier {
|
|
|
456
500
|
*/
|
|
457
501
|
async pushAutoChanges() {
|
|
458
502
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
459
|
-
if (this.TargetHumidifierDehumidifierState === this.
|
|
460
|
-
this.Active === this.
|
|
503
|
+
if (this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
504
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
461
505
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
462
506
|
const bodyChange = JSON.stringify({
|
|
463
507
|
command: 'setMode',
|
|
@@ -466,7 +510,7 @@ class Humidifier {
|
|
|
466
510
|
});
|
|
467
511
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
468
512
|
try {
|
|
469
|
-
const { body, statusCode, headers } = await
|
|
513
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
470
514
|
body: bodyChange,
|
|
471
515
|
method: 'POST',
|
|
472
516
|
headers: this.platform.generateHeaders(),
|
|
@@ -503,7 +547,7 @@ class Humidifier {
|
|
|
503
547
|
*/
|
|
504
548
|
async pushActiveChanges() {
|
|
505
549
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
506
|
-
if (this.Active === this.
|
|
550
|
+
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
507
551
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
508
552
|
const bodyChange = JSON.stringify({
|
|
509
553
|
command: 'turnOff',
|
|
@@ -512,7 +556,7 @@ class Humidifier {
|
|
|
512
556
|
});
|
|
513
557
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
514
558
|
try {
|
|
515
|
-
const { body, statusCode, headers } = await
|
|
559
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
516
560
|
body: bodyChange,
|
|
517
561
|
method: 'POST',
|
|
518
562
|
headers: this.platform.generateHeaders(),
|
|
@@ -560,7 +604,7 @@ class Humidifier {
|
|
|
560
604
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
561
605
|
*/
|
|
562
606
|
async TargetHumidifierDehumidifierStateSet(value) {
|
|
563
|
-
if (this.Active === this.
|
|
607
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
564
608
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
565
609
|
}
|
|
566
610
|
else {
|
|
@@ -573,16 +617,16 @@ class Humidifier {
|
|
|
573
617
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
574
618
|
*/
|
|
575
619
|
async RelativeHumidityHumidifierThresholdSet(value) {
|
|
576
|
-
if (this.Active === this.
|
|
620
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
577
621
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
578
622
|
}
|
|
579
623
|
else {
|
|
580
624
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
581
625
|
}
|
|
582
626
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
583
|
-
if (this.Active === this.
|
|
584
|
-
this.Active = this.
|
|
585
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
627
|
+
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
628
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
629
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
586
630
|
}
|
|
587
631
|
this.doHumidifierUpdate.next();
|
|
588
632
|
}
|
|
@@ -594,7 +638,7 @@ class Humidifier {
|
|
|
594
638
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
595
639
|
}
|
|
596
640
|
else {
|
|
597
|
-
this.humidifierService.updateCharacteristic(this.
|
|
641
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
598
642
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
599
643
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
600
644
|
}
|
|
@@ -603,7 +647,7 @@ class Humidifier {
|
|
|
603
647
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
604
648
|
}
|
|
605
649
|
else {
|
|
606
|
-
this.humidifierService.updateCharacteristic(this.
|
|
650
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.WaterLevel);
|
|
607
651
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
608
652
|
this.accessory.context.WaterLevel = this.WaterLevel;
|
|
609
653
|
}
|
|
@@ -613,7 +657,7 @@ class Humidifier {
|
|
|
613
657
|
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
614
658
|
}
|
|
615
659
|
else {
|
|
616
|
-
this.humidifierService.updateCharacteristic(this.
|
|
660
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
|
|
617
661
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
618
662
|
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
619
663
|
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
@@ -622,7 +666,7 @@ class Humidifier {
|
|
|
622
666
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
623
667
|
}
|
|
624
668
|
else {
|
|
625
|
-
this.humidifierService.updateCharacteristic(this.
|
|
669
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
|
|
626
670
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
627
671
|
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
628
672
|
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
@@ -631,7 +675,7 @@ class Humidifier {
|
|
|
631
675
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
632
676
|
}
|
|
633
677
|
else {
|
|
634
|
-
this.humidifierService.updateCharacteristic(this.
|
|
678
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
635
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
636
680
|
this.accessory.context.Active = this.Active;
|
|
637
681
|
}
|
|
@@ -640,7 +684,7 @@ class Humidifier {
|
|
|
640
684
|
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
641
685
|
}
|
|
642
686
|
else {
|
|
643
|
-
this.humidifierService.updateCharacteristic(this.
|
|
687
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
|
|
644
688
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
645
689
|
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
646
690
|
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
@@ -650,7 +694,7 @@ class Humidifier {
|
|
|
650
694
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
651
695
|
}
|
|
652
696
|
else {
|
|
653
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
697
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
654
698
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
655
699
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
656
700
|
}
|
|
@@ -677,7 +721,7 @@ class Humidifier {
|
|
|
677
721
|
switchbot.onadvertisement = (ad) => {
|
|
678
722
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
679
723
|
};
|
|
680
|
-
await
|
|
724
|
+
await sleep(10000);
|
|
681
725
|
// Stop to monitor
|
|
682
726
|
await switchbot.stopScan();
|
|
683
727
|
})();
|
|
@@ -765,21 +809,21 @@ class Humidifier {
|
|
|
765
809
|
}
|
|
766
810
|
}
|
|
767
811
|
async apiError(e) {
|
|
768
|
-
this.humidifierService.updateCharacteristic(this.
|
|
812
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
769
813
|
if (!this.BLE) {
|
|
770
|
-
this.humidifierService.updateCharacteristic(this.
|
|
814
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
771
815
|
}
|
|
772
|
-
this.humidifierService.updateCharacteristic(this.
|
|
773
|
-
this.humidifierService.updateCharacteristic(this.
|
|
774
|
-
this.humidifierService.updateCharacteristic(this.
|
|
775
|
-
this.humidifierService.updateCharacteristic(this.
|
|
816
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
817
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
818
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
819
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
776
820
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
777
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
821
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
778
822
|
}
|
|
779
823
|
}
|
|
780
824
|
async context() {
|
|
781
825
|
if (this.Active === undefined) {
|
|
782
|
-
this.Active = this.
|
|
826
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
783
827
|
}
|
|
784
828
|
else {
|
|
785
829
|
this.Active = this.accessory.context.Active;
|
|
@@ -797,19 +841,19 @@ class Humidifier {
|
|
|
797
841
|
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
798
842
|
}
|
|
799
843
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
800
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
844
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
801
845
|
}
|
|
802
846
|
else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
803
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
847
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
804
848
|
}
|
|
805
849
|
else {
|
|
806
850
|
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
807
851
|
}
|
|
808
852
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
809
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
853
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
810
854
|
}
|
|
811
855
|
else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
|
|
812
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
856
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
813
857
|
}
|
|
814
858
|
else {
|
|
815
859
|
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
@@ -841,7 +885,7 @@ class Humidifier {
|
|
|
841
885
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
842
886
|
}
|
|
843
887
|
}
|
|
844
|
-
async
|
|
888
|
+
async deviceConfig(device) {
|
|
845
889
|
let config = {};
|
|
846
890
|
if (device.humidifier) {
|
|
847
891
|
config = device.humidifier;
|
|
@@ -868,7 +912,7 @@ class Humidifier {
|
|
|
868
912
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
869
913
|
}
|
|
870
914
|
}
|
|
871
|
-
async
|
|
915
|
+
async deviceLogs(device) {
|
|
872
916
|
if (this.platform.debugMode) {
|
|
873
917
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
874
918
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -932,5 +976,4 @@ class Humidifier {
|
|
|
932
976
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
933
977
|
}
|
|
934
978
|
}
|
|
935
|
-
exports.Humidifier = Humidifier;
|
|
936
979
|
//# sourceMappingURL=humidifier.js.map
|