@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +349 -756
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +584 -759
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +211 -587
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +252 -632
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +206 -531
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +337 -786
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +671 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +503 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +244 -596
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +209 -571
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +176 -584
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +254 -568
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +212 -542
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +172 -577
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +161 -577
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +138 -518
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +84 -452
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +142 -451
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +123 -664
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +512 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +343 -198
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +41 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +375 -782
- package/src/device/bot.ts +618 -844
- package/src/device/ceilinglight.ts +224 -607
- package/src/device/colorbulb.ts +266 -656
- package/src/device/contact.ts +231 -553
- package/src/device/curtain.ts +357 -810
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +552 -0
- package/src/device/hub.ts +271 -624
- package/src/device/humidifier.ts +239 -618
- package/src/device/iosensor.ts +202 -610
- package/src/device/lightstrip.ts +275 -596
- package/src/device/lock.ts +249 -582
- package/src/device/meter.ts +198 -601
- package/src/device/meterplus.ts +186 -602
- package/src/device/motion.ts +158 -541
- package/src/device/plug.ts +94 -480
- package/src/device/robotvacuumcleaner.ts +163 -477
- package/src/device/waterdetector.ts +141 -689
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +528 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +353 -206
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
package/src/device/humidifier.ts
CHANGED
|
@@ -1,119 +1,89 @@
|
|
|
1
1
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
2
|
+
import { deviceBase } from './device.js';
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform.js';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue
|
|
7
|
-
import { device, devicesConfig, serviceData, deviceStatus, Devices
|
|
6
|
+
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
+
import { device, devicesConfig, serviceData, deviceStatus, Devices } from '../settings.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Platform Accessory
|
|
11
11
|
* An instance of this class is created for each accessory your platform registers
|
|
12
12
|
* Each accessory may expose multiple services of different service types.
|
|
13
13
|
*/
|
|
14
|
-
export class Humidifier {
|
|
15
|
-
public readonly api: API;
|
|
16
|
-
public readonly log: Logging;
|
|
17
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
18
|
-
protected readonly hap: HAP;
|
|
14
|
+
export class Humidifier extends deviceBase {
|
|
19
15
|
// Services
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
OpenAPI_Active: deviceStatus['power'];
|
|
35
|
-
OpenAPI_WaterLevel: deviceStatus['lackWater'];
|
|
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;
|
|
16
|
+
private HumidifierDehumidifier: {
|
|
17
|
+
Service: Service;
|
|
18
|
+
Active: CharacteristicValue;
|
|
19
|
+
WaterLevel: CharacteristicValue;
|
|
20
|
+
CurrentRelativeHumidity: CharacteristicValue;
|
|
21
|
+
TargetHumidifierDehumidifierState: CharacteristicValue;
|
|
22
|
+
CurrentHumidifierDehumidifierState: CharacteristicValue;
|
|
23
|
+
RelativeHumidityHumidifierThreshold: CharacteristicValue;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
private TemperatureSensor?: {
|
|
27
|
+
Service: Service;
|
|
28
|
+
CurrentTemperature: CharacteristicValue;
|
|
29
|
+
};
|
|
53
30
|
|
|
54
31
|
// Updates
|
|
55
32
|
humidifierUpdateInProgress!: boolean;
|
|
56
33
|
doHumidifierUpdate!: Subject<void>;
|
|
57
34
|
|
|
58
|
-
// Connection
|
|
59
|
-
private readonly OpenAPI: boolean;
|
|
60
|
-
private readonly BLE: boolean;
|
|
61
|
-
|
|
62
35
|
constructor(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
36
|
+
readonly platform: SwitchBotPlatform,
|
|
37
|
+
accessory: PlatformAccessory,
|
|
38
|
+
device: device & devicesConfig,
|
|
66
39
|
) {
|
|
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
|
-
|
|
40
|
+
super(platform, accessory, device);
|
|
81
41
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
82
42
|
this.doHumidifierUpdate = new Subject();
|
|
83
43
|
this.humidifierUpdateInProgress = false;
|
|
84
44
|
|
|
45
|
+
// Initialize the HumidifierDehumidifier Service
|
|
46
|
+
this.HumidifierDehumidifier = {
|
|
47
|
+
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)!,
|
|
48
|
+
Active: accessory.context.Active || this.hap.Characteristic.Active.ACTIVE,
|
|
49
|
+
WaterLevel: accessory.context.WaterLevel || 100,
|
|
50
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity || 50,
|
|
51
|
+
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
52
|
+
|| this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
53
|
+
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
54
|
+
|| this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
55
|
+
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold || 50,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Initialize the Temperature Sensor Service
|
|
59
|
+
if (!device.humidifier?.hide_temperature) {
|
|
60
|
+
this.TemperatureSensor = {
|
|
61
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor)!,
|
|
62
|
+
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
85
66
|
// Retrieve initial values and updateHomekit
|
|
86
67
|
this.refreshStatus();
|
|
87
68
|
|
|
88
|
-
// set accessory information
|
|
89
|
-
accessory
|
|
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);
|
|
95
|
-
|
|
96
69
|
// get the service if it exists, otherwise create a new service
|
|
97
70
|
// you can create multiple services for each accessory
|
|
98
|
-
const
|
|
99
|
-
(this.
|
|
100
|
-
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)),
|
|
71
|
+
const HumidifierDehumidifierService = `${accessory.displayName} Humidifier`;
|
|
72
|
+
(this.HumidifierDehumidifier.Service = accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
73
|
+
|| accessory.addService(this.hap.Service.HumidifierDehumidifier)), HumidifierDehumidifierService;
|
|
101
74
|
|
|
102
|
-
this.
|
|
103
|
-
if (!this.humidifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
104
|
-
this.humidifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
105
|
-
}
|
|
75
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
106
76
|
|
|
107
77
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
108
78
|
// see https://developers.homebridge.io/#/service/HumidifierDehumidifier
|
|
109
79
|
|
|
110
80
|
// create handlers for required characteristics
|
|
111
|
-
this.
|
|
81
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(
|
|
112
82
|
this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
113
|
-
this.CurrentHumidifierDehumidifierState,
|
|
83
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState,
|
|
114
84
|
);
|
|
115
85
|
|
|
116
|
-
this.
|
|
86
|
+
this.HumidifierDehumidifier.Service
|
|
117
87
|
.getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState)
|
|
118
88
|
.setProps({
|
|
119
89
|
validValueRanges: [0, 1],
|
|
@@ -123,34 +93,31 @@ export class Humidifier {
|
|
|
123
93
|
})
|
|
124
94
|
.onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
|
|
125
95
|
|
|
126
|
-
this.
|
|
96
|
+
this.HumidifierDehumidifier.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
127
97
|
|
|
128
|
-
this.
|
|
98
|
+
this.HumidifierDehumidifier.Service
|
|
129
99
|
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
130
100
|
.setProps({
|
|
131
101
|
validValueRanges: [0, 100],
|
|
132
102
|
minValue: 0,
|
|
133
103
|
maxValue: 100,
|
|
134
|
-
minStep: this.minStep(),
|
|
104
|
+
minStep: this.minStep(device),
|
|
135
105
|
})
|
|
136
106
|
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
137
107
|
|
|
138
108
|
// Temperature Sensor Service
|
|
139
109
|
if (device.humidifier?.hide_temperature || this.BLE) {
|
|
140
110
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
141
|
-
this.
|
|
142
|
-
accessory.removeService(this.
|
|
143
|
-
} else if (!this.
|
|
111
|
+
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
112
|
+
accessory.removeService(this.TemperatureSensor!.Service);
|
|
113
|
+
} else if (!this.TemperatureSensor?.Service && !this.BLE) {
|
|
144
114
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
145
|
-
const
|
|
146
|
-
(this.
|
|
147
|
-
|| this.accessory.addService(this.hap.Service.TemperatureSensor)),
|
|
115
|
+
const TemperatureSensorService = `${accessory.displayName} Temperature Sensor`;
|
|
116
|
+
(this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
117
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), TemperatureSensorService;
|
|
148
118
|
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
this.temperatureservice.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
152
|
-
}
|
|
153
|
-
this.temperatureservice
|
|
119
|
+
this.TemperatureSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, TemperatureSensorService);
|
|
120
|
+
this.TemperatureSensor!.Service
|
|
154
121
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
155
122
|
.setProps({
|
|
156
123
|
validValueRanges: [-273.15, 100],
|
|
@@ -159,7 +126,7 @@ export class Humidifier {
|
|
|
159
126
|
minStep: 0.1,
|
|
160
127
|
})
|
|
161
128
|
.onGet(() => {
|
|
162
|
-
return this.CurrentTemperature;
|
|
129
|
+
return this.TemperatureSensor!.CurrentTemperature;
|
|
163
130
|
});
|
|
164
131
|
} else {
|
|
165
132
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
@@ -176,20 +143,23 @@ export class Humidifier {
|
|
|
176
143
|
});
|
|
177
144
|
|
|
178
145
|
//regisiter webhook event handler
|
|
179
|
-
if (
|
|
180
|
-
this.
|
|
146
|
+
if (device.webhook) {
|
|
147
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
181
148
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
182
149
|
try {
|
|
183
150
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
184
151
|
if (context.scale === 'CELSIUS') {
|
|
185
152
|
const { temperature, humidity } = context;
|
|
186
|
-
const {
|
|
153
|
+
const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
|
|
154
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
187
155
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
188
156
|
'(temperature, humidity) = ' +
|
|
189
157
|
`Webhook:(${temperature}, ${humidity}), ` +
|
|
190
158
|
`current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
191
|
-
this.CurrentRelativeHumidity = humidity;
|
|
192
|
-
this.
|
|
159
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
|
|
160
|
+
if (!this.device.humidifier?.hide_temperature) {
|
|
161
|
+
this.TemperatureSensor!.CurrentTemperature = temperature;
|
|
162
|
+
}
|
|
193
163
|
this.updateHomeKitCharacteristics();
|
|
194
164
|
}
|
|
195
165
|
} catch (e: any) {
|
|
@@ -222,105 +192,93 @@ export class Humidifier {
|
|
|
222
192
|
});
|
|
223
193
|
}
|
|
224
194
|
|
|
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> {
|
|
195
|
+
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
244
196
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
197
|
+
// Target Humidifier Dehumidifier State
|
|
198
|
+
if (serviceData.autoMode) {
|
|
199
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
200
|
+
}
|
|
245
201
|
// Current Relative Humidity
|
|
246
|
-
this.CurrentRelativeHumidity =
|
|
247
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
202
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage!;
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
204
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
248
205
|
// Active
|
|
249
|
-
if (
|
|
250
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
206
|
+
if (serviceData.onState) {
|
|
207
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
251
208
|
} else {
|
|
252
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
209
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
253
210
|
}
|
|
254
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
255
212
|
}
|
|
256
213
|
|
|
257
|
-
async openAPIparseStatus(): Promise<void> {
|
|
214
|
+
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
258
215
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
259
216
|
// Current Relative Humidity
|
|
260
|
-
this.CurrentRelativeHumidity =
|
|
261
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
217
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature!;
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
219
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
262
220
|
// Current Temperature
|
|
263
221
|
if (!this.device.humidifier?.hide_temperature) {
|
|
264
|
-
this.CurrentTemperature =
|
|
265
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
222
|
+
this.TemperatureSensor!.CurrentTemperature = deviceStatus.body.temperature!;
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
266
224
|
}
|
|
267
225
|
// Target Humidifier Dehumidifier State
|
|
268
|
-
switch (
|
|
226
|
+
switch (deviceStatus.body.auto) {
|
|
269
227
|
case true:
|
|
270
|
-
this.TargetHumidifierDehumidifierState =
|
|
271
|
-
|
|
272
|
-
this.
|
|
228
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
|
|
229
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
|
|
230
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
231
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
273
232
|
break;
|
|
274
233
|
default:
|
|
275
|
-
this.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
276
|
-
if (
|
|
277
|
-
this.RelativeHumidityHumidifierThreshold = 100;
|
|
234
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
235
|
+
if (deviceStatus.body.nebulizationEfficiency! > 100) {
|
|
236
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
|
|
278
237
|
} else {
|
|
279
|
-
this.RelativeHumidityHumidifierThreshold =
|
|
238
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency!;
|
|
280
239
|
}
|
|
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;
|
|
240
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
241
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
242
|
+
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
243
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
285
244
|
} else {
|
|
286
|
-
this.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
245
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
287
246
|
}
|
|
288
247
|
}
|
|
289
|
-
this.debugLog(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`
|
|
295
|
-
);
|
|
296
|
-
this.debugLog(
|
|
297
|
-
`${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
298
|
-
);
|
|
248
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
249
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
251
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
252
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
253
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
299
254
|
// Active
|
|
300
|
-
switch (
|
|
255
|
+
switch (deviceStatus.body.power) {
|
|
301
256
|
case 'on':
|
|
302
|
-
this.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
257
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
303
258
|
break;
|
|
304
259
|
default:
|
|
305
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
260
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
306
261
|
}
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
308
263
|
// Water Level
|
|
309
|
-
if (
|
|
310
|
-
this.WaterLevel = 0;
|
|
264
|
+
if (deviceStatus.body.lackWater) {
|
|
265
|
+
this.HumidifierDehumidifier.WaterLevel = 0;
|
|
311
266
|
} else {
|
|
312
|
-
this.WaterLevel = 100;
|
|
267
|
+
this.HumidifierDehumidifier.WaterLevel = 100;
|
|
313
268
|
}
|
|
314
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
269
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
315
270
|
|
|
316
271
|
// FirmwareRevision
|
|
317
|
-
|
|
318
|
-
|
|
272
|
+
if (deviceStatus.body.version) {
|
|
273
|
+
this.accessory.context.version = deviceStatus.body.version;
|
|
274
|
+
this.accessory
|
|
275
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
276
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
277
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
278
|
+
.updateValue(this.accessory.context.version);
|
|
279
|
+
}
|
|
319
280
|
}
|
|
320
281
|
|
|
321
|
-
/**
|
|
322
|
-
* Asks the SwitchBot API for the latest device information
|
|
323
|
-
*/
|
|
324
282
|
async refreshStatus(): Promise<void> {
|
|
325
283
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
326
284
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -350,103 +308,43 @@ export class Humidifier {
|
|
|
350
308
|
// Start to monitor advertisement packets
|
|
351
309
|
(async () => {
|
|
352
310
|
// Start to monitor advertisement packets
|
|
353
|
-
await switchbot.startScan({
|
|
354
|
-
model: 'e',
|
|
355
|
-
id: this.device.bleMac,
|
|
356
|
-
});
|
|
311
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
357
312
|
// Set an event handler
|
|
358
313
|
switchbot.onadvertisement = (ad: any) => {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
314
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
315
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
362
317
|
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
318
|
} else {
|
|
367
319
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
368
320
|
}
|
|
369
321
|
};
|
|
370
|
-
// Wait
|
|
322
|
+
// Wait 10 seconds
|
|
371
323
|
await switchbot.wait(this.scanDuration * 1000);
|
|
372
324
|
// Stop to monitor
|
|
373
325
|
await switchbot.stopScan();
|
|
374
326
|
// Update HomeKit
|
|
375
|
-
await this.BLEparseStatus();
|
|
327
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
376
328
|
await this.updateHomeKitCharacteristics();
|
|
377
329
|
})();
|
|
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 {
|
|
330
|
+
if (switchbot === undefined) {
|
|
425
331
|
await this.BLERefreshConnection(switchbot);
|
|
426
|
-
}
|
|
332
|
+
}
|
|
427
333
|
}
|
|
428
334
|
|
|
429
335
|
async openAPIRefreshStatus(): Promise<void> {
|
|
430
336
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
431
337
|
try {
|
|
432
|
-
const { body, statusCode } = await
|
|
433
|
-
headers: this.platform.generateHeaders()
|
|
434
|
-
});
|
|
338
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
339
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
435
340
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
436
341
|
const deviceStatus: any = await body.json();
|
|
437
342
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
438
343
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
439
344
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
440
|
-
this.
|
|
345
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
441
346
|
+ `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();
|
|
347
|
+
this.openAPIparseStatus(deviceStatus);
|
|
450
348
|
this.updateHomeKitCharacteristics();
|
|
451
349
|
} else {
|
|
452
350
|
this.statusCode(statusCode);
|
|
@@ -500,11 +398,13 @@ export class Humidifier {
|
|
|
500
398
|
id: this.device.bleMac,
|
|
501
399
|
})
|
|
502
400
|
.then(async (device_list: any) => {
|
|
503
|
-
this.infoLog(`${this.accessory.displayName}
|
|
504
|
-
return await device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
|
|
401
|
+
this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
402
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
505
403
|
})
|
|
506
404
|
.then(() => {
|
|
507
405
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
406
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
407
|
+
+ `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
|
|
508
408
|
})
|
|
509
409
|
.catch(async (e: any) => {
|
|
510
410
|
this.apiError(e);
|
|
@@ -519,13 +419,14 @@ export class Humidifier {
|
|
|
519
419
|
async openAPIpushChanges(): Promise<void> {
|
|
520
420
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
521
421
|
if (
|
|
522
|
-
this.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
523
|
-
this.Active === this.hap.Characteristic.Active.ACTIVE
|
|
422
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
423
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
524
424
|
) {
|
|
525
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
425
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
426
|
+
+ ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
|
|
526
427
|
const bodyChange = JSON.stringify({
|
|
527
428
|
command: 'setMode',
|
|
528
|
-
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
429
|
+
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
529
430
|
commandType: 'command',
|
|
530
431
|
});
|
|
531
432
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -543,6 +444,8 @@ export class Humidifier {
|
|
|
543
444
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
544
445
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
545
446
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
447
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
448
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
546
449
|
} else {
|
|
547
450
|
this.statusCode(statusCode);
|
|
548
451
|
this.statusCode(deviceStatus.statusCode);
|
|
@@ -555,8 +458,9 @@ export class Humidifier {
|
|
|
555
458
|
);
|
|
556
459
|
}
|
|
557
460
|
} else if (
|
|
558
|
-
this.TargetHumidifierDehumidifierState ===
|
|
559
|
-
this.
|
|
461
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
462
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
463
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
560
464
|
) {
|
|
561
465
|
await this.pushAutoChanges();
|
|
562
466
|
} else {
|
|
@@ -570,8 +474,9 @@ export class Humidifier {
|
|
|
570
474
|
async pushAutoChanges(): Promise<void> {
|
|
571
475
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
572
476
|
if (
|
|
573
|
-
this.TargetHumidifierDehumidifierState ===
|
|
574
|
-
this.
|
|
477
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
478
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
479
|
+
this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE
|
|
575
480
|
) {
|
|
576
481
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
577
482
|
const bodyChange = JSON.stringify({
|
|
@@ -594,6 +499,8 @@ export class Humidifier {
|
|
|
594
499
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
595
500
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
596
501
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
502
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
503
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
597
504
|
} else {
|
|
598
505
|
this.statusCode(statusCode);
|
|
599
506
|
this.statusCode(deviceStatus.statusCode);
|
|
@@ -606,10 +513,8 @@ export class Humidifier {
|
|
|
606
513
|
);
|
|
607
514
|
}
|
|
608
515
|
} else {
|
|
609
|
-
this.debugLog(
|
|
610
|
-
|
|
611
|
-
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`,
|
|
612
|
-
);
|
|
516
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
|
|
517
|
+
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
613
518
|
}
|
|
614
519
|
}
|
|
615
520
|
|
|
@@ -618,7 +523,7 @@ export class Humidifier {
|
|
|
618
523
|
*/
|
|
619
524
|
async pushActiveChanges(): Promise<void> {
|
|
620
525
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
621
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
526
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
622
527
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
623
528
|
const bodyChange = JSON.stringify({
|
|
624
529
|
command: 'turnOff',
|
|
@@ -640,6 +545,8 @@ export class Humidifier {
|
|
|
640
545
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
641
546
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
642
547
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
548
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
549
|
+
+ `request to SwitchBot API, body: ${deviceStatus} sent successfully`);
|
|
643
550
|
} else {
|
|
644
551
|
this.statusCode(statusCode);
|
|
645
552
|
this.statusCode(deviceStatus.statusCode);
|
|
@@ -652,7 +559,7 @@ export class Humidifier {
|
|
|
652
559
|
);
|
|
653
560
|
}
|
|
654
561
|
} else {
|
|
655
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
562
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
|
|
656
563
|
}
|
|
657
564
|
}
|
|
658
565
|
|
|
@@ -660,13 +567,13 @@ export class Humidifier {
|
|
|
660
567
|
* Handle requests to set the "Active" characteristic
|
|
661
568
|
*/
|
|
662
569
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
663
|
-
if (this.Active === this.accessory.context.Active) {
|
|
570
|
+
if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
|
|
664
571
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
|
|
665
572
|
} else {
|
|
666
573
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
667
574
|
}
|
|
668
575
|
|
|
669
|
-
this.Active = value;
|
|
576
|
+
this.HumidifierDehumidifier.Active = value;
|
|
670
577
|
this.doHumidifierUpdate.next();
|
|
671
578
|
}
|
|
672
579
|
|
|
@@ -674,13 +581,13 @@ export class Humidifier {
|
|
|
674
581
|
* Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
|
|
675
582
|
*/
|
|
676
583
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
677
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
584
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
678
585
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
679
586
|
} else {
|
|
680
587
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
|
|
681
588
|
}
|
|
682
589
|
|
|
683
|
-
this.TargetHumidifierDehumidifierState = value;
|
|
590
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
|
|
684
591
|
this.doHumidifierUpdate.next();
|
|
685
592
|
}
|
|
686
593
|
|
|
@@ -688,16 +595,16 @@ export class Humidifier {
|
|
|
688
595
|
* Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
|
|
689
596
|
*/
|
|
690
597
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
691
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
598
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
692
599
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
693
600
|
} else {
|
|
694
601
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
|
|
695
602
|
}
|
|
696
603
|
|
|
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;
|
|
604
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
|
|
605
|
+
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
606
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
|
|
607
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
|
|
701
608
|
}
|
|
702
609
|
this.doHumidifierUpdate.next();
|
|
703
610
|
}
|
|
@@ -706,117 +613,76 @@ export class Humidifier {
|
|
|
706
613
|
* Updates the status for each of the HomeKit Characteristics
|
|
707
614
|
*/
|
|
708
615
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
709
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
710
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
616
|
+
if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
|
|
617
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
618
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
711
619
|
} else {
|
|
712
|
-
this.
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
620
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
621
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity);
|
|
622
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
623
|
+
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
624
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
|
|
717
625
|
}
|
|
718
626
|
if (this.OpenAPI) {
|
|
719
|
-
if (this.WaterLevel === undefined) {
|
|
720
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
627
|
+
if (this.HumidifierDehumidifier.WaterLevel === undefined) {
|
|
628
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
721
629
|
} else {
|
|
722
|
-
this.
|
|
723
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
724
|
-
|
|
630
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
|
|
631
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
632
|
+
+ ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
|
|
633
|
+
this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
|
|
725
634
|
}
|
|
726
635
|
}
|
|
727
|
-
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
728
|
-
this.debugLog(
|
|
729
|
-
|
|
730
|
-
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
731
|
-
);
|
|
636
|
+
if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
|
|
637
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
638
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
732
639
|
} 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}`,
|
|
640
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
641
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
|
|
642
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
643
|
+
` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
644
|
+
this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
|
|
645
|
+
}
|
|
646
|
+
if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
|
|
647
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
648
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`,
|
|
746
649
|
);
|
|
747
650
|
} 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}`);
|
|
651
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
652
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
|
|
653
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
654
|
+
+ ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
|
|
655
|
+
this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
|
|
656
|
+
}
|
|
657
|
+
if (this.HumidifierDehumidifier.Active === undefined) {
|
|
658
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
|
|
760
659
|
} else {
|
|
761
|
-
this.
|
|
762
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
763
|
-
this.accessory.context.Active = this.Active;
|
|
660
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
|
|
661
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
|
|
662
|
+
this.accessory.context.Active = this.HumidifierDehumidifier.Active;
|
|
764
663
|
}
|
|
765
|
-
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
766
|
-
this.debugLog(
|
|
767
|
-
|
|
768
|
-
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
769
|
-
);
|
|
664
|
+
if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
|
|
665
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
666
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
770
667
|
} 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;
|
|
668
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
669
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
|
|
670
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
|
|
671
|
+
` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
|
|
672
|
+
this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
780
673
|
}
|
|
781
674
|
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}`);
|
|
675
|
+
if (this.TemperatureSensor!.CurrentTemperature === undefined) {
|
|
676
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
784
677
|
} else {
|
|
785
|
-
this.
|
|
786
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
787
|
-
|
|
678
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
679
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
680
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
681
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
788
682
|
}
|
|
789
683
|
}
|
|
790
684
|
}
|
|
791
685
|
|
|
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
686
|
async BLEPushConnection() {
|
|
821
687
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
822
688
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -833,283 +699,38 @@ export class Humidifier {
|
|
|
833
699
|
}
|
|
834
700
|
}
|
|
835
701
|
|
|
836
|
-
minStep(): number {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
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
|
-
}
|
|
702
|
+
minStep(device: device & devicesConfig): number {
|
|
703
|
+
let set_minStep: number;
|
|
704
|
+
if (device.humidifier?.set_minStep) {
|
|
705
|
+
set_minStep = device.humidifier?.set_minStep;
|
|
851
706
|
} else {
|
|
852
|
-
|
|
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
|
-
);
|
|
707
|
+
set_minStep = 1;
|
|
934
708
|
}
|
|
709
|
+
return set_minStep;
|
|
935
710
|
}
|
|
936
711
|
|
|
937
712
|
async offlineOff(): Promise<void> {
|
|
938
713
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
|
|
939
714
|
if (this.device.offline) {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
715
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
716
|
+
this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
|
|
717
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
718
|
+
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
719
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
945
720
|
}
|
|
946
721
|
}
|
|
947
722
|
|
|
948
723
|
async apiError(e: any): Promise<void> {
|
|
949
|
-
this.
|
|
724
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
950
725
|
if (!this.BLE) {
|
|
951
|
-
this.
|
|
726
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
|
|
952
727
|
}
|
|
953
|
-
this.
|
|
954
|
-
this.
|
|
955
|
-
this.
|
|
956
|
-
this.
|
|
728
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
|
|
729
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
|
|
730
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
731
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
|
|
957
732
|
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;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
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}`);
|
|
733
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
1015
734
|
}
|
|
1016
735
|
}
|
|
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
736
|
}
|