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