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