@switchbot/homebridge-switchbot 3.7.1-beta.9 → 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 +76 -1
- 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 +133 -160
- 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 +20 -19
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +466 -710
- 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 +61 -54
- 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 +1462 -1678
- 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/irdevice/light.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
*
|
|
3
3
|
* light.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,127 +18,108 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
|
|
|
17
18
|
export class Light extends irdeviceBase {
|
|
18
19
|
// Services
|
|
19
20
|
private LightBulb?: {
|
|
20
|
-
Name: CharacteristicValue
|
|
21
|
-
Service: Service
|
|
22
|
-
On: CharacteristicValue
|
|
23
|
-
}
|
|
21
|
+
Name: CharacteristicValue
|
|
22
|
+
Service: Service
|
|
23
|
+
On: CharacteristicValue
|
|
24
|
+
}
|
|
24
25
|
|
|
25
26
|
private ProgrammableSwitchOn?: {
|
|
26
|
-
Name: CharacteristicValue
|
|
27
|
-
Service: Service
|
|
28
|
-
ProgrammableSwitchEvent: CharacteristicValue
|
|
29
|
-
ProgrammableSwitchOutputState: CharacteristicValue
|
|
30
|
-
}
|
|
27
|
+
Name: CharacteristicValue
|
|
28
|
+
Service: Service
|
|
29
|
+
ProgrammableSwitchEvent: CharacteristicValue
|
|
30
|
+
ProgrammableSwitchOutputState: CharacteristicValue
|
|
31
|
+
}
|
|
31
32
|
|
|
32
33
|
private ProgrammableSwitchOff?: {
|
|
33
|
-
Name: CharacteristicValue
|
|
34
|
-
Service: Service
|
|
35
|
-
ProgrammableSwitchEvent: CharacteristicValue
|
|
36
|
-
ProgrammableSwitchOutputState: CharacteristicValue
|
|
37
|
-
}
|
|
34
|
+
Name: CharacteristicValue
|
|
35
|
+
Service: Service
|
|
36
|
+
ProgrammableSwitchEvent: CharacteristicValue
|
|
37
|
+
ProgrammableSwitchOutputState: CharacteristicValue
|
|
38
|
+
}
|
|
38
39
|
|
|
39
40
|
constructor(
|
|
40
41
|
readonly platform: SwitchBotPlatform,
|
|
41
42
|
accessory: PlatformAccessory,
|
|
42
43
|
device: irdevice & irDevicesConfig,
|
|
43
44
|
) {
|
|
44
|
-
super(platform, accessory, device)
|
|
45
|
+
super(platform, accessory, device)
|
|
45
46
|
// Set category
|
|
46
|
-
accessory.category = this.hap.Categories.LIGHTBULB
|
|
47
|
+
accessory.category = this.hap.Categories.LIGHTBULB
|
|
47
48
|
|
|
48
49
|
if (!device.irlight?.stateless) {
|
|
49
50
|
// Initialize LightBulb Service
|
|
50
|
-
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
51
|
+
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
51
52
|
this.LightBulb = {
|
|
52
53
|
Name: accessory.displayName,
|
|
53
54
|
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
54
55
|
On: accessory.context.On || false,
|
|
55
|
-
}
|
|
56
|
-
accessory.context.LightBulb = this.LightBulb as object
|
|
56
|
+
}
|
|
57
|
+
accessory.context.LightBulb = this.LightBulb as object
|
|
57
58
|
|
|
58
|
-
this.LightBulb.Service
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.onGet(() => {
|
|
62
|
-
return this.LightBulb!.On;
|
|
63
|
-
})
|
|
64
|
-
.onSet(this.OnSet.bind(this));
|
|
59
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
|
|
60
|
+
return this.LightBulb!.On
|
|
61
|
+
}).onSet(this.OnSet.bind(this))
|
|
65
62
|
} else {
|
|
66
63
|
// Initialize ProgrammableSwitchOn Service
|
|
67
|
-
accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {}
|
|
64
|
+
accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {}
|
|
68
65
|
this.ProgrammableSwitchOn = {
|
|
69
66
|
Name: `${accessory.displayName} On`,
|
|
70
|
-
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
71
|
-
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
67
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
72
68
|
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
73
69
|
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
74
|
-
}
|
|
75
|
-
accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object
|
|
70
|
+
}
|
|
71
|
+
accessory.context.ProgrammableSwitchOn = this.ProgrammableSwitchOn as object
|
|
76
72
|
|
|
77
73
|
// Initialize ProgrammableSwitchOn Characteristics
|
|
78
|
-
this.ProgrammableSwitchOn?.Service
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.ProgrammableSwitchOn?.Service
|
|
91
|
-
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
92
|
-
.onGet(() => {
|
|
93
|
-
return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState;
|
|
94
|
-
})
|
|
95
|
-
.onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
|
|
74
|
+
this.ProgrammableSwitchOn?.Service.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOn.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
75
|
+
validValueRanges: [0, 0],
|
|
76
|
+
minValue: 0,
|
|
77
|
+
maxValue: 0,
|
|
78
|
+
validValues: [0],
|
|
79
|
+
}).onGet(() => {
|
|
80
|
+
return this.ProgrammableSwitchOn!.ProgrammableSwitchEvent
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
this.ProgrammableSwitchOn?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onGet(() => {
|
|
84
|
+
return this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState
|
|
85
|
+
}).onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this))
|
|
96
86
|
|
|
97
87
|
// Initialize ProgrammableSwitchOff Service
|
|
98
|
-
accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {}
|
|
88
|
+
accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {}
|
|
99
89
|
this.ProgrammableSwitchOff = {
|
|
100
90
|
Name: `${accessory.displayName} Off`,
|
|
101
|
-
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
102
|
-
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
91
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
103
92
|
ProgrammableSwitchEvent: accessory.context.ProgrammableSwitchEvent ?? this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
|
|
104
93
|
ProgrammableSwitchOutputState: accessory.context.ProgrammableSwitchOutputState ?? 0,
|
|
105
|
-
}
|
|
106
|
-
accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object
|
|
94
|
+
}
|
|
95
|
+
accessory.context.ProgrammableSwitchOff = this.ProgrammableSwitchOff as object
|
|
107
96
|
|
|
108
97
|
// Initialize ProgrammableSwitchOff Characteristics
|
|
109
|
-
this.ProgrammableSwitchOff?.Service
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.ProgrammableSwitchOff?.Service
|
|
122
|
-
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
123
|
-
.onGet(() => {
|
|
124
|
-
return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState;
|
|
125
|
-
})
|
|
126
|
-
.onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
|
|
98
|
+
this.ProgrammableSwitchOff?.Service.setCharacteristic(this.hap.Characteristic.Name, this.ProgrammableSwitchOff.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
99
|
+
validValueRanges: [0, 0],
|
|
100
|
+
minValue: 0,
|
|
101
|
+
maxValue: 0,
|
|
102
|
+
validValues: [0],
|
|
103
|
+
}).onGet(() => {
|
|
104
|
+
return this.ProgrammableSwitchOff!.ProgrammableSwitchEvent
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
this.ProgrammableSwitchOff?.Service.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onGet(() => {
|
|
108
|
+
return this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState
|
|
109
|
+
}).onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this))
|
|
127
110
|
}
|
|
128
|
-
|
|
129
111
|
}
|
|
130
112
|
|
|
131
113
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
132
|
-
await this.debugLog(`On: ${value}`)
|
|
114
|
+
await this.debugLog(`On: ${value}`)
|
|
133
115
|
|
|
134
|
-
this.LightBulb!.On = value
|
|
116
|
+
this.LightBulb!.On = value
|
|
135
117
|
if (this.LightBulb?.On) {
|
|
136
|
-
const On = true
|
|
137
|
-
await this.pushLightOnChanges(On)
|
|
118
|
+
const On = true
|
|
119
|
+
await this.pushLightOnChanges(On)
|
|
138
120
|
} else {
|
|
139
|
-
const On = false
|
|
140
|
-
await this.pushLightOffChanges(On)
|
|
121
|
+
const On = false
|
|
122
|
+
await this.pushLightOffChanges(On)
|
|
141
123
|
}
|
|
142
124
|
/**
|
|
143
125
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -146,12 +128,12 @@ export class Light extends irdeviceBase {
|
|
|
146
128
|
}
|
|
147
129
|
|
|
148
130
|
async ProgrammableSwitchOutputStateSetOn(value: CharacteristicValue): Promise<void> {
|
|
149
|
-
await this.debugLog(`On: ${value}`)
|
|
131
|
+
await this.debugLog(`On: ${value}`)
|
|
150
132
|
|
|
151
|
-
this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value
|
|
133
|
+
this.ProgrammableSwitchOn!.ProgrammableSwitchOutputState = value
|
|
152
134
|
if (this.ProgrammableSwitchOn?.ProgrammableSwitchOutputState === 1) {
|
|
153
|
-
const On = true
|
|
154
|
-
await this.pushLightOnChanges(On)
|
|
135
|
+
const On = true
|
|
136
|
+
await this.pushLightOnChanges(On)
|
|
155
137
|
}
|
|
156
138
|
/**
|
|
157
139
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -160,12 +142,12 @@ export class Light extends irdeviceBase {
|
|
|
160
142
|
}
|
|
161
143
|
|
|
162
144
|
async ProgrammableSwitchOutputStateSetOff(value: CharacteristicValue): Promise<void> {
|
|
163
|
-
await this.debugLog(`On: ${value}`)
|
|
145
|
+
await this.debugLog(`On: ${value}`)
|
|
164
146
|
|
|
165
|
-
this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value
|
|
147
|
+
this.ProgrammableSwitchOff!.ProgrammableSwitchOutputState = value
|
|
166
148
|
if (this.ProgrammableSwitchOff?.ProgrammableSwitchOutputState === 1) {
|
|
167
|
-
const On = false
|
|
168
|
-
await this.pushLightOffChanges(On)
|
|
149
|
+
const On = false
|
|
150
|
+
await this.pushLightOffChanges(On)
|
|
169
151
|
}
|
|
170
152
|
/**
|
|
171
153
|
* pushLightOnChanges and pushLightOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
@@ -173,100 +155,94 @@ export class Light extends irdeviceBase {
|
|
|
173
155
|
*/
|
|
174
156
|
}
|
|
175
157
|
|
|
176
|
-
|
|
177
|
-
|
|
178
158
|
/**
|
|
179
159
|
* Pushes the requested changes to the SwitchBot API
|
|
180
|
-
* deviceType
|
|
181
|
-
* Light -
|
|
182
|
-
* Light - "command" "turnOn" "default"
|
|
183
|
-
* Light - "command" "volumeAdd" "default"
|
|
184
|
-
* Light - "command" "volumeSub" "default"
|
|
185
|
-
* Light - "command" "channelAdd" "default"
|
|
186
|
-
* Light - "command" "channelSub" "default"
|
|
160
|
+
* deviceType commandType Command command parameter Description
|
|
161
|
+
* Light - "command" "turnOff" "default" = set to OFF state
|
|
162
|
+
* Light - "command" "turnOn" "default" = set to ON state
|
|
163
|
+
* Light - "command" "volumeAdd" "default" = volume up
|
|
164
|
+
* Light - "command" "volumeSub" "default" = volume down
|
|
165
|
+
* Light - "command" "channelAdd" "default" = next channel
|
|
166
|
+
* Light - "command" "channelSub" "default" = previous channel
|
|
187
167
|
*/
|
|
188
168
|
async pushLightOnChanges(On: boolean): Promise<void> {
|
|
189
|
-
await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`)
|
|
169
|
+
await this.debugLog(`pushLightOnChanges On: ${On}, disablePushOn: ${this.disablePushOn}`)
|
|
190
170
|
if (On === true && this.disablePushOn === false) {
|
|
191
|
-
const commandType: string = await this.commandType()
|
|
192
|
-
const command: string = await this.commandOn()
|
|
171
|
+
const commandType: string = await this.commandType()
|
|
172
|
+
const command: string = await this.commandOn()
|
|
193
173
|
const bodyChange = JSON.stringify({
|
|
194
|
-
command
|
|
174
|
+
command,
|
|
195
175
|
parameter: 'default',
|
|
196
|
-
commandType
|
|
197
|
-
})
|
|
198
|
-
await this.pushChanges(bodyChange, On)
|
|
176
|
+
commandType,
|
|
177
|
+
})
|
|
178
|
+
await this.pushChanges(bodyChange, On)
|
|
199
179
|
}
|
|
200
180
|
}
|
|
201
181
|
|
|
202
182
|
async pushLightOffChanges(On: boolean): Promise<void> {
|
|
203
|
-
await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`)
|
|
183
|
+
await this.debugLog(`pushLightOffChanges On: ${On}, disablePushOff: ${this.disablePushOff}`)
|
|
204
184
|
if (On === false && this.disablePushOff === false) {
|
|
205
|
-
const commandType: string = await this.commandType()
|
|
206
|
-
const command: string = await this.commandOff()
|
|
185
|
+
const commandType: string = await this.commandType()
|
|
186
|
+
const command: string = await this.commandOff()
|
|
207
187
|
const bodyChange = JSON.stringify({
|
|
208
|
-
command
|
|
188
|
+
command,
|
|
209
189
|
parameter: 'default',
|
|
210
|
-
commandType
|
|
211
|
-
})
|
|
212
|
-
await this.pushChanges(bodyChange, On)
|
|
190
|
+
commandType,
|
|
191
|
+
})
|
|
192
|
+
await this.pushChanges(bodyChange, On)
|
|
213
193
|
}
|
|
214
194
|
}
|
|
215
195
|
|
|
216
196
|
async pushChanges(bodyChange: any, On: boolean): Promise<void> {
|
|
217
|
-
this.debugLog('pushChanges')
|
|
197
|
+
this.debugLog('pushChanges')
|
|
218
198
|
if (this.device.connectionType === 'OpenAPI') {
|
|
219
|
-
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
199
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
220
200
|
try {
|
|
221
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
222
|
-
const deviceStatus: any = await body.json()
|
|
223
|
-
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
201
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
202
|
+
const deviceStatus: any = await body.json()
|
|
203
|
+
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
224
204
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
225
|
-
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
226
|
-
this.accessory.context.On = On
|
|
227
|
-
await this.updateHomeKitCharacteristics()
|
|
205
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
206
|
+
this.accessory.context.On = On
|
|
207
|
+
await this.updateHomeKitCharacteristics()
|
|
228
208
|
} else {
|
|
229
|
-
await this.statusCode(statusCode)
|
|
230
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
209
|
+
await this.statusCode(statusCode)
|
|
210
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
231
211
|
}
|
|
232
212
|
} catch (e: any) {
|
|
233
|
-
await this.apiError(e)
|
|
234
|
-
await this.pushChangeError(e)
|
|
213
|
+
await this.apiError(e)
|
|
214
|
+
await this.pushChangeError(e)
|
|
235
215
|
}
|
|
236
216
|
} else {
|
|
237
|
-
this.warnLog(
|
|
238
|
-
+ `${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
217
|
+
this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
239
218
|
}
|
|
240
219
|
}
|
|
241
220
|
|
|
242
221
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
243
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
222
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
244
223
|
if (!this.device.irlight?.stateless && this.LightBulb?.Service) {
|
|
245
224
|
// On
|
|
246
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
247
|
-
this.LightBulb.On, 'On');
|
|
225
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
|
|
248
226
|
} else {
|
|
249
227
|
if (this.ProgrammableSwitchOn?.Service) {
|
|
250
|
-
|
|
251
|
-
await this.updateCharacteristic(this.ProgrammableSwitchOn.Service, this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
252
|
-
this.ProgrammableSwitchOn.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState');
|
|
228
|
+
// On Stateful Programmable Switch
|
|
229
|
+
await this.updateCharacteristic(this.ProgrammableSwitchOn.Service, this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOn.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState')
|
|
253
230
|
}
|
|
254
231
|
if (this.ProgrammableSwitchOff?.Service) {
|
|
255
|
-
|
|
256
|
-
await this.updateCharacteristic(this.ProgrammableSwitchOff.Service, this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
257
|
-
this.ProgrammableSwitchOff.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState');
|
|
232
|
+
// Off Stateful Programmable Switch
|
|
233
|
+
await this.updateCharacteristic(this.ProgrammableSwitchOff.Service, this.hap.Characteristic.ProgrammableSwitchOutputState, this.ProgrammableSwitchOff.ProgrammableSwitchOutputState, 'ProgrammableSwitchOutputState')
|
|
258
234
|
}
|
|
259
235
|
}
|
|
260
236
|
}
|
|
261
237
|
|
|
262
238
|
async apiError(e: any): Promise<void> {
|
|
263
239
|
if (!this.device.irlight?.stateless) {
|
|
264
|
-
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
240
|
+
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
265
241
|
} else {
|
|
266
|
-
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
267
|
-
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
268
|
-
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
269
|
-
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
242
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
243
|
+
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
244
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|
|
245
|
+
this.ProgrammableSwitchOff?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
|
|
270
246
|
}
|
|
271
247
|
}
|
|
272
248
|
}
|