@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
package/src/device/hub.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { connectAsync } from 'async-mqtt';
|
|
2
|
-
import { CharacteristicValue, PlatformAccessory, Service, Units } from 'homebridge';
|
|
2
|
+
import { CharacteristicValue, PlatformAccessory, Service, Units, API, Logging, HAP } from 'homebridge';
|
|
3
3
|
import { MqttClient } from 'mqtt';
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
6
|
import { request } from 'undici';
|
|
7
7
|
import { SwitchBotPlatform } from '../platform';
|
|
8
|
-
import { Devices, device, deviceStatus, devicesConfig } from '../settings';
|
|
8
|
+
import { Devices, device, deviceStatus, devicesConfig, SwitchBotPlatformConfig } from '../settings';
|
|
9
9
|
|
|
10
10
|
export class Hub {
|
|
11
|
+
public readonly api: API;
|
|
12
|
+
public readonly log: Logging;
|
|
13
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
14
|
+
protected readonly hap: HAP;
|
|
11
15
|
// Services
|
|
12
16
|
lightSensorService?: Service;
|
|
13
17
|
humidityService?: Service;
|
|
@@ -44,21 +48,28 @@ export class Hub {
|
|
|
44
48
|
deviceRefreshRate!: number;
|
|
45
49
|
|
|
46
50
|
// Connection
|
|
47
|
-
private readonly
|
|
48
|
-
private readonly
|
|
51
|
+
private readonly OpenAPI: boolean;
|
|
52
|
+
private readonly BLE: boolean;
|
|
49
53
|
|
|
50
54
|
constructor(
|
|
51
55
|
private readonly platform: SwitchBotPlatform,
|
|
52
56
|
private accessory: PlatformAccessory,
|
|
53
57
|
public device: device & devicesConfig,
|
|
54
58
|
) {
|
|
59
|
+
this.api = this.platform.api;
|
|
60
|
+
this.log = this.platform.log;
|
|
61
|
+
this.config = this.platform.config;
|
|
62
|
+
this.hap = this.api.hap;
|
|
63
|
+
// Connection
|
|
64
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
65
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
55
66
|
// default placeholders
|
|
56
|
-
this.
|
|
67
|
+
this.deviceLogs(device);
|
|
57
68
|
this.refreshRate(device);
|
|
58
69
|
this.context();
|
|
59
70
|
this.setupHistoryService(device);
|
|
60
71
|
this.setupMqtt(device);
|
|
61
|
-
this.
|
|
72
|
+
this.deviceConfig(device);
|
|
62
73
|
|
|
63
74
|
this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
|
|
64
75
|
this.CurrentTemperature = accessory.context.CurrentTemperature;
|
|
@@ -68,29 +79,29 @@ export class Hub {
|
|
|
68
79
|
|
|
69
80
|
// set accessory information
|
|
70
81
|
accessory
|
|
71
|
-
.getService(this.
|
|
72
|
-
.setCharacteristic(this.
|
|
73
|
-
.setCharacteristic(this.
|
|
74
|
-
.setCharacteristic(this.
|
|
75
|
-
.setCharacteristic(this.
|
|
82
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
83
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
84
|
+
.setCharacteristic(this.hap.Characteristic.Model, accessory.context.model)
|
|
85
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
86
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
76
87
|
|
|
77
88
|
// Temperature Sensor Service
|
|
78
89
|
if (device.hub?.hide_temperature) {
|
|
79
90
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
80
|
-
this.temperatureService = this.accessory.getService(this.
|
|
91
|
+
this.temperatureService = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
81
92
|
accessory.removeService(this.temperatureService!);
|
|
82
93
|
} else if (!this.temperatureService) {
|
|
83
94
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
84
95
|
const temperatureService = `${accessory.displayName} Temperature Sensor`;
|
|
85
|
-
(this.temperatureService = this.accessory.getService(this.
|
|
86
|
-
|| this.accessory.addService(this.
|
|
96
|
+
(this.temperatureService = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
97
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureService;
|
|
87
98
|
|
|
88
|
-
this.temperatureService.setCharacteristic(this.
|
|
89
|
-
if (!this.temperatureService.testCharacteristic(this.
|
|
90
|
-
this.temperatureService.addCharacteristic(this.
|
|
99
|
+
this.temperatureService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
100
|
+
if (!this.temperatureService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
101
|
+
this.temperatureService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
91
102
|
}
|
|
92
103
|
this.temperatureService
|
|
93
|
-
.getCharacteristic(this.
|
|
104
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
94
105
|
.setProps({
|
|
95
106
|
unit: Units['CELSIUS'],
|
|
96
107
|
validValueRanges: [-273.15, 100],
|
|
@@ -108,20 +119,20 @@ export class Hub {
|
|
|
108
119
|
// Humidity Sensor Service
|
|
109
120
|
if (device.hub?.hide_humidity) {
|
|
110
121
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
111
|
-
this.humidityService = this.accessory.getService(this.
|
|
122
|
+
this.humidityService = this.accessory.getService(this.hap.Service.HumiditySensor);
|
|
112
123
|
accessory.removeService(this.humidityService!);
|
|
113
124
|
} else if (!this.humidityService) {
|
|
114
125
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
115
126
|
const humidityService = `${accessory.displayName} Humidity Sensor`;
|
|
116
|
-
(this.humidityService = this.accessory.getService(this.
|
|
117
|
-
|| this.accessory.addService(this.
|
|
127
|
+
(this.humidityService = this.accessory.getService(this.hap.Service.HumiditySensor)
|
|
128
|
+
|| this.accessory.addService(this.hap.Service.HumiditySensor)), humidityService;
|
|
118
129
|
|
|
119
|
-
this.humidityService.setCharacteristic(this.
|
|
120
|
-
if (!this.humidityService.testCharacteristic(this.
|
|
121
|
-
this.humidityService.addCharacteristic(this.
|
|
130
|
+
this.humidityService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
131
|
+
if (!this.humidityService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
132
|
+
this.humidityService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
122
133
|
}
|
|
123
134
|
this.humidityService
|
|
124
|
-
.getCharacteristic(this.
|
|
135
|
+
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
125
136
|
.setProps({
|
|
126
137
|
minStep: 0.1,
|
|
127
138
|
})
|
|
@@ -135,16 +146,16 @@ export class Hub {
|
|
|
135
146
|
// Light Sensor Service
|
|
136
147
|
if (device.hub?.hide_lightsensor) {
|
|
137
148
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
|
|
138
|
-
this.lightSensorService = this.accessory.getService(this.
|
|
149
|
+
this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor);
|
|
139
150
|
accessory.removeService(this.lightSensorService!);
|
|
140
151
|
} else if (!this.lightSensorService) {
|
|
141
152
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
142
153
|
const lightSensorService = `${accessory.displayName} Light Sensor`;
|
|
143
|
-
(this.lightSensorService = this.accessory.getService(this.
|
|
144
|
-
|| this.accessory.addService(this.
|
|
154
|
+
(this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
|
|
155
|
+
|| this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
|
|
145
156
|
|
|
146
|
-
this.lightSensorService.setCharacteristic(this.
|
|
147
|
-
this.lightSensorService.setCharacteristic(this.
|
|
157
|
+
this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
158
|
+
this.lightSensorService.setCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
148
159
|
} else {
|
|
149
160
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
|
|
150
161
|
}
|
|
@@ -168,9 +179,9 @@ export class Hub {
|
|
|
168
179
|
const { temperature, humidity, lightLevel } = context;
|
|
169
180
|
const { CurrentTemperature, CurrentRelativeHumidity, CurrentAmbientLightLevel } = this;
|
|
170
181
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
'(temperature, humidity, lightLevel) = ' +
|
|
183
|
+
`Webhook:(${temperature}, ${humidity}, ${lightLevel}), ` +
|
|
184
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity}, ${CurrentAmbientLightLevel})`);
|
|
174
185
|
this.CurrentRelativeHumidity = humidity;
|
|
175
186
|
this.CurrentTemperature = temperature;
|
|
176
187
|
this.set_minLux = this.minLux();
|
|
@@ -265,7 +276,7 @@ export class Hub {
|
|
|
265
276
|
}
|
|
266
277
|
} catch (e: any) {
|
|
267
278
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
268
|
-
|
|
279
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
269
280
|
}
|
|
270
281
|
};
|
|
271
282
|
}
|
|
@@ -396,7 +407,7 @@ export class Hub {
|
|
|
396
407
|
);
|
|
397
408
|
}
|
|
398
409
|
if (!this.device.hub?.hide_lightsensor) {
|
|
399
|
-
this.lightSensorService?.setCharacteristic(this.
|
|
410
|
+
this.lightSensorService?.setCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
400
411
|
}
|
|
401
412
|
}
|
|
402
413
|
|
|
@@ -469,7 +480,7 @@ export class Hub {
|
|
|
469
480
|
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
470
481
|
}
|
|
471
482
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
472
|
-
this.humidityService?.updateCharacteristic(this.
|
|
483
|
+
this.humidityService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
473
484
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
474
485
|
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
475
486
|
}
|
|
@@ -487,7 +498,7 @@ export class Hub {
|
|
|
487
498
|
entry['temp'] = this.CurrentTemperature;
|
|
488
499
|
}
|
|
489
500
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
490
|
-
this.temperatureService?.updateCharacteristic(this.
|
|
501
|
+
this.temperatureService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
491
502
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
492
503
|
}
|
|
493
504
|
}
|
|
@@ -504,7 +515,7 @@ export class Hub {
|
|
|
504
515
|
entry['lux'] = this.CurrentAmbientLightLevel;
|
|
505
516
|
}
|
|
506
517
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
507
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
518
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
508
519
|
this.debugLog(
|
|
509
520
|
`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
510
521
|
+ `updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
@@ -624,13 +635,13 @@ export class Hub {
|
|
|
624
635
|
|
|
625
636
|
async apiError(e: any): Promise<void> {
|
|
626
637
|
if (!this.device.hub?.hide_temperature) {
|
|
627
|
-
this.temperatureService?.updateCharacteristic(this.
|
|
638
|
+
this.temperatureService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
628
639
|
}
|
|
629
640
|
if (!this.device.hub?.hide_humidity) {
|
|
630
|
-
this.humidityService?.updateCharacteristic(this.
|
|
641
|
+
this.humidityService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
631
642
|
}
|
|
632
643
|
if (!this.device.hub?.hide_lightsensor) {
|
|
633
|
-
this.lightSensorService?.updateCharacteristic(this.
|
|
644
|
+
this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
|
|
634
645
|
}
|
|
635
646
|
}
|
|
636
647
|
|
|
@@ -693,7 +704,7 @@ export class Hub {
|
|
|
693
704
|
}
|
|
694
705
|
}
|
|
695
706
|
|
|
696
|
-
async
|
|
707
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
697
708
|
let config = {};
|
|
698
709
|
if (device.hub) {
|
|
699
710
|
config = device.hub;
|
|
@@ -715,7 +726,7 @@ export class Hub {
|
|
|
715
726
|
}
|
|
716
727
|
}
|
|
717
728
|
|
|
718
|
-
async
|
|
729
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
719
730
|
if (this.platform.debugMode) {
|
|
720
731
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
721
732
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/device/humidifier.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, serviceData, ad, deviceStatus, Devices } from '../settings';
|
|
6
|
+
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
+
import { device, devicesConfig, serviceData, ad, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
@@ -12,6 +12,10 @@ import { device, devicesConfig, serviceData, ad, deviceStatus, Devices } from '.
|
|
|
12
12
|
* Each accessory may expose multiple services of different service types.
|
|
13
13
|
*/
|
|
14
14
|
export class Humidifier {
|
|
15
|
+
public readonly api: API;
|
|
16
|
+
public readonly log: Logging;
|
|
17
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
+
protected readonly hap: HAP;
|
|
15
19
|
// Services
|
|
16
20
|
humidifierService: Service;
|
|
17
21
|
temperatureservice?: Service;
|
|
@@ -52,20 +56,27 @@ export class Humidifier {
|
|
|
52
56
|
doHumidifierUpdate!: Subject<void>;
|
|
53
57
|
|
|
54
58
|
// Connection
|
|
55
|
-
private readonly
|
|
56
|
-
private readonly
|
|
59
|
+
private readonly OpenAPI: boolean;
|
|
60
|
+
private readonly BLE: boolean;
|
|
57
61
|
|
|
58
62
|
constructor(
|
|
59
63
|
private readonly platform: SwitchBotPlatform,
|
|
60
64
|
private accessory: PlatformAccessory,
|
|
61
65
|
public device: device & devicesConfig,
|
|
62
66
|
) {
|
|
67
|
+
this.api = this.platform.api;
|
|
68
|
+
this.log = this.platform.log;
|
|
69
|
+
this.config = this.platform.config;
|
|
70
|
+
this.hap = this.api.hap;
|
|
71
|
+
// Connection
|
|
72
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
73
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
63
74
|
// default placeholders
|
|
64
|
-
this.
|
|
75
|
+
this.deviceLogs(device);
|
|
65
76
|
this.scan(device);
|
|
66
77
|
this.refreshRate(device);
|
|
67
78
|
this.context();
|
|
68
|
-
this.
|
|
79
|
+
this.deviceConfig(device);
|
|
69
80
|
|
|
70
81
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
71
82
|
this.doHumidifierUpdate = new Subject();
|
|
@@ -76,21 +87,21 @@ export class Humidifier {
|
|
|
76
87
|
|
|
77
88
|
// set accessory information
|
|
78
89
|
accessory
|
|
79
|
-
.getService(this.
|
|
80
|
-
.setCharacteristic(this.
|
|
81
|
-
.setCharacteristic(this.
|
|
82
|
-
.setCharacteristic(this.
|
|
83
|
-
.setCharacteristic(this.
|
|
90
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
91
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
92
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W0801800')
|
|
93
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
94
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
84
95
|
|
|
85
96
|
// get the service if it exists, otherwise create a new service
|
|
86
97
|
// you can create multiple services for each accessory
|
|
87
98
|
const humidifierService = `${accessory.displayName} Humidifier`;
|
|
88
|
-
(this.humidifierService = accessory.getService(this.
|
|
89
|
-
|| accessory.addService(this.
|
|
99
|
+
(this.humidifierService = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
100
|
+
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), humidifierService;
|
|
90
101
|
|
|
91
|
-
this.humidifierService.setCharacteristic(this.
|
|
92
|
-
if (!this.humidifierService.testCharacteristic(this.
|
|
93
|
-
this.humidifierService.addCharacteristic(this.
|
|
102
|
+
this.humidifierService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
103
|
+
if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
104
|
+
this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
@@ -98,12 +109,12 @@ export class Humidifier {
|
|
|
98
109
|
|
|
99
110
|
// create handlers for required characteristics
|
|
100
111
|
this.humidifierService.setCharacteristic(
|
|
101
|
-
this.
|
|
112
|
+
this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
102
113
|
this.CurrentHumidifierDehumidifierState,
|
|
103
114
|
);
|
|
104
115
|
|
|
105
116
|
this.humidifierService
|
|
106
|
-
.getCharacteristic(this.
|
|
117
|
+
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
107
118
|
.setProps({
|
|
108
119
|
validValueRanges: [0, 1],
|
|
109
120
|
minValue: 0,
|
|
@@ -112,10 +123,10 @@ export class Humidifier {
|
|
|
112
123
|
})
|
|
113
124
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
114
125
|
|
|
115
|
-
this.humidifierService.getCharacteristic(this.
|
|
126
|
+
this.humidifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
116
127
|
|
|
117
128
|
this.humidifierService
|
|
118
|
-
.getCharacteristic(this.
|
|
129
|
+
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
119
130
|
.setProps({
|
|
120
131
|
validValueRanges: [0, 100],
|
|
121
132
|
minValue: 0,
|
|
@@ -127,20 +138,20 @@ export class Humidifier {
|
|
|
127
138
|
// Temperature Sensor Service
|
|
128
139
|
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
129
140
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
130
|
-
this.temperatureservice = this.accessory.getService(this.
|
|
141
|
+
this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
131
142
|
accessory.removeService(this.temperatureservice!);
|
|
132
143
|
} else if (!this.temperatureservice && !this.BLE) {
|
|
133
144
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
134
145
|
const temperatureservice = `${accessory.displayName} Temperature Sensor`;
|
|
135
|
-
(this.temperatureservice = this.accessory.getService(this.
|
|
136
|
-
|| this.accessory.addService(this.
|
|
146
|
+
(this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
147
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureservice;
|
|
137
148
|
|
|
138
|
-
this.temperatureservice.setCharacteristic(this.
|
|
139
|
-
if (!this.temperatureservice.testCharacteristic(this.
|
|
140
|
-
this.temperatureservice.addCharacteristic(this.
|
|
149
|
+
this.temperatureservice.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
150
|
+
if (!this.temperatureservice.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
151
|
+
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
141
152
|
}
|
|
142
153
|
this.temperatureservice
|
|
143
|
-
.getCharacteristic(this.
|
|
154
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
144
155
|
.setProps({
|
|
145
156
|
validValueRanges: [-273.15, 100],
|
|
146
157
|
minValue: -273.15,
|
|
@@ -174,16 +185,16 @@ export class Humidifier {
|
|
|
174
185
|
const { temperature, humidity } = context;
|
|
175
186
|
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
176
187
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
'(temperature, humidity) = ' +
|
|
189
|
+
`Webhook:(${temperature}, ${humidity}), ` +
|
|
190
|
+
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
180
191
|
this.CurrentRelativeHumidity = humidity;
|
|
181
192
|
this.CurrentTemperature = temperature;
|
|
182
193
|
this.updateHomeKitCharacteristics();
|
|
183
194
|
}
|
|
184
195
|
} catch (e: any) {
|
|
185
196
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
186
|
-
|
|
197
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
187
198
|
}
|
|
188
199
|
};
|
|
189
200
|
}
|
|
@@ -236,9 +247,9 @@ export class Humidifier {
|
|
|
236
247
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
237
248
|
// Active
|
|
238
249
|
if (this.onState) {
|
|
239
|
-
this.Active = this.
|
|
250
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
240
251
|
} else {
|
|
241
|
-
this.Active = this.
|
|
252
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
242
253
|
}
|
|
243
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
244
255
|
}
|
|
@@ -256,23 +267,23 @@ export class Humidifier {
|
|
|
256
267
|
// Target Humidifier Dehumidifier State
|
|
257
268
|
switch (this.OpenAPI_CurrentHumidifierDehumidifierState) {
|
|
258
269
|
case true:
|
|
259
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
260
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
270
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
271
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
261
272
|
this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
|
|
262
273
|
break;
|
|
263
274
|
default:
|
|
264
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
275
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
265
276
|
if (this.OpenAPI_RelativeHumidityHumidifierThreshold! > 100) {
|
|
266
277
|
this.RelativeHumidityHumidifierThreshold = 100;
|
|
267
278
|
} else {
|
|
268
279
|
this.RelativeHumidityHumidifierThreshold = this.OpenAPI_RelativeHumidityHumidifierThreshold!;
|
|
269
280
|
}
|
|
270
281
|
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
271
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
272
|
-
} else if (this.Active === this.
|
|
273
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
282
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
283
|
+
} else if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
284
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
274
285
|
} else {
|
|
275
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
286
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
276
287
|
}
|
|
277
288
|
}
|
|
278
289
|
this.debugLog(
|
|
@@ -288,10 +299,10 @@ export class Humidifier {
|
|
|
288
299
|
// Active
|
|
289
300
|
switch (this.OpenAPI_Active) {
|
|
290
301
|
case 'on':
|
|
291
|
-
this.Active = this.
|
|
302
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
292
303
|
break;
|
|
293
304
|
default:
|
|
294
|
-
this.Active = this.
|
|
305
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
295
306
|
}
|
|
296
307
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
297
308
|
// Water Level
|
|
@@ -484,8 +495,8 @@ export class Humidifier {
|
|
|
484
495
|
async openAPIpushChanges(): Promise<void> {
|
|
485
496
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
486
497
|
if (
|
|
487
|
-
this.TargetHumidifierDehumidifierState === this.
|
|
488
|
-
this.Active === this.
|
|
498
|
+
this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
499
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE
|
|
489
500
|
) {
|
|
490
501
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
491
502
|
const bodyChange = JSON.stringify({
|
|
@@ -522,8 +533,8 @@ export class Humidifier {
|
|
|
522
533
|
);
|
|
523
534
|
}
|
|
524
535
|
} else if (
|
|
525
|
-
this.TargetHumidifierDehumidifierState === this.
|
|
526
|
-
this.Active === this.
|
|
536
|
+
this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
537
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE
|
|
527
538
|
) {
|
|
528
539
|
await this.pushAutoChanges();
|
|
529
540
|
} else {
|
|
@@ -537,8 +548,8 @@ export class Humidifier {
|
|
|
537
548
|
async pushAutoChanges(): Promise<void> {
|
|
538
549
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
539
550
|
if (
|
|
540
|
-
this.TargetHumidifierDehumidifierState === this.
|
|
541
|
-
this.Active === this.
|
|
551
|
+
this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
552
|
+
this.Active === this.hap.Characteristic.Active.ACTIVE
|
|
542
553
|
) {
|
|
543
554
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
544
555
|
const bodyChange = JSON.stringify({
|
|
@@ -587,7 +598,7 @@ export class Humidifier {
|
|
|
587
598
|
*/
|
|
588
599
|
async pushActiveChanges(): Promise<void> {
|
|
589
600
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
590
|
-
if (this.Active === this.
|
|
601
|
+
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
591
602
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
592
603
|
const bodyChange = JSON.stringify({
|
|
593
604
|
command: 'turnOff',
|
|
@@ -645,7 +656,7 @@ export class Humidifier {
|
|
|
645
656
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
646
657
|
*/
|
|
647
658
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
648
|
-
if (this.Active === this.
|
|
659
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
649
660
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
650
661
|
} else {
|
|
651
662
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
@@ -659,16 +670,16 @@ export class Humidifier {
|
|
|
659
670
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
660
671
|
*/
|
|
661
672
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
662
|
-
if (this.Active === this.
|
|
673
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
663
674
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
664
675
|
} else {
|
|
665
676
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
666
677
|
}
|
|
667
678
|
|
|
668
679
|
this.RelativeHumidityHumidifierThreshold = value;
|
|
669
|
-
if (this.Active === this.
|
|
670
|
-
this.Active = this.
|
|
671
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
680
|
+
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
681
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
682
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
672
683
|
}
|
|
673
684
|
this.doHumidifierUpdate.next();
|
|
674
685
|
}
|
|
@@ -680,7 +691,7 @@ export class Humidifier {
|
|
|
680
691
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
681
692
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
682
693
|
} else {
|
|
683
|
-
this.humidifierService.updateCharacteristic(this.
|
|
694
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
684
695
|
this.debugLog(
|
|
685
696
|
`${this.device.deviceType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
686
697
|
);
|
|
@@ -690,7 +701,7 @@ export class Humidifier {
|
|
|
690
701
|
if (this.WaterLevel === undefined) {
|
|
691
702
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
692
703
|
} else {
|
|
693
|
-
this.humidifierService.updateCharacteristic(this.
|
|
704
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.WaterLevel);
|
|
694
705
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
|
|
695
706
|
this.accessory.context.WaterLevel = this.WaterLevel;
|
|
696
707
|
}
|
|
@@ -702,7 +713,7 @@ export class Humidifier {
|
|
|
702
713
|
);
|
|
703
714
|
} else {
|
|
704
715
|
this.humidifierService.updateCharacteristic(
|
|
705
|
-
this.
|
|
716
|
+
this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
706
717
|
this.CurrentHumidifierDehumidifierState,
|
|
707
718
|
);
|
|
708
719
|
this.debugLog(
|
|
@@ -717,7 +728,7 @@ export class Humidifier {
|
|
|
717
728
|
);
|
|
718
729
|
} else {
|
|
719
730
|
this.humidifierService.updateCharacteristic(
|
|
720
|
-
this.
|
|
731
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
721
732
|
this.TargetHumidifierDehumidifierState,
|
|
722
733
|
);
|
|
723
734
|
this.debugLog(
|
|
@@ -729,7 +740,7 @@ export class Humidifier {
|
|
|
729
740
|
if (this.Active === undefined) {
|
|
730
741
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
731
742
|
} else {
|
|
732
|
-
this.humidifierService.updateCharacteristic(this.
|
|
743
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
733
744
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
734
745
|
this.accessory.context.Active = this.Active;
|
|
735
746
|
}
|
|
@@ -740,7 +751,7 @@ export class Humidifier {
|
|
|
740
751
|
);
|
|
741
752
|
} else {
|
|
742
753
|
this.humidifierService.updateCharacteristic(
|
|
743
|
-
this.
|
|
754
|
+
this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
744
755
|
this.RelativeHumidityHumidifierThreshold,
|
|
745
756
|
);
|
|
746
757
|
this.debugLog(
|
|
@@ -753,7 +764,7 @@ export class Humidifier {
|
|
|
753
764
|
if (this.CurrentTemperature === undefined) {
|
|
754
765
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
755
766
|
} else {
|
|
756
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
767
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
757
768
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
758
769
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
759
770
|
}
|
|
@@ -880,22 +891,22 @@ export class Humidifier {
|
|
|
880
891
|
}
|
|
881
892
|
|
|
882
893
|
async apiError(e: any): Promise<void> {
|
|
883
|
-
this.humidifierService.updateCharacteristic(this.
|
|
894
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
884
895
|
if (!this.BLE) {
|
|
885
|
-
this.humidifierService.updateCharacteristic(this.
|
|
896
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
886
897
|
}
|
|
887
|
-
this.humidifierService.updateCharacteristic(this.
|
|
888
|
-
this.humidifierService.updateCharacteristic(this.
|
|
889
|
-
this.humidifierService.updateCharacteristic(this.
|
|
890
|
-
this.humidifierService.updateCharacteristic(this.
|
|
898
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
899
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
900
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
901
|
+
this.humidifierService.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
891
902
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
892
|
-
this.temperatureservice?.updateCharacteristic(this.
|
|
903
|
+
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
893
904
|
}
|
|
894
905
|
}
|
|
895
906
|
|
|
896
907
|
async context() {
|
|
897
908
|
if (this.Active === undefined) {
|
|
898
|
-
this.Active = this.
|
|
909
|
+
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
899
910
|
} else {
|
|
900
911
|
this.Active = this.accessory.context.Active;
|
|
901
912
|
}
|
|
@@ -910,16 +921,16 @@ export class Humidifier {
|
|
|
910
921
|
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
911
922
|
}
|
|
912
923
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
913
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
924
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
914
925
|
} else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
915
|
-
this.TargetHumidifierDehumidifierState = this.
|
|
926
|
+
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
916
927
|
} else {
|
|
917
928
|
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
918
929
|
}
|
|
919
930
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
920
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
931
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
921
932
|
} else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
|
|
922
|
-
this.CurrentHumidifierDehumidifierState = this.
|
|
933
|
+
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
923
934
|
} else {
|
|
924
935
|
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
925
936
|
}
|
|
@@ -949,7 +960,7 @@ export class Humidifier {
|
|
|
949
960
|
}
|
|
950
961
|
}
|
|
951
962
|
|
|
952
|
-
async
|
|
963
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
953
964
|
let config = {};
|
|
954
965
|
if (device.humidifier) {
|
|
955
966
|
config = device.humidifier;
|
|
@@ -977,7 +988,7 @@ export class Humidifier {
|
|
|
977
988
|
}
|
|
978
989
|
}
|
|
979
990
|
|
|
980
|
-
async
|
|
991
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
981
992
|
if (this.platform.debugMode) {
|
|
982
993
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
983
994
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|