@switchbot/homebridge-switchbot 3.7.1-beta.12 → 3.7.1-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.d.ts +8 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +34 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +61 -97
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +5 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +36 -71
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +22 -37
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +141 -146
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +54 -47
- package/src/device/blindtilt.ts +419 -456
- package/src/device/bot.ts +656 -693
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +400 -435
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +169 -184
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +280 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1281 -1281
- package/src/settings.ts +170 -170
- package/src/types/bledevicestatus.ts +255 -255
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -127
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
package/src/irdevice/fan.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
*
|
|
3
3
|
* fan.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
-
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
+
|
|
11
|
+
import { irdeviceBase } from './irdevice.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Platform Accessory
|
|
@@ -17,25 +18,25 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
|
|
|
17
18
|
export class IRFan extends irdeviceBase {
|
|
18
19
|
// Services
|
|
19
20
|
private Fan: {
|
|
20
|
-
Name: CharacteristicValue
|
|
21
|
-
Service: Service
|
|
22
|
-
Active: CharacteristicValue
|
|
23
|
-
SwingMode: CharacteristicValue
|
|
24
|
-
RotationSpeed: CharacteristicValue
|
|
25
|
-
RotationDirection: CharacteristicValue
|
|
26
|
-
}
|
|
21
|
+
Name: CharacteristicValue
|
|
22
|
+
Service: Service
|
|
23
|
+
Active: CharacteristicValue
|
|
24
|
+
SwingMode: CharacteristicValue
|
|
25
|
+
RotationSpeed: CharacteristicValue
|
|
26
|
+
RotationDirection: CharacteristicValue
|
|
27
|
+
}
|
|
27
28
|
|
|
28
29
|
constructor(
|
|
29
30
|
readonly platform: SwitchBotPlatform,
|
|
30
31
|
accessory: PlatformAccessory,
|
|
31
32
|
device: irdevice & irDevicesConfig,
|
|
32
33
|
) {
|
|
33
|
-
super(platform, accessory, device)
|
|
34
|
+
super(platform, accessory, device)
|
|
34
35
|
// Set category
|
|
35
|
-
accessory.category = this.hap.Categories.FAN
|
|
36
|
+
accessory.category = this.hap.Categories.FAN
|
|
36
37
|
|
|
37
38
|
// Initialize Switch Service
|
|
38
|
-
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
39
|
+
accessory.context.Fan = accessory.context.Fan ?? {}
|
|
39
40
|
this.Fan = {
|
|
40
41
|
Name: accessory.displayName,
|
|
41
42
|
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
|
|
@@ -43,133 +44,118 @@ export class IRFan extends irdeviceBase {
|
|
|
43
44
|
SwingMode: accessory.context.SwingMode ?? this.hap.Characteristic.SwingMode.SWING_DISABLED,
|
|
44
45
|
RotationSpeed: accessory.context.RotationSpeed ?? 0,
|
|
45
46
|
RotationDirection: accessory.context.RotationDirection ?? this.hap.Characteristic.RotationDirection.CLOCKWISE,
|
|
46
|
-
}
|
|
47
|
-
accessory.context.Fan = this.Fan as object
|
|
48
|
-
|
|
49
|
-
this.Fan.Service
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.onGet(() => {
|
|
53
|
-
return this.Fan.Active;
|
|
54
|
-
})
|
|
55
|
-
.onSet(this.ActiveSet.bind(this));
|
|
47
|
+
}
|
|
48
|
+
accessory.context.Fan = this.Fan as object
|
|
49
|
+
|
|
50
|
+
this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name).getCharacteristic(this.hap.Characteristic.Active).onGet(() => {
|
|
51
|
+
return this.Fan.Active
|
|
52
|
+
}).onSet(this.ActiveSet.bind(this))
|
|
56
53
|
|
|
57
54
|
if (device.irfan?.rotation_speed) {
|
|
58
55
|
// handle Rotation Speed events using the RotationSpeed characteristic
|
|
59
|
-
this.Fan.Service
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.onGet(() => {
|
|
67
|
-
return this.Fan.RotationSpeed;
|
|
68
|
-
})
|
|
69
|
-
.onSet(this.RotationSpeedSet.bind(this));
|
|
56
|
+
this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed).setProps({
|
|
57
|
+
minStep: device.irfan?.set_minStep ?? 1,
|
|
58
|
+
minValue: device.irfan?.set_min ?? 1,
|
|
59
|
+
maxValue: device.irfan?.set_max ?? 100,
|
|
60
|
+
}).onGet(() => {
|
|
61
|
+
return this.Fan.RotationSpeed
|
|
62
|
+
}).onSet(this.RotationSpeedSet.bind(this))
|
|
70
63
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
71
|
-
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
72
|
-
this.Fan.Service.removeCharacteristic(characteristic)
|
|
73
|
-
this.debugLog('Rotation Speed Characteristic was removed.')
|
|
64
|
+
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
65
|
+
this.Fan.Service.removeCharacteristic(characteristic)
|
|
66
|
+
this.debugLog('Rotation Speed Characteristic was removed.')
|
|
74
67
|
} else {
|
|
75
|
-
this.debugLog(
|
|
76
|
-
+ `Clear Cache on ${this.accessory.displayName} to remove Chracteristic`);
|
|
68
|
+
this.debugLog(`RotationSpeed Characteristic was not removed/added, Clear Cache on ${this.accessory.displayName} to remove Chracteristic`)
|
|
77
69
|
}
|
|
78
70
|
|
|
79
71
|
if (device.irfan?.swing_mode) {
|
|
80
72
|
// handle Osolcation events using the SwingMode characteristic
|
|
81
|
-
this.Fan.Service
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return this.Fan.SwingMode;
|
|
85
|
-
})
|
|
86
|
-
.onSet(this.SwingModeSet.bind(this));
|
|
73
|
+
this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode).onGet(() => {
|
|
74
|
+
return this.Fan.SwingMode
|
|
75
|
+
}).onSet(this.SwingModeSet.bind(this))
|
|
87
76
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
88
|
-
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode)
|
|
89
|
-
this.Fan.Service.removeCharacteristic(characteristic)
|
|
90
|
-
this.debugLog('Swing Mode Characteristic was removed.')
|
|
77
|
+
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode)
|
|
78
|
+
this.Fan.Service.removeCharacteristic(characteristic)
|
|
79
|
+
this.debugLog('Swing Mode Characteristic was removed.')
|
|
91
80
|
} else {
|
|
92
|
-
this.debugLog(
|
|
93
|
-
+ `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`);
|
|
81
|
+
this.debugLog(`Swing Mode Characteristic was not removed/added, Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`)
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
|
|
97
85
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
98
|
-
await this.debugLog(`SwingMode: ${value}`)
|
|
86
|
+
await this.debugLog(`SwingMode: ${value}`)
|
|
99
87
|
if (value > this.Fan.SwingMode) {
|
|
100
|
-
this.Fan.SwingMode = 1
|
|
101
|
-
await this.pushFanOnChanges()
|
|
102
|
-
await this.pushFanSwingChanges()
|
|
88
|
+
this.Fan.SwingMode = 1
|
|
89
|
+
await this.pushFanOnChanges()
|
|
90
|
+
await this.pushFanSwingChanges()
|
|
103
91
|
} else {
|
|
104
|
-
this.Fan.SwingMode = 0
|
|
105
|
-
await this.pushFanOnChanges()
|
|
106
|
-
await this.pushFanSwingChanges()
|
|
92
|
+
this.Fan.SwingMode = 0
|
|
93
|
+
await this.pushFanOnChanges()
|
|
94
|
+
await this.pushFanSwingChanges()
|
|
107
95
|
}
|
|
108
|
-
this.Fan.SwingMode = value
|
|
109
|
-
this.accessory.context.SwingMode = this.Fan.SwingMode
|
|
96
|
+
this.Fan.SwingMode = value
|
|
97
|
+
this.accessory.context.SwingMode = this.Fan.SwingMode
|
|
110
98
|
}
|
|
111
99
|
|
|
112
100
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
113
|
-
await this.debugLog(`RotationSpeed: ${value}`)
|
|
101
|
+
await this.debugLog(`RotationSpeed: ${value}`)
|
|
114
102
|
if (value > this.Fan.RotationSpeed) {
|
|
115
|
-
this.Fan.RotationSpeed = 1
|
|
116
|
-
this.pushFanSpeedUpChanges()
|
|
117
|
-
this.pushFanOnChanges()
|
|
103
|
+
this.Fan.RotationSpeed = 1
|
|
104
|
+
this.pushFanSpeedUpChanges()
|
|
105
|
+
this.pushFanOnChanges()
|
|
118
106
|
} else {
|
|
119
|
-
this.Fan.RotationSpeed = 0
|
|
120
|
-
this.pushFanSpeedDownChanges()
|
|
107
|
+
this.Fan.RotationSpeed = 0
|
|
108
|
+
this.pushFanSpeedDownChanges()
|
|
121
109
|
}
|
|
122
|
-
this.Fan.RotationSpeed = value
|
|
123
|
-
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed
|
|
110
|
+
this.Fan.RotationSpeed = value
|
|
111
|
+
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed
|
|
124
112
|
}
|
|
125
113
|
|
|
126
114
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
127
|
-
await this.debugLog(`Active: ${value}`)
|
|
115
|
+
await this.debugLog(`Active: ${value}`)
|
|
128
116
|
|
|
129
|
-
this.Fan.Active = value
|
|
117
|
+
this.Fan.Active = value
|
|
130
118
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
131
|
-
this.pushFanOnChanges()
|
|
119
|
+
this.pushFanOnChanges()
|
|
132
120
|
} else {
|
|
133
|
-
this.pushFanOffChanges()
|
|
121
|
+
this.pushFanOffChanges()
|
|
134
122
|
}
|
|
135
123
|
}
|
|
136
124
|
|
|
137
125
|
/**
|
|
138
126
|
* Pushes the requested changes to the SwitchBot API
|
|
139
|
-
* deviceType
|
|
140
|
-
* Fan - "command" "swing" "default"
|
|
141
|
-
* Fan - "command" "timer" "default"
|
|
142
|
-
* Fan - "command" "lowSpeed" "default"
|
|
143
|
-
* Fan - "command" "middleSpeed" "default"
|
|
144
|
-
* Fan - "command" "highSpeed" "default"
|
|
127
|
+
* deviceType commandType Command command parameter Description
|
|
128
|
+
* Fan - "command" "swing" "default" = swing
|
|
129
|
+
* Fan - "command" "timer" "default" = timer
|
|
130
|
+
* Fan - "command" "lowSpeed" "default" = fan speed to low
|
|
131
|
+
* Fan - "command" "middleSpeed" "default" = fan speed to medium
|
|
132
|
+
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
145
133
|
*/
|
|
146
134
|
async pushFanOnChanges(): Promise<void> {
|
|
147
|
-
await this.debugLog(`pushFanOnChanges Active: ${this.Fan.Active}
|
|
148
|
-
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
135
|
+
await this.debugLog(`pushFanOnChanges Active: ${this.Fan.Active}, disablePushOn: ${this.disablePushOn}`)
|
|
149
136
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
150
|
-
const commandType: string = await this.commandType()
|
|
151
|
-
const command: string = await this.commandOn()
|
|
137
|
+
const commandType: string = await this.commandType()
|
|
138
|
+
const command: string = await this.commandOn()
|
|
152
139
|
const bodyChange = JSON.stringify({
|
|
153
|
-
command
|
|
140
|
+
command,
|
|
154
141
|
parameter: 'default',
|
|
155
|
-
commandType
|
|
156
|
-
})
|
|
157
|
-
await this.pushChanges(bodyChange)
|
|
142
|
+
commandType,
|
|
143
|
+
})
|
|
144
|
+
await this.pushChanges(bodyChange)
|
|
158
145
|
}
|
|
159
146
|
}
|
|
160
147
|
|
|
161
148
|
async pushFanOffChanges(): Promise<void> {
|
|
162
|
-
await this.debugLog(`pushLightOffChanges Active: ${this.Fan.Active}
|
|
163
|
-
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
149
|
+
await this.debugLog(`pushLightOffChanges Active: ${this.Fan.Active}, disablePushOff: ${this.disablePushOff}`)
|
|
164
150
|
if (this.Fan.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
165
|
-
const commandType: string = await this.commandType()
|
|
166
|
-
const command: string = await this.commandOff()
|
|
151
|
+
const commandType: string = await this.commandType()
|
|
152
|
+
const command: string = await this.commandOff()
|
|
167
153
|
const bodyChange = JSON.stringify({
|
|
168
|
-
command
|
|
154
|
+
command,
|
|
169
155
|
parameter: 'default',
|
|
170
|
-
commandType
|
|
171
|
-
})
|
|
172
|
-
await this.pushChanges(bodyChange)
|
|
156
|
+
commandType,
|
|
157
|
+
})
|
|
158
|
+
await this.pushChanges(bodyChange)
|
|
173
159
|
}
|
|
174
160
|
}
|
|
175
161
|
|
|
@@ -178,8 +164,8 @@ export class IRFan extends irdeviceBase {
|
|
|
178
164
|
command: 'highSpeed',
|
|
179
165
|
parameter: 'default',
|
|
180
166
|
commandType: 'command',
|
|
181
|
-
})
|
|
182
|
-
await this.pushChanges(bodyChange)
|
|
167
|
+
})
|
|
168
|
+
await this.pushChanges(bodyChange)
|
|
183
169
|
}
|
|
184
170
|
|
|
185
171
|
async pushFanSpeedDownChanges(): Promise<void> {
|
|
@@ -187,8 +173,8 @@ export class IRFan extends irdeviceBase {
|
|
|
187
173
|
command: 'lowSpeed',
|
|
188
174
|
parameter: 'default',
|
|
189
175
|
commandType: 'command',
|
|
190
|
-
})
|
|
191
|
-
await this.pushChanges(bodyChange)
|
|
176
|
+
})
|
|
177
|
+
await this.pushChanges(bodyChange)
|
|
192
178
|
}
|
|
193
179
|
|
|
194
180
|
async pushFanSwingChanges(): Promise<void> {
|
|
@@ -196,50 +182,47 @@ export class IRFan extends irdeviceBase {
|
|
|
196
182
|
command: 'swing',
|
|
197
183
|
parameter: 'default',
|
|
198
184
|
commandType: 'command',
|
|
199
|
-
})
|
|
200
|
-
await this.pushChanges(bodyChange)
|
|
185
|
+
})
|
|
186
|
+
await this.pushChanges(bodyChange)
|
|
201
187
|
}
|
|
202
188
|
|
|
203
189
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
204
|
-
await this.debugLog('pushChanges')
|
|
190
|
+
await this.debugLog('pushChanges')
|
|
205
191
|
if (this.device.connectionType === 'OpenAPI') {
|
|
206
|
-
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
192
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
207
193
|
try {
|
|
208
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
209
|
-
const deviceStatus: any = await body.json()
|
|
210
|
-
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
194
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
195
|
+
const deviceStatus: any = await body.json()
|
|
196
|
+
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
211
197
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
212
|
-
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
213
|
-
await this.updateHomeKitCharacteristics()
|
|
198
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
199
|
+
await this.updateHomeKitCharacteristics()
|
|
214
200
|
} else {
|
|
215
|
-
await this.statusCode(statusCode)
|
|
216
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
201
|
+
await this.statusCode(statusCode)
|
|
202
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
217
203
|
}
|
|
218
204
|
} catch (e: any) {
|
|
219
|
-
await this.apiError(e)
|
|
220
|
-
await this.pushChangeError(e)
|
|
205
|
+
await this.apiError(e)
|
|
206
|
+
await this.pushChangeError(e)
|
|
221
207
|
}
|
|
222
208
|
} else {
|
|
223
|
-
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
209
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
224
210
|
}
|
|
225
211
|
}
|
|
226
212
|
|
|
227
213
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
228
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
214
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
229
215
|
// Active
|
|
230
|
-
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active,
|
|
231
|
-
this.Fan.Active, 'Active');
|
|
216
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active, this.Fan.Active, 'Active')
|
|
232
217
|
// SwingMode
|
|
233
|
-
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.SwingMode,
|
|
234
|
-
this.Fan.SwingMode, 'SwingMode');
|
|
218
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.SwingMode, this.Fan.SwingMode, 'SwingMode')
|
|
235
219
|
// RotationSpeed
|
|
236
|
-
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed,
|
|
237
|
-
this.Fan.RotationSpeed, 'RotationSpeed');
|
|
220
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed, 'RotationSpeed')
|
|
238
221
|
}
|
|
239
222
|
|
|
240
223
|
async apiError(e: any): Promise<void> {
|
|
241
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
242
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e)
|
|
243
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, e)
|
|
224
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
225
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e)
|
|
226
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, e)
|
|
244
227
|
}
|
|
245
228
|
}
|