@switchbot/homebridge-switchbot 3.7.1-beta.11 → 3.7.1-beta.13
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/dist/device/blindtilt.d.ts +8 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +34 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +61 -97
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +5 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +36 -71
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +22 -37
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +142 -146
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +54 -47
- package/src/device/blindtilt.ts +419 -456
- package/src/device/bot.ts +656 -693
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +400 -435
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +169 -184
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +280 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1282 -1281
- package/src/settings.ts +170 -170
- package/src/types/bledevicestatus.ts +255 -255
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -127
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
package/src/device/humidifier.ts
CHANGED
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
*
|
|
3
3
|
* humidifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { humidifierServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { humidifierStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { humidifierWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
7
14
|
/*
|
|
8
15
|
* For Testing Locally:
|
|
9
16
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
17
|
*/
|
|
11
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
12
|
-
import {
|
|
18
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
13
20
|
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import type { SwitchBotPlatform } from '../platform.js';
|
|
17
|
-
import type { humidifierServiceData } from '../types/bledevicestatus.js';
|
|
18
|
-
import type { humidifierStatus } from '../types/devicestatus.js';
|
|
19
|
-
import type { humidifierWebhookContext } from '../types/devicewebhookstatus.js';
|
|
20
|
-
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
21
|
+
import { convertUnits, validHumidity } from '../utils.js'
|
|
22
|
+
import { deviceBase } from './device.js'
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Platform Accessory
|
|
@@ -27,308 +29,276 @@ import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge
|
|
|
27
29
|
export class Humidifier extends deviceBase {
|
|
28
30
|
// Services
|
|
29
31
|
private HumidifierDehumidifier: {
|
|
30
|
-
Name: CharacteristicValue
|
|
31
|
-
Service: Service
|
|
32
|
-
Active: CharacteristicValue
|
|
33
|
-
WaterLevel: CharacteristicValue
|
|
34
|
-
CurrentRelativeHumidity: CharacteristicValue
|
|
35
|
-
TargetHumidifierDehumidifierState: CharacteristicValue
|
|
36
|
-
CurrentHumidifierDehumidifierState: CharacteristicValue
|
|
37
|
-
RelativeHumidityHumidifierThreshold: CharacteristicValue
|
|
38
|
-
}
|
|
32
|
+
Name: CharacteristicValue
|
|
33
|
+
Service: Service
|
|
34
|
+
Active: CharacteristicValue
|
|
35
|
+
WaterLevel: CharacteristicValue
|
|
36
|
+
CurrentRelativeHumidity: CharacteristicValue
|
|
37
|
+
TargetHumidifierDehumidifierState: CharacteristicValue
|
|
38
|
+
CurrentHumidifierDehumidifierState: CharacteristicValue
|
|
39
|
+
RelativeHumidityHumidifierThreshold: CharacteristicValue
|
|
40
|
+
}
|
|
39
41
|
|
|
40
42
|
private TemperatureSensor?: {
|
|
41
|
-
Name: CharacteristicValue
|
|
42
|
-
Service: Service
|
|
43
|
-
CurrentTemperature: CharacteristicValue
|
|
44
|
-
}
|
|
43
|
+
Name: CharacteristicValue
|
|
44
|
+
Service: Service
|
|
45
|
+
CurrentTemperature: CharacteristicValue
|
|
46
|
+
}
|
|
45
47
|
|
|
46
48
|
// OpenAPI
|
|
47
|
-
deviceStatus!: humidifierStatus
|
|
49
|
+
deviceStatus!: humidifierStatus
|
|
48
50
|
|
|
49
|
-
//Webhook
|
|
50
|
-
webhookContext!: humidifierWebhookContext
|
|
51
|
+
// Webhook
|
|
52
|
+
webhookContext!: humidifierWebhookContext
|
|
51
53
|
|
|
52
54
|
// BLE
|
|
53
|
-
serviceData!: humidifierServiceData
|
|
55
|
+
serviceData!: humidifierServiceData
|
|
54
56
|
|
|
55
57
|
// Updates
|
|
56
|
-
humidifierUpdateInProgress!: boolean
|
|
57
|
-
doHumidifierUpdate!: Subject<void
|
|
58
|
+
humidifierUpdateInProgress!: boolean
|
|
59
|
+
doHumidifierUpdate!: Subject<void>
|
|
58
60
|
|
|
59
61
|
constructor(
|
|
60
62
|
readonly platform: SwitchBotPlatform,
|
|
61
63
|
accessory: PlatformAccessory,
|
|
62
64
|
device: device & devicesConfig,
|
|
63
65
|
) {
|
|
64
|
-
super(platform, accessory, device)
|
|
66
|
+
super(platform, accessory, device)
|
|
65
67
|
// Set category
|
|
66
|
-
accessory.category = this.hap.Categories.AIR_HUMIDIFIER
|
|
68
|
+
accessory.category = this.hap.Categories.AIR_HUMIDIFIER
|
|
67
69
|
|
|
68
70
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
69
|
-
this.doHumidifierUpdate = new Subject()
|
|
70
|
-
this.humidifierUpdateInProgress = false
|
|
71
|
+
this.doHumidifierUpdate = new Subject()
|
|
72
|
+
this.humidifierUpdateInProgress = false
|
|
71
73
|
|
|
72
74
|
// Initialize the HumidifierDehumidifier Service
|
|
73
|
-
accessory.context.HumidifierDehumidifier = accessory.context.HumidifierDehumidifier ?? {}
|
|
75
|
+
accessory.context.HumidifierDehumidifier = accessory.context.HumidifierDehumidifier ?? {}
|
|
74
76
|
this.HumidifierDehumidifier = {
|
|
75
77
|
Name: accessory.displayName,
|
|
76
|
-
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier)
|
|
77
|
-
?? accessory.addService(this.hap.Service.HumidifierDehumidifier) as Service,
|
|
78
|
+
Service: accessory.getService(this.hap.Service.HumidifierDehumidifier) ?? accessory.addService(this.hap.Service.HumidifierDehumidifier) as Service,
|
|
78
79
|
Active: accessory.context.Active ?? this.hap.Characteristic.Active.ACTIVE,
|
|
79
80
|
WaterLevel: accessory.context.WaterLevel ?? 100,
|
|
80
81
|
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
81
|
-
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState
|
|
82
|
-
|
|
83
|
-
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState
|
|
84
|
-
?? this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
82
|
+
TargetHumidifierDehumidifierState: accessory.context.TargetHumidifierDehumidifierState ?? this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER,
|
|
83
|
+
CurrentHumidifierDehumidifierState: accessory.context.CurrentHumidifierDehumidifierState ?? this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE,
|
|
85
84
|
RelativeHumidityHumidifierThreshold: accessory.context.RelativeHumidityHumidifierThreshold ?? 50,
|
|
86
|
-
}
|
|
87
|
-
accessory.context.HumidifierDehumidifier = this.HumidifierDehumidifier as object
|
|
85
|
+
}
|
|
86
|
+
accessory.context.HumidifierDehumidifier = this.HumidifierDehumidifier as object
|
|
88
87
|
|
|
89
88
|
// Initialize the HumidifierDehumidifier Characteristics
|
|
90
|
-
this.HumidifierDehumidifier.Service
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.onSet(this.ActiveSet.bind(this));
|
|
112
|
-
|
|
113
|
-
this.HumidifierDehumidifier.Service
|
|
114
|
-
.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold)
|
|
115
|
-
.setProps({
|
|
116
|
-
validValueRanges: [0, 100],
|
|
117
|
-
minValue: 0,
|
|
118
|
-
maxValue: 100,
|
|
119
|
-
minStep: device.humidifier?.set_minStep ?? 1,
|
|
120
|
-
})
|
|
121
|
-
.onGet(() => {
|
|
122
|
-
return this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
|
|
123
|
-
})
|
|
124
|
-
.onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
|
|
89
|
+
this.HumidifierDehumidifier.Service.setCharacteristic(this.hap.Characteristic.Name, this.HumidifierDehumidifier.Name).setCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState).getCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState).setProps({
|
|
90
|
+
validValueRanges: [0, 1],
|
|
91
|
+
minValue: 0,
|
|
92
|
+
maxValue: 1,
|
|
93
|
+
validValues: [0, 1],
|
|
94
|
+
}).onGet(() => {
|
|
95
|
+
return this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
96
|
+
}).onSet(this.TargetHumidifierDehumidifierStateSet.bind(this))
|
|
97
|
+
|
|
98
|
+
this.HumidifierDehumidifier.Service.getCharacteristic(this.hap.Characteristic.Active).onGet(() => {
|
|
99
|
+
return this.HumidifierDehumidifier.Active
|
|
100
|
+
}).onSet(this.ActiveSet.bind(this))
|
|
101
|
+
|
|
102
|
+
this.HumidifierDehumidifier.Service.getCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold).setProps({
|
|
103
|
+
validValueRanges: [0, 100],
|
|
104
|
+
minValue: 0,
|
|
105
|
+
maxValue: 100,
|
|
106
|
+
minStep: device.humidifier?.set_minStep ?? 1,
|
|
107
|
+
}).onGet(() => {
|
|
108
|
+
return this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold
|
|
109
|
+
}).onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this))
|
|
125
110
|
|
|
126
111
|
// Initialize the Temperature Sensor Service
|
|
127
112
|
if (device.humidifier?.hide_temperature) {
|
|
128
113
|
if (this.TemperatureSensor) {
|
|
129
|
-
this.debugLog('Removing Temperature Sensor Service')
|
|
130
|
-
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service
|
|
131
|
-
accessory.removeService(this.TemperatureSensor!.Service)
|
|
114
|
+
this.debugLog('Removing Temperature Sensor Service')
|
|
115
|
+
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service
|
|
116
|
+
accessory.removeService(this.TemperatureSensor!.Service)
|
|
132
117
|
}
|
|
133
118
|
} else {
|
|
134
|
-
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {}
|
|
119
|
+
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {}
|
|
135
120
|
this.TemperatureSensor = {
|
|
136
121
|
Name: `${accessory.displayName} Temperature Sensor`,
|
|
137
122
|
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
138
123
|
CurrentTemperature: accessory.context.CurrentTemperature || 30,
|
|
139
|
-
}
|
|
140
|
-
accessory.context.TemperatureSensor = this.TemperatureSensor as object
|
|
124
|
+
}
|
|
125
|
+
accessory.context.TemperatureSensor = this.TemperatureSensor as object
|
|
141
126
|
|
|
142
127
|
// Initialize the Temperature Sensor Characteristics
|
|
143
|
-
this.TemperatureSensor.Service
|
|
144
|
-
.
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
})
|
|
152
|
-
.onGet(() => {
|
|
153
|
-
return this.TemperatureSensor!.CurrentTemperature;
|
|
154
|
-
});
|
|
128
|
+
this.TemperatureSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name).getCharacteristic(this.hap.Characteristic.CurrentTemperature).setProps({
|
|
129
|
+
validValueRanges: [-273.15, 100],
|
|
130
|
+
minValue: -273.15,
|
|
131
|
+
maxValue: 100,
|
|
132
|
+
minStep: 0.1,
|
|
133
|
+
}).onGet(() => {
|
|
134
|
+
return this.TemperatureSensor!.CurrentTemperature
|
|
135
|
+
})
|
|
155
136
|
}
|
|
156
137
|
|
|
157
138
|
// Retrieve initial values and updateHomekit
|
|
158
139
|
try {
|
|
159
|
-
this.debugLog('Retrieve initial values and update Homekit')
|
|
160
|
-
this.refreshStatus()
|
|
140
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
141
|
+
this.refreshStatus()
|
|
161
142
|
} catch (e: any) {
|
|
162
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
143
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
163
144
|
}
|
|
164
145
|
|
|
165
|
-
//regisiter webhook event handler if enabled
|
|
146
|
+
// regisiter webhook event handler if enabled
|
|
166
147
|
try {
|
|
167
|
-
this.debugLog('Registering Webhook Event Handler')
|
|
168
|
-
this.registerWebhook()
|
|
148
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
149
|
+
this.registerWebhook()
|
|
169
150
|
} catch (e: any) {
|
|
170
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
151
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
171
152
|
}
|
|
172
153
|
|
|
173
|
-
//regisiter platform BLE event handler if enabled
|
|
154
|
+
// regisiter platform BLE event handler if enabled
|
|
174
155
|
try {
|
|
175
|
-
this.debugLog('Registering Platform BLE Event Handler')
|
|
176
|
-
this.registerPlatformBLE()
|
|
156
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
157
|
+
this.registerPlatformBLE()
|
|
177
158
|
} catch (e: any) {
|
|
178
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
159
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
179
160
|
}
|
|
180
161
|
|
|
181
162
|
// Start an update interval
|
|
182
163
|
interval(this.deviceRefreshRate * 1000)
|
|
183
164
|
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
184
165
|
.subscribe(async () => {
|
|
185
|
-
await this.refreshStatus()
|
|
186
|
-
})
|
|
166
|
+
await this.refreshStatus()
|
|
167
|
+
})
|
|
187
168
|
|
|
188
169
|
// Watch for Humidifier change events
|
|
189
170
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
190
171
|
this.doHumidifierUpdate
|
|
191
172
|
.pipe(
|
|
192
173
|
tap(() => {
|
|
193
|
-
this.humidifierUpdateInProgress = true
|
|
174
|
+
this.humidifierUpdateInProgress = true
|
|
194
175
|
}),
|
|
195
176
|
debounceTime(this.devicePushRate * 1000),
|
|
196
177
|
)
|
|
197
178
|
.subscribe(async () => {
|
|
198
179
|
try {
|
|
199
|
-
await this.pushChanges()
|
|
180
|
+
await this.pushChanges()
|
|
200
181
|
} catch (e: any) {
|
|
201
|
-
await this.apiError(e)
|
|
202
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
182
|
+
await this.apiError(e)
|
|
183
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
203
184
|
}
|
|
204
|
-
this.humidifierUpdateInProgress = false
|
|
205
|
-
})
|
|
185
|
+
this.humidifierUpdateInProgress = false
|
|
186
|
+
})
|
|
206
187
|
}
|
|
207
188
|
|
|
208
189
|
async BLEparseStatus(): Promise<void> {
|
|
209
|
-
await this.debugLog('BLEparseStatus')
|
|
210
|
-
await this.debugLog(`(onState, percentage, autoMode) = BLE:(${this.serviceData.onState}, ${this.serviceData.percentage}
|
|
211
|
-
|
|
212
|
-
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`,
|
|
213
|
-
);
|
|
190
|
+
await this.debugLog('BLEparseStatus')
|
|
191
|
+
await this.debugLog(`(onState, percentage, autoMode) = BLE:(${this.serviceData.onState}, ${this.serviceData.percentage}, ${this.serviceData.autoMode}), current:(${this.HumidifierDehumidifier.Active}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`,
|
|
192
|
+
)
|
|
214
193
|
|
|
215
194
|
// Active
|
|
216
|
-
this.HumidifierDehumidifier.Active = this.serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE
|
|
217
|
-
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`)
|
|
195
|
+
this.HumidifierDehumidifier.Active = this.serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE
|
|
196
|
+
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`)
|
|
218
197
|
|
|
219
198
|
// Current Relative Humidity
|
|
220
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity)
|
|
221
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
199
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity)
|
|
200
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
222
201
|
|
|
223
202
|
// Target Humidifier Dehumidifier State
|
|
224
203
|
switch (this.serviceData.autoMode) {
|
|
225
204
|
case true:
|
|
226
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
227
|
-
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER
|
|
228
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
229
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity
|
|
230
|
-
break
|
|
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
|
|
209
|
+
break
|
|
231
210
|
default:
|
|
232
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER
|
|
233
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.serviceData.percentage > 100 ? 100 : this.serviceData.percentage
|
|
211
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER
|
|
212
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.serviceData.percentage > 100 ? 100 : this.serviceData.percentage
|
|
234
213
|
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
235
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
214
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
236
215
|
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
237
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE
|
|
216
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE
|
|
238
217
|
} else {
|
|
239
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
218
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
240
219
|
}
|
|
241
220
|
}
|
|
242
|
-
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}
|
|
243
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
244
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
221
|
+
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`)
|
|
245
222
|
}
|
|
246
223
|
|
|
247
224
|
async openAPIparseStatus(): Promise<void> {
|
|
248
|
-
await this.debugLog('openAPIparseStatus')
|
|
249
|
-
await this.debugLog(`(power, auto, temperature, lackWater, nebulizationEfficiency, version) = OpenAPI:(${this.deviceStatus.power}
|
|
250
|
-
+ ` ${this.deviceStatus.auto}, ${this.deviceStatus.temperature}, ${this.deviceStatus.lackWater},`
|
|
251
|
-
+ ` ${this.deviceStatus.nebulizationEfficiency}, ${this.deviceStatus.version}), current:(${this.HumidifierDehumidifier.Active},`
|
|
252
|
-
+ ` ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
|
|
253
|
-
+ ` ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`);
|
|
225
|
+
await this.debugLog('openAPIparseStatus')
|
|
226
|
+
await this.debugLog(`(power, auto, temperature, lackWater, nebulizationEfficiency, version) = OpenAPI:(${this.deviceStatus.power}, ${this.deviceStatus.auto}, ${this.deviceStatus.temperature}, ${this.deviceStatus.lackWater}, ${this.deviceStatus.nebulizationEfficiency}, ${this.deviceStatus.version}), current:(${this.HumidifierDehumidifier.Active}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`)
|
|
254
227
|
|
|
255
228
|
// Active
|
|
256
229
|
this.HumidifierDehumidifier.Active = this.deviceStatus.power === 'on'
|
|
257
|
-
? this.hap.Characteristic.Active.ACTIVE
|
|
258
|
-
|
|
230
|
+
? this.hap.Characteristic.Active.ACTIVE
|
|
231
|
+
: this.hap.Characteristic.Active.INACTIVE
|
|
232
|
+
await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`)
|
|
259
233
|
|
|
260
234
|
// Current Relative Humidity
|
|
261
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.deviceStatus.humidity)
|
|
262
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
235
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.deviceStatus.humidity)
|
|
236
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
263
237
|
|
|
264
238
|
// Current Temperature
|
|
265
239
|
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
266
|
-
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
267
|
-
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
240
|
+
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
241
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
268
242
|
}
|
|
269
243
|
// Target Humidifier Dehumidifier State
|
|
270
244
|
switch (this.deviceStatus.auto) {
|
|
271
245
|
case true:
|
|
272
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
273
|
-
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER
|
|
274
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
275
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity
|
|
276
|
-
break
|
|
246
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
247
|
+
= this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER
|
|
248
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
249
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity
|
|
250
|
+
break
|
|
277
251
|
default:
|
|
278
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER
|
|
252
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER
|
|
279
253
|
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.deviceStatus.nebulizationEfficiency > 100
|
|
280
|
-
? 100
|
|
254
|
+
? 100
|
|
255
|
+
: this.deviceStatus.nebulizationEfficiency
|
|
281
256
|
if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
|
|
282
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
257
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
283
258
|
} else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
284
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE
|
|
259
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE
|
|
285
260
|
} else {
|
|
286
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
261
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
287
262
|
}
|
|
288
263
|
}
|
|
289
|
-
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}
|
|
290
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
291
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
|
|
264
|
+
await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`)
|
|
292
265
|
|
|
293
266
|
// Water Level
|
|
294
267
|
if (this.deviceStatus.lackWater) {
|
|
295
|
-
this.HumidifierDehumidifier.WaterLevel = 0
|
|
268
|
+
this.HumidifierDehumidifier.WaterLevel = 0
|
|
296
269
|
} else {
|
|
297
|
-
this.HumidifierDehumidifier.WaterLevel = 100
|
|
270
|
+
this.HumidifierDehumidifier.WaterLevel = 100
|
|
298
271
|
}
|
|
299
|
-
await this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`)
|
|
272
|
+
await this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`)
|
|
300
273
|
|
|
301
274
|
// Firmware Version
|
|
302
275
|
if (this.deviceStatus.version) {
|
|
303
|
-
const version = this.deviceStatus.version.toString()
|
|
304
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
305
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
276
|
+
const version = this.deviceStatus.version.toString()
|
|
277
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
278
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
306
279
|
this.accessory
|
|
307
280
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
308
281
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
309
282
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
310
283
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
311
|
-
.updateValue(deviceVersion)
|
|
312
|
-
this.accessory.context.version = deviceVersion
|
|
313
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
284
|
+
.updateValue(deviceVersion)
|
|
285
|
+
this.accessory.context.version = deviceVersion
|
|
286
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
314
287
|
}
|
|
315
288
|
}
|
|
316
289
|
|
|
317
290
|
async parseStatusWebhook(): Promise<void> {
|
|
318
|
-
await this.debugLog('parseStatusWebhook')
|
|
319
|
-
await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
|
|
320
|
-
this.device.iosensor?.convertUnitTo)}, ${this.webhookContext.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature},`
|
|
321
|
-
+ ` ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
|
|
291
|
+
await this.debugLog('parseStatusWebhook')
|
|
292
|
+
await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.iosensor?.convertUnitTo)}, ${this.webhookContext.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`)
|
|
322
293
|
|
|
323
294
|
// CurrentRelativeHumidity
|
|
324
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.webhookContext.humidity)
|
|
325
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
295
|
+
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.webhookContext.humidity)
|
|
296
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
326
297
|
|
|
327
298
|
// CurrentTemperature
|
|
328
299
|
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
329
|
-
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
|
|
330
|
-
|
|
331
|
-
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
300
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.iosensor?.convertUnitTo)
|
|
301
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
332
302
|
}
|
|
333
303
|
}
|
|
334
304
|
|
|
@@ -337,95 +307,95 @@ export class Humidifier extends deviceBase {
|
|
|
337
307
|
*/
|
|
338
308
|
async refreshStatus(): Promise<void> {
|
|
339
309
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
340
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
310
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
341
311
|
} else if (this.BLE) {
|
|
342
|
-
await this.BLERefreshStatus()
|
|
312
|
+
await this.BLERefreshStatus()
|
|
343
313
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
344
|
-
await this.openAPIRefreshStatus()
|
|
314
|
+
await this.openAPIRefreshStatus()
|
|
345
315
|
} else {
|
|
346
|
-
await this.offlineOff()
|
|
347
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
316
|
+
await this.offlineOff()
|
|
317
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
348
318
|
}
|
|
349
319
|
}
|
|
350
320
|
|
|
351
321
|
async BLERefreshStatus(): Promise<void> {
|
|
352
|
-
await this.debugLog('BLERefreshStatus')
|
|
353
|
-
const switchbot = await this.switchbotBLE()
|
|
322
|
+
await this.debugLog('BLERefreshStatus')
|
|
323
|
+
const switchbot = await this.switchbotBLE()
|
|
354
324
|
if (switchbot === undefined) {
|
|
355
|
-
await this.BLERefreshConnection(switchbot)
|
|
325
|
+
await this.BLERefreshConnection(switchbot)
|
|
356
326
|
} else {
|
|
357
327
|
// Start to monitor advertisement packets
|
|
358
328
|
(async () => {
|
|
359
329
|
// Start to monitor advertisement packets
|
|
360
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData
|
|
330
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData
|
|
361
331
|
// Update HomeKit
|
|
362
332
|
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
363
|
-
this.serviceData = serviceData
|
|
364
|
-
await this.BLEparseStatus()
|
|
365
|
-
await this.updateHomeKitCharacteristics()
|
|
333
|
+
this.serviceData = serviceData
|
|
334
|
+
await this.BLEparseStatus()
|
|
335
|
+
await this.updateHomeKitCharacteristics()
|
|
366
336
|
} else {
|
|
367
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
368
|
-
await this.BLERefreshConnection(switchbot)
|
|
337
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
338
|
+
await this.BLERefreshConnection(switchbot)
|
|
369
339
|
}
|
|
370
|
-
})()
|
|
340
|
+
})()
|
|
371
341
|
}
|
|
372
342
|
}
|
|
373
343
|
|
|
374
344
|
async registerPlatformBLE(): Promise<void> {
|
|
375
|
-
await this.debugLog('registerPlatformBLE')
|
|
345
|
+
await this.debugLog('registerPlatformBLE')
|
|
376
346
|
if (this.config.options?.BLE) {
|
|
377
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
378
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
379
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
347
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
348
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
349
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
380
350
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: humidifierServiceData) => {
|
|
381
351
|
try {
|
|
382
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
383
|
-
this.serviceData = context
|
|
384
|
-
await this.BLEparseStatus()
|
|
385
|
-
await this.updateHomeKitCharacteristics()
|
|
352
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
353
|
+
this.serviceData = context
|
|
354
|
+
await this.BLEparseStatus()
|
|
355
|
+
await this.updateHomeKitCharacteristics()
|
|
386
356
|
} catch (e: any) {
|
|
387
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
357
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
388
358
|
}
|
|
389
|
-
}
|
|
359
|
+
}
|
|
390
360
|
} else {
|
|
391
|
-
await this.debugLog('is not listening to Platform BLE')
|
|
361
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
392
362
|
}
|
|
393
363
|
}
|
|
394
364
|
|
|
395
365
|
async openAPIRefreshStatus(): Promise<void> {
|
|
396
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
366
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
397
367
|
try {
|
|
398
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
399
|
-
const deviceStatus: any = await body.json()
|
|
400
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
368
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
369
|
+
const deviceStatus: any = await body.json()
|
|
370
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
401
371
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
402
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
403
|
-
this.deviceStatus = deviceStatus.body
|
|
404
|
-
await this.openAPIparseStatus()
|
|
405
|
-
await this.updateHomeKitCharacteristics()
|
|
372
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
|
+
this.deviceStatus = deviceStatus.body
|
|
374
|
+
await this.openAPIparseStatus()
|
|
375
|
+
await this.updateHomeKitCharacteristics()
|
|
406
376
|
} else {
|
|
407
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
408
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
377
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
409
379
|
}
|
|
410
380
|
} catch (e: any) {
|
|
411
|
-
await this.apiError(e)
|
|
412
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
381
|
+
await this.apiError(e)
|
|
382
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
413
383
|
}
|
|
414
384
|
}
|
|
415
385
|
|
|
416
386
|
async registerWebhook() {
|
|
417
387
|
if (this.device.webhook) {
|
|
418
|
-
await this.debugLog('is listening webhook.')
|
|
388
|
+
await this.debugLog('is listening webhook.')
|
|
419
389
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: humidifierWebhookContext) => {
|
|
420
390
|
try {
|
|
421
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
422
|
-
this.webhookContext = context
|
|
423
|
-
await this.parseStatusWebhook()
|
|
424
|
-
await this.updateHomeKitCharacteristics()
|
|
391
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
392
|
+
this.webhookContext = context
|
|
393
|
+
await this.parseStatusWebhook()
|
|
394
|
+
await this.updateHomeKitCharacteristics()
|
|
425
395
|
} catch (e: any) {
|
|
426
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
396
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
427
397
|
}
|
|
428
|
-
}
|
|
398
|
+
}
|
|
429
399
|
}
|
|
430
400
|
}
|
|
431
401
|
|
|
@@ -434,91 +404,86 @@ export class Humidifier extends deviceBase {
|
|
|
434
404
|
*/
|
|
435
405
|
async pushChanges(): Promise<void> {
|
|
436
406
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
437
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
407
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
438
408
|
} else if (this.BLE) {
|
|
439
|
-
await this.BLEpushChanges()
|
|
409
|
+
await this.BLEpushChanges()
|
|
440
410
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
441
|
-
await this.openAPIpushChanges()
|
|
411
|
+
await this.openAPIpushChanges()
|
|
442
412
|
} else {
|
|
443
|
-
await this.offlineOff()
|
|
444
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
413
|
+
await this.offlineOff()
|
|
414
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
445
415
|
}
|
|
446
416
|
// Refresh the status from the API
|
|
447
417
|
interval(15000)
|
|
448
418
|
.pipe(skipWhile(() => this.humidifierUpdateInProgress))
|
|
449
419
|
.pipe(take(1))
|
|
450
420
|
.subscribe(async () => {
|
|
451
|
-
await this.refreshStatus()
|
|
452
|
-
})
|
|
421
|
+
await this.refreshStatus()
|
|
422
|
+
})
|
|
453
423
|
}
|
|
454
424
|
|
|
455
425
|
async BLEpushChanges(): Promise<void> {
|
|
456
|
-
await this.debugLog('BLEpushChanges')
|
|
426
|
+
await this.debugLog('BLEpushChanges')
|
|
457
427
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
458
428
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
459
429
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
460
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
461
|
-
await this.convertBLEAddress()
|
|
430
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
431
|
+
await this.convertBLEAddress()
|
|
462
432
|
if (switchbot !== false) {
|
|
463
433
|
switchbot
|
|
464
434
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
465
435
|
.then(async (device_list: any) => {
|
|
466
|
-
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
|
|
436
|
+
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
|
|
467
437
|
})
|
|
468
438
|
.then(async () => {
|
|
469
|
-
await this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`
|
|
470
|
-
|
|
471
|
-
await this.updateHomeKitCharacteristics();
|
|
439
|
+
await this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold} sent over BLE, sent successfully`)
|
|
440
|
+
await this.updateHomeKitCharacteristics()
|
|
472
441
|
})
|
|
473
442
|
.catch(async (e: any) => {
|
|
474
|
-
await this.apiError(e)
|
|
475
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
476
|
-
await this.BLEPushConnection()
|
|
477
|
-
})
|
|
443
|
+
await this.apiError(e)
|
|
444
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
445
|
+
await this.BLEPushConnection()
|
|
446
|
+
})
|
|
478
447
|
} else {
|
|
479
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
480
|
-
await this.BLEPushConnection()
|
|
448
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
449
|
+
await this.BLEPushConnection()
|
|
481
450
|
}
|
|
482
451
|
} else {
|
|
483
|
-
await this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active}
|
|
484
|
-
+ ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
|
|
485
|
-
+ ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
|
|
452
|
+
await this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
486
453
|
}
|
|
487
454
|
}
|
|
488
455
|
|
|
489
456
|
async openAPIpushChanges(): Promise<void> {
|
|
490
|
-
await this.debugLog('openAPIpushChanges')
|
|
457
|
+
await this.debugLog('openAPIpushChanges')
|
|
491
458
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
492
459
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
493
460
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
494
|
-
await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`)
|
|
461
|
+
await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`)
|
|
495
462
|
const bodyChange = JSON.stringify({
|
|
496
463
|
command: 'setMode',
|
|
497
464
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
498
465
|
commandType: 'command',
|
|
499
|
-
})
|
|
500
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
466
|
+
})
|
|
467
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
501
468
|
try {
|
|
502
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
503
|
-
const deviceStatus: any = await body.json()
|
|
504
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
469
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
470
|
+
const deviceStatus: any = await body.json()
|
|
471
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
505
472
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
506
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
507
|
-
await this.updateHomeKitCharacteristics()
|
|
473
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
474
|
+
await this.updateHomeKitCharacteristics()
|
|
508
475
|
} else {
|
|
509
|
-
await this.statusCode(statusCode)
|
|
510
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
476
|
+
await this.statusCode(statusCode)
|
|
477
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
511
478
|
}
|
|
512
479
|
} catch (e: any) {
|
|
513
|
-
await this.apiError(e)
|
|
514
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
480
|
+
await this.apiError(e)
|
|
481
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
515
482
|
}
|
|
516
|
-
} else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
|
|
517
|
-
this.
|
|
518
|
-
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
519
|
-
await this.pushAutoChanges();
|
|
483
|
+
} else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER) && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
484
|
+
await this.pushAutoChanges()
|
|
520
485
|
} else {
|
|
521
|
-
await this.pushActiveChanges()
|
|
486
|
+
await this.pushActiveChanges()
|
|
522
487
|
}
|
|
523
488
|
}
|
|
524
489
|
|
|
@@ -526,35 +491,34 @@ export class Humidifier extends deviceBase {
|
|
|
526
491
|
* Pushes the requested changes to the SwitchBot API
|
|
527
492
|
*/
|
|
528
493
|
async pushAutoChanges(): Promise<void> {
|
|
529
|
-
this.debugLog('pushAutoChanges')
|
|
530
|
-
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
531
|
-
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
494
|
+
this.debugLog('pushAutoChanges')
|
|
495
|
+
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
496
|
+
=== this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
532
497
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
533
|
-
await this.debugLog('Pushing Auto')
|
|
498
|
+
await this.debugLog('Pushing Auto')
|
|
534
499
|
const bodyChange = JSON.stringify({
|
|
535
500
|
command: 'setMode',
|
|
536
501
|
parameter: 'auto',
|
|
537
502
|
commandType: 'command',
|
|
538
|
-
})
|
|
539
|
-
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
503
|
+
})
|
|
504
|
+
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
540
505
|
try {
|
|
541
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
542
|
-
const deviceStatus: any = await body.json()
|
|
543
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
506
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
507
|
+
const deviceStatus: any = await body.json()
|
|
508
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
544
509
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
545
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
546
|
-
await this.updateHomeKitCharacteristics()
|
|
510
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
511
|
+
await this.updateHomeKitCharacteristics()
|
|
547
512
|
} else {
|
|
548
|
-
await this.statusCode(statusCode)
|
|
549
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
513
|
+
await this.statusCode(statusCode)
|
|
514
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
550
515
|
}
|
|
551
516
|
} catch (e: any) {
|
|
552
|
-
await this.apiError(e)
|
|
553
|
-
await this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
517
|
+
await this.apiError(e)
|
|
518
|
+
await this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
554
519
|
}
|
|
555
520
|
} else {
|
|
556
|
-
await this.debugLog(
|
|
557
|
-
+ ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
|
|
521
|
+
await this.debugLog(`No changes (pushAutoChanges), TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`)
|
|
558
522
|
}
|
|
559
523
|
}
|
|
560
524
|
|
|
@@ -562,32 +526,32 @@ export class Humidifier extends deviceBase {
|
|
|
562
526
|
* Pushes the requested changes to the SwitchBot API
|
|
563
527
|
*/
|
|
564
528
|
async pushActiveChanges(): Promise<void> {
|
|
565
|
-
await this.debugLog('pushActiveChanges')
|
|
529
|
+
await this.debugLog('pushActiveChanges')
|
|
566
530
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
567
|
-
await this.debugLog('Pushing Off')
|
|
531
|
+
await this.debugLog('Pushing Off')
|
|
568
532
|
const bodyChange = JSON.stringify({
|
|
569
533
|
command: 'turnOff',
|
|
570
534
|
parameter: 'default',
|
|
571
535
|
commandType: 'command',
|
|
572
|
-
})
|
|
573
|
-
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
536
|
+
})
|
|
537
|
+
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
574
538
|
try {
|
|
575
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
576
|
-
const deviceStatus: any = await body.json()
|
|
577
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
539
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
540
|
+
const deviceStatus: any = await body.json()
|
|
541
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
578
542
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
579
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
580
|
-
await this.updateHomeKitCharacteristics()
|
|
543
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
544
|
+
await this.updateHomeKitCharacteristics()
|
|
581
545
|
} else {
|
|
582
|
-
await this.statusCode(statusCode)
|
|
583
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
546
|
+
await this.statusCode(statusCode)
|
|
547
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
584
548
|
}
|
|
585
549
|
} catch (e: any) {
|
|
586
|
-
await this.apiError(e)
|
|
587
|
-
await this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
550
|
+
await this.apiError(e)
|
|
551
|
+
await this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
588
552
|
}
|
|
589
553
|
} else {
|
|
590
|
-
await this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`)
|
|
554
|
+
await this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`)
|
|
591
555
|
}
|
|
592
556
|
}
|
|
593
557
|
|
|
@@ -596,13 +560,13 @@ export class Humidifier extends deviceBase {
|
|
|
596
560
|
*/
|
|
597
561
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
598
562
|
if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
|
|
599
|
-
await this.infoLog(`Set Active: ${value}`)
|
|
563
|
+
await this.infoLog(`Set Active: ${value}`)
|
|
600
564
|
} else {
|
|
601
|
-
await this.debugLog(`No Changes, Active: ${value}`)
|
|
565
|
+
await this.debugLog(`No Changes, Active: ${value}`)
|
|
602
566
|
}
|
|
603
567
|
|
|
604
|
-
this.HumidifierDehumidifier.Active = value
|
|
605
|
-
this.doHumidifierUpdate.next()
|
|
568
|
+
this.HumidifierDehumidifier.Active = value
|
|
569
|
+
this.doHumidifierUpdate.next()
|
|
606
570
|
}
|
|
607
571
|
|
|
608
572
|
/**
|
|
@@ -610,13 +574,13 @@ export class Humidifier extends deviceBase {
|
|
|
610
574
|
*/
|
|
611
575
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
612
576
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
613
|
-
await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`)
|
|
577
|
+
await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`)
|
|
614
578
|
} else {
|
|
615
|
-
await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`)
|
|
579
|
+
await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`)
|
|
616
580
|
}
|
|
617
581
|
|
|
618
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value
|
|
619
|
-
this.doHumidifierUpdate.next()
|
|
582
|
+
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value
|
|
583
|
+
this.doHumidifierUpdate.next()
|
|
620
584
|
}
|
|
621
585
|
|
|
622
586
|
/**
|
|
@@ -624,18 +588,18 @@ export class Humidifier extends deviceBase {
|
|
|
624
588
|
*/
|
|
625
589
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
626
590
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
627
|
-
await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`)
|
|
591
|
+
await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`)
|
|
628
592
|
} else {
|
|
629
|
-
await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`)
|
|
593
|
+
await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`)
|
|
630
594
|
}
|
|
631
595
|
// If the Humidifier is off, turn it on
|
|
632
596
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
633
|
-
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE
|
|
634
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
597
|
+
this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE
|
|
598
|
+
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE
|
|
635
599
|
}
|
|
636
600
|
|
|
637
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value
|
|
638
|
-
this.doHumidifierUpdate.next()
|
|
601
|
+
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value
|
|
602
|
+
this.doHumidifierUpdate.next()
|
|
639
603
|
}
|
|
640
604
|
|
|
641
605
|
/**
|
|
@@ -643,64 +607,55 @@ export class Humidifier extends deviceBase {
|
|
|
643
607
|
*/
|
|
644
608
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
645
609
|
// CurrentRelativeHumidity
|
|
646
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
647
|
-
this.HumidifierDehumidifier.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
610
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity, 'CurrentRelativeHumidity')
|
|
648
611
|
// WaterLevel
|
|
649
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.WaterLevel,
|
|
650
|
-
this.HumidifierDehumidifier.WaterLevel, 'WaterLevel');
|
|
612
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel, 'WaterLevel')
|
|
651
613
|
// CurrentHumidifierDehumidifierState
|
|
652
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
653
|
-
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState, 'CurrentHumidifierDehumidifierState');
|
|
614
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState, 'CurrentHumidifierDehumidifierState')
|
|
654
615
|
// TargetHumidifierDehumidifierState
|
|
655
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.TargetHumidifierDehumidifierState,
|
|
656
|
-
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState, 'TargetHumidifierDehumidifierState');
|
|
616
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState, 'TargetHumidifierDehumidifierState')
|
|
657
617
|
// Active
|
|
658
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.Active,
|
|
659
|
-
this.HumidifierDehumidifier.Active, 'Active');
|
|
618
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active, 'Active')
|
|
660
619
|
// RelativeHumidityHumidifierThreshold
|
|
661
|
-
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
662
|
-
this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold, 'RelativeHumidityHumidifierThreshold');
|
|
620
|
+
await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold, 'RelativeHumidityHumidifierThreshold')
|
|
663
621
|
// CurrentTemperature
|
|
664
622
|
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
665
|
-
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
|
|
666
|
-
this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
|
|
623
|
+
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature')
|
|
667
624
|
}
|
|
668
625
|
}
|
|
669
626
|
|
|
670
627
|
async BLEPushConnection() {
|
|
671
628
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
672
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
673
|
-
await this.openAPIpushChanges()
|
|
629
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
630
|
+
await this.openAPIpushChanges()
|
|
674
631
|
}
|
|
675
632
|
}
|
|
676
633
|
|
|
677
634
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
678
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
635
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
679
636
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
680
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
681
|
-
await this.openAPIRefreshStatus()
|
|
637
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
638
|
+
await this.openAPIRefreshStatus()
|
|
682
639
|
}
|
|
683
640
|
}
|
|
684
641
|
|
|
685
642
|
async offlineOff(): Promise<void> {
|
|
686
643
|
if (this.device.offline) {
|
|
687
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState,
|
|
688
|
-
|
|
689
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.
|
|
690
|
-
this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
|
|
691
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
644
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE)
|
|
645
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
646
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
|
|
692
647
|
}
|
|
693
648
|
}
|
|
694
649
|
|
|
695
650
|
async apiError(e: any): Promise<void> {
|
|
696
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
697
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e)
|
|
698
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e)
|
|
699
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e)
|
|
700
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
701
|
-
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e)
|
|
651
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
652
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e)
|
|
653
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e)
|
|
654
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e)
|
|
655
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
656
|
+
this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e)
|
|
702
657
|
if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
703
|
-
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
658
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
704
659
|
}
|
|
705
660
|
}
|
|
706
661
|
}
|