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