@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +166 -24
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +439 -817
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +835 -865
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +287 -653
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +354 -732
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +268 -576
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +431 -851
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +60 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +739 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +698 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +257 -631
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +266 -629
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +215 -615
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +336 -645
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +290 -595
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +211 -608
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +205 -615
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +202 -563
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +125 -484
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +233 -549
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +170 -493
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +340 -468
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +105 -319
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +44 -285
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +92 -350
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +369 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +118 -362
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +438 -570
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +91 -339
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +45 -285
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +47 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -17
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +472 -888
- package/src/device/bot.ts +893 -968
- package/src/device/ceilinglight.ts +304 -709
- package/src/device/colorbulb.ts +370 -803
- package/src/device/contact.ts +301 -611
- package/src/device/curtain.ts +460 -908
- package/src/device/device.ts +755 -0
- package/src/device/fan.ts +749 -0
- package/src/device/hub.ts +294 -664
- package/src/device/humidifier.ts +299 -696
- package/src/device/iosensor.ts +251 -644
- package/src/device/lightstrip.ts +362 -712
- package/src/device/lock.ts +328 -653
- package/src/device/meter.ts +247 -637
- package/src/device/meterplus.ts +240 -644
- package/src/device/motion.ts +230 -598
- package/src/device/plug.ts +139 -525
- package/src/device/robotvacuumcleaner.ts +258 -593
- package/src/device/waterdetector.ts +191 -522
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +370 -527
- package/src/irdevice/airpurifier.ts +132 -356
- package/src/irdevice/camera.ts +58 -311
- package/src/irdevice/fan.ts +109 -379
- package/src/irdevice/irdevice.ts +382 -0
- package/src/irdevice/light.ts +157 -412
- package/src/irdevice/other.ts +507 -648
- package/src/irdevice/tv.ts +121 -375
- package/src/irdevice/vacuumcleaner.ts +59 -311
- package/src/irdevice/waterheater.ts +61 -320
- package/src/platform.ts +395 -259
- package/src/settings.ts +118 -609
- package/src/utils.ts +642 -1
- package/.github/npm-version-script.cjs +0 -81
- package/src/device/waterdetector.json +0 -11
package/src/device/humidifier.ts
CHANGED
|
@@ -1,119 +1,74 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
2
|
+
import { deviceBase } from './device.js';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
|
-
import {
|
|
4
|
+
import { Devices } from '../settings.js';
|
|
5
|
+
import { convertUnits } from '../utils.js';
|
|
5
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
import {
|
|
7
|
+
|
|
8
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
|
+
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Platform Accessory
|
|
11
14
|
* An instance of this class is created for each accessory your platform registers
|
|
12
15
|
* Each accessory may expose multiple services of different service types.
|
|
13
16
|
*/
|
|
14
|
-
export class Humidifier {
|
|
15
|
-
public readonly api: API;
|
|
16
|
-
public readonly log: Logging;
|
|
17
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
-
protected readonly hap: HAP;
|
|
17
|
+
export class Humidifier extends deviceBase {
|
|
19
18
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
37
|
-
OpenAPI_CurrentTemperature: deviceStatus['temperature'];
|
|
38
|
-
OpenAPI_CurrentRelativeHumidity: deviceStatus['humidity'];
|
|
39
|
-
OpenAPI_CurrentHumidifierDehumidifierState: deviceStatus['auto'];
|
|
40
|
-
OpenAPI_RelativeHumidityHumidifierThreshold: deviceStatus['nebulizationEfficiency'];
|
|
41
|
-
|
|
42
|
-
// BLE Others
|
|
43
|
-
connected?: boolean;
|
|
44
|
-
onState!: serviceData['onState'];
|
|
45
|
-
autoMode!: serviceData['autoMode'];
|
|
46
|
-
percentage!: serviceData['percentage'];
|
|
47
|
-
|
|
48
|
-
// Config
|
|
49
|
-
set_minStep?: number;
|
|
50
|
-
scanDuration!: number;
|
|
51
|
-
deviceLogging!: string;
|
|
52
|
-
deviceRefreshRate!: number;
|
|
19
|
+
private HumidifierDehumidifier: {
|
|
20
|
+
Name: CharacteristicValue;
|
|
21
|
+
Service: Service;
|
|
22
|
+
Active: CharacteristicValue;
|
|
23
|
+
WaterLevel: CharacteristicValue;
|
|
24
|
+
CurrentRelativeHumidity: CharacteristicValue;
|
|
25
|
+
TargetHumidifierDehumidifierState: CharacteristicValue;
|
|
26
|
+
CurrentHumidifierDehumidifierState: CharacteristicValue;
|
|
27
|
+
RelativeHumidityHumidifierThreshold: CharacteristicValue;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
private TemperatureSensor?: {
|
|
31
|
+
Name: CharacteristicValue;
|
|
32
|
+
Service: Service;
|
|
33
|
+
CurrentTemperature: CharacteristicValue;
|
|
34
|
+
};
|
|
53
35
|
|
|
54
36
|
// Updates
|
|
55
37
|
humidifierUpdateInProgress!: boolean;
|
|
56
38
|
doHumidifierUpdate!: Subject<void>;
|
|
57
39
|
|
|
58
|
-
// Connection
|
|
59
|
-
private readonly OpenAPI: boolean;
|
|
60
|
-
private readonly BLE: boolean;
|
|
61
|
-
|
|
62
40
|
constructor(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
41
|
+
readonly platform: SwitchBotPlatform,
|
|
42
|
+
accessory: PlatformAccessory,
|
|
43
|
+
device: device & devicesConfig,
|
|
66
44
|
) {
|
|
67
|
-
|
|
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';
|
|
74
|
-
// default placeholders
|
|
75
|
-
this.deviceLogs(device);
|
|
76
|
-
this.scan(device);
|
|
77
|
-
this.refreshRate(device);
|
|
78
|
-
this.deviceContext();
|
|
79
|
-
this.deviceConfig(device);
|
|
80
|
-
|
|
45
|
+
super(platform, accessory, device);
|
|
81
46
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
82
47
|
this.doHumidifierUpdate = new Subject();
|
|
83
48
|
this.humidifierUpdateInProgress = false;
|
|
84
49
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
108
|
-
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
109
|
-
|
|
110
|
-
// create handlers for required characteristics
|
|
111
|
-
this.humidifierService.setCharacteristic(
|
|
112
|
-
this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
113
|
-
this.CurrentHumidifierDehumidifierState,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
this.humidifierService
|
|
50
|
+
// Initialize the HumidifierDehumidifier Service
|
|
51
|
+
accessory.context.HumidifierDehumidifier = accessory.context.HumidifierDehumidifier ?? {};
|
|
52
|
+
this.HumidifierDehumidifier = {
|
|
53
|
+
Name: accessory.context.HumidifierDehumidifier.Name ?? accessory.displayName,
|
|
54
|
+
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
55
|
+
?? accessory.addService(this.hap.Service.HumidifierDehumidifier) as Service,
|
|
56
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.ACTIVE,
|
|
57
|
+
WaterLevel: accessory.context.WaterLevel ?? 100,
|
|
58
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
59
|
+
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
60
|
+
?? this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
61
|
+
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
62
|
+
?? this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
63
|
+
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold ?? 50,
|
|
64
|
+
};
|
|
65
|
+
accessory.context.HumidifierDehumidifier = this.HumidifierDehumidifier as object;
|
|
66
|
+
|
|
67
|
+
// Initialize the HumidifierDehumidifier Characteristics
|
|
68
|
+
this.HumidifierDehumidifier.Service
|
|
69
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumidifierDehumidifier.Name)
|
|
70
|
+
.setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
71
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState)
|
|
117
72
|
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
118
73
|
.setProps({
|
|
119
74
|
validValueRanges: [0, 1],
|
|
@@ -121,36 +76,50 @@ export class Humidifier {
|
|
|
121
76
|
maxValue: 1,
|
|
122
77
|
validValues: [0, 1],
|
|
123
78
|
})
|
|
79
|
+
.onGet(() => {
|
|
80
|
+
return this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
81
|
+
})
|
|
124
82
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
125
83
|
|
|
126
|
-
this.
|
|
84
|
+
this.HumidifierDehumidifier.Service
|
|
85
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
86
|
+
.onGet(() => {
|
|
87
|
+
return this.HumidifierDehumidifier.Active;
|
|
88
|
+
})
|
|
89
|
+
.onSet(this.ActiveSet.bind(this));
|
|
127
90
|
|
|
128
|
-
this.
|
|
91
|
+
this.HumidifierDehumidifier.Service
|
|
129
92
|
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
130
93
|
.setProps({
|
|
131
94
|
validValueRanges: [0, 100],
|
|
132
95
|
minValue: 0,
|
|
133
96
|
maxValue: 100,
|
|
134
|
-
minStep:
|
|
97
|
+
minStep: device.humidifier?.set_minStep ?? 1,
|
|
98
|
+
})
|
|
99
|
+
.onGet(() => {
|
|
100
|
+
return this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
135
101
|
})
|
|
136
102
|
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
137
103
|
|
|
138
|
-
// Temperature Sensor Service
|
|
139
|
-
if (device.humidifier?.hide_temperature
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
145
|
-
const temperatureservice = `${accessory.displayName} Temperature Sensor`;
|
|
146
|
-
(this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
147
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureservice;
|
|
148
|
-
|
|
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`);
|
|
104
|
+
// Initialize the Temperature Sensor Service
|
|
105
|
+
if (device.humidifier?.hide_temperature) {
|
|
106
|
+
if (this.TemperatureSensor) {
|
|
107
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
108
|
+
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
109
|
+
accessory.removeService(this.TemperatureSensor!.Service);
|
|
152
110
|
}
|
|
153
|
-
|
|
111
|
+
} else {
|
|
112
|
+
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {};
|
|
113
|
+
this.TemperatureSensor = {
|
|
114
|
+
Name: accessory.context.TemperatureSensor.Name ?? `${accessory.displayName} Temperature Sensor`,
|
|
115
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
116
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
117
|
+
};
|
|
118
|
+
accessory.context.TemperatureSensor = this.TemperatureSensor as object;
|
|
119
|
+
|
|
120
|
+
// Initialize the Temperature Sensor Characteristics
|
|
121
|
+
this.TemperatureSensor.Service
|
|
122
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
154
123
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
155
124
|
.setProps({
|
|
156
125
|
validValueRanges: [-273.15, 100],
|
|
@@ -159,45 +128,25 @@ export class Humidifier {
|
|
|
159
128
|
minStep: 0.1,
|
|
160
129
|
})
|
|
161
130
|
.onGet(() => {
|
|
162
|
-
return this.CurrentTemperature;
|
|
131
|
+
return this.TemperatureSensor!.CurrentTemperature;
|
|
163
132
|
});
|
|
164
|
-
} else {
|
|
165
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
166
133
|
}
|
|
167
134
|
|
|
135
|
+
// Retrieve initial values and updateHomekit
|
|
136
|
+
this.refreshStatus();
|
|
137
|
+
|
|
168
138
|
// Retrieve initial values and updateHomekit
|
|
169
139
|
this.updateHomeKitCharacteristics();
|
|
170
140
|
|
|
171
141
|
// Start an update interval
|
|
172
142
|
interval(this.deviceRefreshRate * 1000)
|
|
173
143
|
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
174
|
-
.subscribe(() => {
|
|
175
|
-
this.refreshStatus();
|
|
144
|
+
.subscribe(async () => {
|
|
145
|
+
await this.refreshStatus();
|
|
176
146
|
});
|
|
177
147
|
|
|
178
148
|
//regisiter webhook event handler
|
|
179
|
-
|
|
180
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
181
|
-
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
182
|
-
try {
|
|
183
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
184
|
-
if (context.scale === 'CELSIUS') {
|
|
185
|
-
const { temperature, humidity } = context;
|
|
186
|
-
const { CurrentTemperature, CurrentRelativeHumidity } = this;
|
|
187
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
188
|
-
'(temperature, humidity) = ' +
|
|
189
|
-
`Webhook:(${temperature}, ${humidity}), ` +
|
|
190
|
-
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
191
|
-
this.CurrentRelativeHumidity = humidity;
|
|
192
|
-
this.CurrentTemperature = temperature;
|
|
193
|
-
this.updateHomeKitCharacteristics();
|
|
194
|
-
}
|
|
195
|
-
} catch (e: any) {
|
|
196
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
197
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
149
|
+
this.registerWebhook(accessory, device);
|
|
201
150
|
|
|
202
151
|
// Watch for Humidifier change events
|
|
203
152
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
@@ -206,121 +155,112 @@ export class Humidifier {
|
|
|
206
155
|
tap(() => {
|
|
207
156
|
this.humidifierUpdateInProgress = true;
|
|
208
157
|
}),
|
|
209
|
-
debounceTime(this.
|
|
158
|
+
debounceTime(this.devicePushRate * 1000),
|
|
210
159
|
)
|
|
211
160
|
.subscribe(async () => {
|
|
212
161
|
try {
|
|
213
162
|
await this.pushChanges();
|
|
214
163
|
} catch (e: any) {
|
|
215
164
|
this.apiError(e);
|
|
216
|
-
this.errorLog(
|
|
217
|
-
|
|
218
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
219
|
-
);
|
|
165
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
166
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
220
167
|
}
|
|
221
168
|
this.humidifierUpdateInProgress = false;
|
|
222
169
|
});
|
|
223
170
|
}
|
|
224
171
|
|
|
225
|
-
|
|
226
|
-
* Parse the device status from the SwitchBot api
|
|
227
|
-
*/
|
|
228
|
-
async parseStatus(): Promise<void> {
|
|
229
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
230
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
231
|
-
} else if (this.BLE) {
|
|
232
|
-
await this.BLEparseStatus();
|
|
233
|
-
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
234
|
-
await this.openAPIparseStatus();
|
|
235
|
-
} else {
|
|
236
|
-
await this.offlineOff();
|
|
237
|
-
this.debugWarnLog(
|
|
238
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async BLEparseStatus(): Promise<void> {
|
|
172
|
+
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
244
173
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
174
|
+
// Target Humidifier Dehumidifier State
|
|
175
|
+
if (serviceData.autoMode) {
|
|
176
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
177
|
+
}
|
|
245
178
|
// Current Relative Humidity
|
|
246
|
-
this.CurrentRelativeHumidity =
|
|
247
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
179
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage!;
|
|
180
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
181
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
248
182
|
// Active
|
|
249
|
-
if (
|
|
250
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
183
|
+
if (serviceData.onState) {
|
|
184
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
251
185
|
} else {
|
|
252
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
186
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
253
187
|
}
|
|
254
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
188
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
255
189
|
}
|
|
256
190
|
|
|
257
|
-
async openAPIparseStatus(): Promise<void> {
|
|
191
|
+
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
258
192
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
259
193
|
// Current Relative Humidity
|
|
260
|
-
this.CurrentRelativeHumidity =
|
|
261
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
194
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature!;
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
196
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
262
197
|
// Current Temperature
|
|
263
198
|
if (!this.device.humidifier?.hide_temperature) {
|
|
264
|
-
this.CurrentTemperature =
|
|
265
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
199
|
+
this.TemperatureSensor!.CurrentTemperature = deviceStatus.body.temperature!;
|
|
200
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
266
201
|
}
|
|
267
202
|
// Target Humidifier Dehumidifier State
|
|
268
|
-
switch (
|
|
203
|
+
switch (deviceStatus.body.auto) {
|
|
269
204
|
case true:
|
|
270
|
-
this.TargetHumidifierDehumidifierState =
|
|
271
|
-
|
|
272
|
-
this.
|
|
205
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
206
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
207
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
208
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
273
209
|
break;
|
|
274
210
|
default:
|
|
275
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
276
|
-
if (
|
|
277
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
211
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
212
|
+
if (deviceStatus.body.nebulizationEfficiency! > 100) {
|
|
213
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
278
214
|
} else {
|
|
279
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
215
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency!;
|
|
280
216
|
}
|
|
281
|
-
if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
|
|
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;
|
|
217
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
218
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
219
|
+
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
220
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
285
221
|
} else {
|
|
286
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
222
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
287
223
|
}
|
|
288
224
|
}
|
|
289
|
-
this.debugLog(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`
|
|
295
|
-
);
|
|
296
|
-
this.debugLog(
|
|
297
|
-
`${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
298
|
-
);
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
226
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
227
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
228
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
229
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
230
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
299
231
|
// Active
|
|
300
|
-
switch (
|
|
232
|
+
switch (deviceStatus.body.power) {
|
|
301
233
|
case 'on':
|
|
302
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
234
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
303
235
|
break;
|
|
304
236
|
default:
|
|
305
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
237
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
306
238
|
}
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
239
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
308
240
|
// Water Level
|
|
309
|
-
if (
|
|
310
|
-
this.WaterLevel = 0;
|
|
241
|
+
if (deviceStatus.body.lackWater) {
|
|
242
|
+
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
311
243
|
} else {
|
|
312
|
-
this.WaterLevel = 100;
|
|
244
|
+
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
313
245
|
}
|
|
314
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
246
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
315
247
|
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
this.
|
|
248
|
+
// Firmware Version
|
|
249
|
+
const version = deviceStatus.body.version?.toString();
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
251
|
+
if (deviceStatus.body.version) {
|
|
252
|
+
const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
253
|
+
this.accessory
|
|
254
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
255
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
256
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
257
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
258
|
+
.updateValue(deviceVersion);
|
|
259
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
260
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
261
|
+
}
|
|
319
262
|
}
|
|
320
263
|
|
|
321
|
-
/**
|
|
322
|
-
* Asks the SwitchBot API for the latest device information
|
|
323
|
-
*/
|
|
324
264
|
async refreshStatus(): Promise<void> {
|
|
325
265
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
326
266
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -330,10 +270,8 @@ export class Humidifier {
|
|
|
330
270
|
await this.openAPIRefreshStatus();
|
|
331
271
|
} else {
|
|
332
272
|
await this.offlineOff();
|
|
333
|
-
this.debugWarnLog(
|
|
334
|
-
|
|
335
|
-
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
336
|
-
);
|
|
273
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
274
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
337
275
|
}
|
|
338
276
|
}
|
|
339
277
|
|
|
@@ -350,103 +288,43 @@ export class Humidifier {
|
|
|
350
288
|
// Start to monitor advertisement packets
|
|
351
289
|
(async () => {
|
|
352
290
|
// Start to monitor advertisement packets
|
|
353
|
-
await switchbot.startScan({
|
|
354
|
-
model: 'e',
|
|
355
|
-
id: this.device.bleMac,
|
|
356
|
-
});
|
|
291
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
357
292
|
// Set an event handler
|
|
358
293
|
switchbot.onadvertisement = (ad: any) => {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
294
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
295
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
296
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
362
297
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
363
|
-
this.autoMode = ad.serviceData.autoMode;
|
|
364
|
-
this.onState = ad.serviceData.onState;
|
|
365
|
-
this.percentage = ad.serviceData.percentage > 100 ? 100 : ad.serviceData.percentage;
|
|
366
298
|
} else {
|
|
367
299
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
368
300
|
}
|
|
369
301
|
};
|
|
370
|
-
// Wait
|
|
302
|
+
// Wait 10 seconds
|
|
371
303
|
await switchbot.wait(this.scanDuration * 1000);
|
|
372
304
|
// Stop to monitor
|
|
373
305
|
await switchbot.stopScan();
|
|
374
306
|
// Update HomeKit
|
|
375
|
-
await this.BLEparseStatus();
|
|
307
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
376
308
|
await this.updateHomeKitCharacteristics();
|
|
377
309
|
})();
|
|
378
|
-
|
|
379
|
-
switchbot
|
|
380
|
-
.startScan({
|
|
381
|
-
model: 'e',
|
|
382
|
-
id: this.device.bleMac,
|
|
383
|
-
})
|
|
384
|
-
.then(async () => {
|
|
385
|
-
// Set an event handler
|
|
386
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
387
|
-
this.debugLog(
|
|
388
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
389
|
-
` BLE Address Found: ${ad.address}`,
|
|
390
|
-
);
|
|
391
|
-
this.autoMode = ad.serviceData.autoMode;
|
|
392
|
-
this.onState = ad.serviceData.onState;
|
|
393
|
-
this.percentage = ad.serviceData.percentage;
|
|
394
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
395
|
-
this.debugLog(
|
|
396
|
-
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
397
|
-
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
if (ad.serviceData) {
|
|
401
|
-
this.connected = true;
|
|
402
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
403
|
-
await this.stopScanning(switchbot);
|
|
404
|
-
} else {
|
|
405
|
-
this.connected = false;
|
|
406
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
// Wait
|
|
410
|
-
return await sleep(this.scanDuration * 1000);
|
|
411
|
-
})
|
|
412
|
-
.then(async () => {
|
|
413
|
-
// Stop to monitor
|
|
414
|
-
await this.stopScanning(switchbot);
|
|
415
|
-
})
|
|
416
|
-
.catch(async (e: any) => {
|
|
417
|
-
this.apiError(e);
|
|
418
|
-
this.errorLog(
|
|
419
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
420
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
421
|
-
);
|
|
422
|
-
await this.BLERefreshConnection(switchbot);
|
|
423
|
-
});
|
|
424
|
-
} else {
|
|
310
|
+
if (switchbot === undefined) {
|
|
425
311
|
await this.BLERefreshConnection(switchbot);
|
|
426
|
-
}
|
|
312
|
+
}
|
|
427
313
|
}
|
|
428
314
|
|
|
429
315
|
async openAPIRefreshStatus(): Promise<void> {
|
|
430
316
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
431
317
|
try {
|
|
432
|
-
const { body, statusCode } = await
|
|
433
|
-
headers: this.platform.generateHeaders()
|
|
434
|
-
});
|
|
318
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
319
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
435
320
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
436
321
|
const deviceStatus: any = await body.json();
|
|
437
322
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
438
323
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
439
324
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
440
|
-
this.
|
|
325
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
441
326
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
442
|
-
this.
|
|
443
|
-
this.OpenAPI_Active = deviceStatus.body.power;
|
|
444
|
-
this.OpenAPI_WaterLevel = deviceStatus.body.lackWater;
|
|
445
|
-
this.OpenAPI_CurrentRelativeHumidity = deviceStatus.body.humidity;
|
|
446
|
-
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature;
|
|
447
|
-
this.OpenAPI_RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
|
|
448
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
449
|
-
this.openAPIparseStatus();
|
|
327
|
+
this.openAPIparseStatus(deviceStatus);
|
|
450
328
|
this.updateHomeKitCharacteristics();
|
|
451
329
|
} else {
|
|
452
330
|
this.statusCode(statusCode);
|
|
@@ -454,10 +332,32 @@ export class Humidifier {
|
|
|
454
332
|
}
|
|
455
333
|
} catch (e: any) {
|
|
456
334
|
this.apiError(e);
|
|
457
|
-
this.errorLog(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
335
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
336
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async registerWebhook(accessory: PlatformAccessory, device: device & devicesConfig) {
|
|
341
|
+
if (device.webhook) {
|
|
342
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
|
|
343
|
+
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
344
|
+
try {
|
|
345
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
346
|
+
const { temperature, humidity } = context;
|
|
347
|
+
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
348
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
349
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} (temperature, humidity) = Webhook:(${convertUnits(temperature,
|
|
350
|
+
context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
351
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
352
|
+
if (!device.humidifier?.hide_temperature) {
|
|
353
|
+
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
|
354
|
+
}
|
|
355
|
+
this.updateHomeKitCharacteristics();
|
|
356
|
+
} catch (e: any) {
|
|
357
|
+
this.errorLog(`${device.deviceType}: ${accessory.displayName} `
|
|
358
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
461
361
|
}
|
|
462
362
|
}
|
|
463
363
|
|
|
@@ -473,9 +373,8 @@ export class Humidifier {
|
|
|
473
373
|
await this.openAPIpushChanges();
|
|
474
374
|
} else {
|
|
475
375
|
await this.offlineOff();
|
|
476
|
-
this.debugWarnLog(
|
|
477
|
-
|
|
478
|
-
);
|
|
376
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
377
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
479
378
|
}
|
|
480
379
|
interval(5000)
|
|
481
380
|
.pipe(take(1))
|
|
@@ -500,18 +399,18 @@ export class Humidifier {
|
|
|
500
399
|
id: this.device.bleMac,
|
|
501
400
|
})
|
|
502
401
|
.then(async (device_list: any) => {
|
|
503
|
-
this.infoLog(`${this.accessory.displayName}
|
|
504
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
402
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
403
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
505
404
|
})
|
|
506
405
|
.then(() => {
|
|
507
406
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
407
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
408
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
508
409
|
})
|
|
509
410
|
.catch(async (e: any) => {
|
|
510
411
|
this.apiError(e);
|
|
511
|
-
this.errorLog(
|
|
512
|
-
|
|
513
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
514
|
-
);
|
|
412
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
413
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
515
414
|
await this.BLEPushConnection();
|
|
516
415
|
});
|
|
517
416
|
}
|
|
@@ -519,13 +418,14 @@ export class Humidifier {
|
|
|
519
418
|
async openAPIpushChanges(): Promise<void> {
|
|
520
419
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
521
420
|
if (
|
|
522
|
-
this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
523
|
-
this.Active === this.hap.Characteristic.Active.ACTIVE
|
|
421
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
422
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
524
423
|
) {
|
|
525
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
425
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
526
426
|
const bodyChange = JSON.stringify({
|
|
527
427
|
command: 'setMode',
|
|
528
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
428
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
529
429
|
commandType: 'command',
|
|
530
430
|
});
|
|
531
431
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -543,20 +443,21 @@ export class Humidifier {
|
|
|
543
443
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
544
444
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
545
445
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
446
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
447
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
546
448
|
} else {
|
|
547
449
|
this.statusCode(statusCode);
|
|
548
450
|
this.statusCode(deviceStatus.statusCode);
|
|
549
451
|
}
|
|
550
452
|
} catch (e: any) {
|
|
551
453
|
this.apiError(e);
|
|
552
|
-
this.errorLog(
|
|
553
|
-
|
|
554
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
555
|
-
);
|
|
454
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
455
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
556
456
|
}
|
|
557
457
|
} else if (
|
|
558
|
-
this.TargetHumidifierDehumidifierState ===
|
|
559
|
-
this.
|
|
458
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
459
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
460
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
560
461
|
) {
|
|
561
462
|
await this.pushAutoChanges();
|
|
562
463
|
} else {
|
|
@@ -570,8 +471,9 @@ export class Humidifier {
|
|
|
570
471
|
async pushAutoChanges(): Promise<void> {
|
|
571
472
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
572
473
|
if (
|
|
573
|
-
this.TargetHumidifierDehumidifierState ===
|
|
574
|
-
this.
|
|
474
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
475
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
476
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
575
477
|
) {
|
|
576
478
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
577
479
|
const bodyChange = JSON.stringify({
|
|
@@ -594,22 +496,20 @@ export class Humidifier {
|
|
|
594
496
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
595
497
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
596
498
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
499
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
500
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
597
501
|
} else {
|
|
598
502
|
this.statusCode(statusCode);
|
|
599
503
|
this.statusCode(deviceStatus.statusCode);
|
|
600
504
|
}
|
|
601
505
|
} catch (e: any) {
|
|
602
506
|
this.apiError(e);
|
|
603
|
-
this.errorLog(
|
|
604
|
-
|
|
605
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
606
|
-
);
|
|
507
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
|
|
508
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
607
509
|
}
|
|
608
510
|
} else {
|
|
609
|
-
this.debugLog(
|
|
610
|
-
|
|
611
|
-
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`,
|
|
612
|
-
);
|
|
511
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
512
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
613
513
|
}
|
|
614
514
|
}
|
|
615
515
|
|
|
@@ -618,7 +518,7 @@ export class Humidifier {
|
|
|
618
518
|
*/
|
|
619
519
|
async pushActiveChanges(): Promise<void> {
|
|
620
520
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
621
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
521
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
622
522
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
623
523
|
const bodyChange = JSON.stringify({
|
|
624
524
|
command: 'turnOff',
|
|
@@ -640,19 +540,19 @@ export class Humidifier {
|
|
|
640
540
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
641
541
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
642
542
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
543
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
544
|
+
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
643
545
|
} else {
|
|
644
546
|
this.statusCode(statusCode);
|
|
645
547
|
this.statusCode(deviceStatus.statusCode);
|
|
646
548
|
}
|
|
647
549
|
} catch (e: any) {
|
|
648
550
|
this.apiError(e);
|
|
649
|
-
this.errorLog(
|
|
650
|
-
|
|
651
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
652
|
-
);
|
|
551
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
552
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
653
553
|
}
|
|
654
554
|
} else {
|
|
655
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
555
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
656
556
|
}
|
|
657
557
|
}
|
|
658
558
|
|
|
@@ -660,13 +560,13 @@ export class Humidifier {
|
|
|
660
560
|
* Handle requests to set the "Active" characteristic
|
|
661
561
|
*/
|
|
662
562
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
663
|
-
if (this.Active === this.accessory.context.Active) {
|
|
563
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
664
564
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
665
565
|
} else {
|
|
666
566
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
667
567
|
}
|
|
668
568
|
|
|
669
|
-
this.Active = value;
|
|
569
|
+
this.HumidifierDehumidifier.Active = value;
|
|
670
570
|
this.doHumidifierUpdate.next();
|
|
671
571
|
}
|
|
672
572
|
|
|
@@ -674,13 +574,13 @@ export class Humidifier {
|
|
|
674
574
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
675
575
|
*/
|
|
676
576
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
677
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
577
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
678
578
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
679
579
|
} else {
|
|
680
580
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
681
581
|
}
|
|
682
582
|
|
|
683
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
583
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
684
584
|
this.doHumidifierUpdate.next();
|
|
685
585
|
}
|
|
686
586
|
|
|
@@ -688,16 +588,16 @@ export class Humidifier {
|
|
|
688
588
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
689
589
|
*/
|
|
690
590
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
691
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
591
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
692
592
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
693
593
|
} else {
|
|
694
594
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
695
595
|
}
|
|
696
596
|
|
|
697
|
-
this.RelativeHumidityHumidifierThreshold = value;
|
|
698
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
699
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
700
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
597
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
598
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
599
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
600
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
701
601
|
}
|
|
702
602
|
this.doHumidifierUpdate.next();
|
|
703
603
|
}
|
|
@@ -706,117 +606,75 @@ export class Humidifier {
|
|
|
706
606
|
* Updates the status for each of the HomeKit Characteristics
|
|
707
607
|
*/
|
|
708
608
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
709
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
710
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
609
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
610
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
611
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
711
612
|
} else {
|
|
712
|
-
this.
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
613
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
614
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
615
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
616
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
617
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
717
618
|
}
|
|
718
619
|
if (this.OpenAPI) {
|
|
719
|
-
if (this.WaterLevel === undefined) {
|
|
720
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
620
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
621
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
721
622
|
} else {
|
|
722
|
-
this.
|
|
723
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
724
|
-
|
|
623
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
624
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
625
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
626
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
725
627
|
}
|
|
726
628
|
}
|
|
727
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
728
|
-
this.debugLog(
|
|
729
|
-
|
|
730
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
731
|
-
);
|
|
629
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
630
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
631
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
732
632
|
} else {
|
|
733
|
-
this.
|
|
734
|
-
this.
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
this.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
744
|
-
this.debugLog(
|
|
745
|
-
`${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
746
|
-
);
|
|
633
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
634
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
635
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
636
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
637
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
638
|
+
}
|
|
639
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
640
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
641
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
747
642
|
} else {
|
|
748
|
-
this.
|
|
749
|
-
this.
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
this.
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
);
|
|
756
|
-
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
757
|
-
}
|
|
758
|
-
if (this.Active === undefined) {
|
|
759
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
643
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
644
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
645
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
646
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
647
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
648
|
+
}
|
|
649
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
650
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
760
651
|
} else {
|
|
761
|
-
this.
|
|
762
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
763
|
-
this.accessory.context.Active = this.Active;
|
|
652
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
653
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
654
|
+
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
764
655
|
}
|
|
765
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
766
|
-
this.debugLog(
|
|
767
|
-
|
|
768
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
769
|
-
);
|
|
656
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
657
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
658
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
770
659
|
} else {
|
|
771
|
-
this.
|
|
772
|
-
this.
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
this.
|
|
776
|
-
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
777
|
-
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
778
|
-
);
|
|
779
|
-
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
660
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
661
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
663
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
664
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
780
665
|
}
|
|
781
666
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
782
|
-
if (this.CurrentTemperature === undefined) {
|
|
783
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
667
|
+
if (this.TemperatureSensor!.CurrentTemperature === undefined) {
|
|
668
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
784
669
|
} else {
|
|
785
|
-
this.
|
|
786
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
787
|
-
|
|
670
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
671
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
672
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
673
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
788
674
|
}
|
|
789
675
|
}
|
|
790
676
|
}
|
|
791
677
|
|
|
792
|
-
async stopScanning(switchbot: any) {
|
|
793
|
-
switchbot.stopScan();
|
|
794
|
-
if (this.connected) {
|
|
795
|
-
await this.BLEparseStatus();
|
|
796
|
-
await this.updateHomeKitCharacteristics();
|
|
797
|
-
} else {
|
|
798
|
-
await this.BLERefreshConnection(switchbot);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
async getCustomBLEAddress(switchbot: any) {
|
|
803
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
804
|
-
(async () => {
|
|
805
|
-
// Start to monitor advertisement packets
|
|
806
|
-
await switchbot.startScan({
|
|
807
|
-
model: 'e',
|
|
808
|
-
});
|
|
809
|
-
// Set an event handler
|
|
810
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
811
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
812
|
-
};
|
|
813
|
-
await sleep(10000);
|
|
814
|
-
// Stop to monitor
|
|
815
|
-
switchbot.stopScan();
|
|
816
|
-
})();
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
|
|
820
678
|
async BLEPushConnection() {
|
|
821
679
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
822
680
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -833,283 +691,28 @@ export class Humidifier {
|
|
|
833
691
|
}
|
|
834
692
|
}
|
|
835
693
|
|
|
836
|
-
minStep(): number {
|
|
837
|
-
if (this.device.humidifier?.set_minStep) {
|
|
838
|
-
this.set_minStep = this.device.humidifier?.set_minStep;
|
|
839
|
-
} else {
|
|
840
|
-
this.set_minStep = 1;
|
|
841
|
-
}
|
|
842
|
-
return this.set_minStep;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
async scan(device: device & devicesConfig): Promise<void> {
|
|
846
|
-
if (device.scanDuration) {
|
|
847
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
848
|
-
if (this.BLE) {
|
|
849
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
850
|
-
}
|
|
851
|
-
} else {
|
|
852
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
853
|
-
if (this.BLE) {
|
|
854
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
860
|
-
switch (statusCode) {
|
|
861
|
-
case 151:
|
|
862
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
863
|
-
break;
|
|
864
|
-
case 152:
|
|
865
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
866
|
-
break;
|
|
867
|
-
case 160:
|
|
868
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
869
|
-
break;
|
|
870
|
-
case 161:
|
|
871
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
872
|
-
this.offlineOff();
|
|
873
|
-
break;
|
|
874
|
-
case 171:
|
|
875
|
-
this.errorLog(
|
|
876
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
877
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
878
|
-
);
|
|
879
|
-
this.offlineOff();
|
|
880
|
-
break;
|
|
881
|
-
case 190:
|
|
882
|
-
this.errorLog(
|
|
883
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
884
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
885
|
-
);
|
|
886
|
-
break;
|
|
887
|
-
case 100:
|
|
888
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
889
|
-
break;
|
|
890
|
-
case 200:
|
|
891
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
892
|
-
break;
|
|
893
|
-
case 400:
|
|
894
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
895
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
896
|
-
break;
|
|
897
|
-
case 401:
|
|
898
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
899
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
900
|
-
break;
|
|
901
|
-
case 403:
|
|
902
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
903
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
904
|
-
break;
|
|
905
|
-
case 404:
|
|
906
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
907
|
-
+ `statusCode: ${statusCode}`);
|
|
908
|
-
break;
|
|
909
|
-
case 406:
|
|
910
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
911
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
912
|
-
break;
|
|
913
|
-
case 415:
|
|
914
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
915
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
916
|
-
break;
|
|
917
|
-
case 422:
|
|
918
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
919
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
920
|
-
break;
|
|
921
|
-
case 429:
|
|
922
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
923
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
924
|
-
break;
|
|
925
|
-
case 500:
|
|
926
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
927
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
928
|
-
break;
|
|
929
|
-
default:
|
|
930
|
-
this.infoLog(
|
|
931
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
932
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
933
|
-
);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
|
|
937
694
|
async offlineOff(): Promise<void> {
|
|
938
695
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
939
696
|
if (this.device.offline) {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
697
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
698
|
+
this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
699
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
700
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
701
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
945
702
|
}
|
|
946
703
|
}
|
|
947
704
|
|
|
948
705
|
async apiError(e: any): Promise<void> {
|
|
949
|
-
this.
|
|
706
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
950
707
|
if (!this.BLE) {
|
|
951
|
-
this.
|
|
708
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
952
709
|
}
|
|
953
|
-
this.
|
|
954
|
-
this.
|
|
955
|
-
this.
|
|
956
|
-
this.
|
|
710
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
711
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
712
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
713
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
957
714
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
958
|
-
this.
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
async deviceContext() {
|
|
963
|
-
if (this.Active === undefined) {
|
|
964
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
965
|
-
} else {
|
|
966
|
-
this.Active = this.accessory.context.Active;
|
|
967
|
-
}
|
|
968
|
-
if (this.CurrentTemperature === undefined) {
|
|
969
|
-
this.CurrentTemperature = 30;
|
|
970
|
-
} else {
|
|
971
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
972
|
-
}
|
|
973
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
974
|
-
this.CurrentRelativeHumidity = 0;
|
|
975
|
-
} else {
|
|
976
|
-
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
977
|
-
}
|
|
978
|
-
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
979
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
980
|
-
} else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
981
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
982
|
-
} else {
|
|
983
|
-
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
984
|
-
}
|
|
985
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
986
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
987
|
-
} else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
|
|
988
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
989
|
-
} else {
|
|
990
|
-
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
991
|
-
}
|
|
992
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
993
|
-
this.RelativeHumidityHumidifierThreshold = 0;
|
|
994
|
-
} else {
|
|
995
|
-
this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
|
|
996
|
-
}
|
|
997
|
-
if (this.WaterLevel === undefined) {
|
|
998
|
-
this.WaterLevel = 0;
|
|
999
|
-
} else {
|
|
1000
|
-
this.WaterLevel = this.accessory.context.WaterLevel;
|
|
1001
|
-
}
|
|
1002
|
-
if (this.FirmwareRevision === undefined) {
|
|
1003
|
-
this.FirmwareRevision = this.platform.version;
|
|
1004
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
715
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
1005
716
|
}
|
|
1006
717
|
}
|
|
1007
|
-
|
|
1008
|
-
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
1009
|
-
if (device.refreshRate) {
|
|
1010
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1011
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1012
|
-
} else if (this.platform.config.options!.refreshRate) {
|
|
1013
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
1014
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
1019
|
-
let config = {};
|
|
1020
|
-
if (device.humidifier) {
|
|
1021
|
-
config = device.humidifier;
|
|
1022
|
-
}
|
|
1023
|
-
if (device.connectionType !== undefined) {
|
|
1024
|
-
config['connectionType'] = device.connectionType;
|
|
1025
|
-
}
|
|
1026
|
-
if (device.external !== undefined) {
|
|
1027
|
-
config['external'] = device.external;
|
|
1028
|
-
}
|
|
1029
|
-
if (device.logging !== undefined) {
|
|
1030
|
-
config['logging'] = device.logging;
|
|
1031
|
-
}
|
|
1032
|
-
if (device.refreshRate !== undefined) {
|
|
1033
|
-
config['refreshRate'] = device.refreshRate;
|
|
1034
|
-
}
|
|
1035
|
-
if (device.scanDuration !== undefined) {
|
|
1036
|
-
config['scanDuration'] = device.scanDuration;
|
|
1037
|
-
}
|
|
1038
|
-
if (device.offline !== undefined) {
|
|
1039
|
-
config['offline'] = device.offline;
|
|
1040
|
-
}
|
|
1041
|
-
if (device.webhook !== undefined) {
|
|
1042
|
-
config['webhook'] = device.webhook;
|
|
1043
|
-
}
|
|
1044
|
-
if (Object.entries(config).length !== 0) {
|
|
1045
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
1050
|
-
if (this.platform.debugMode) {
|
|
1051
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1052
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1053
|
-
} else if (device.logging) {
|
|
1054
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1055
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1056
|
-
} else if (this.platform.config.options?.logging) {
|
|
1057
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1058
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1059
|
-
} else {
|
|
1060
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1061
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
/**
|
|
1066
|
-
* Logging for Device
|
|
1067
|
-
*/
|
|
1068
|
-
async infoLog(...log: any[]): Promise<void> {
|
|
1069
|
-
if (this.enablingDeviceLogging()) {
|
|
1070
|
-
this.platform.log.info(String(...log));
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
async warnLog(...log: any[]): Promise<void> {
|
|
1075
|
-
if (this.enablingDeviceLogging()) {
|
|
1076
|
-
this.platform.log.warn(String(...log));
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
async debugWarnLog(...log: any[]): Promise<void> {
|
|
1081
|
-
if (this.enablingDeviceLogging()) {
|
|
1082
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1083
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
async errorLog(...log: any[]): Promise<void> {
|
|
1089
|
-
if (this.enablingDeviceLogging()) {
|
|
1090
|
-
this.platform.log.error(String(...log));
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
async debugErrorLog(...log: any[]): Promise<void> {
|
|
1095
|
-
if (this.enablingDeviceLogging()) {
|
|
1096
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1097
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
async debugLog(...log: any[]): Promise<void> {
|
|
1103
|
-
if (this.enablingDeviceLogging()) {
|
|
1104
|
-
if (this.deviceLogging === 'debug') {
|
|
1105
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1106
|
-
} else {
|
|
1107
|
-
this.platform.log.debug(String(...log));
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
enablingDeviceLogging(): boolean {
|
|
1113
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1114
|
-
}
|
|
1115
718
|
}
|