@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/colorbulb.ts
CHANGED
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
*
|
|
3
3
|
* blindtilt.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { colorBulbServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { colorBulbStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { colorBulbWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
7
14
|
/*
|
|
8
15
|
* For Testing Locally:
|
|
9
16
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
17
|
*/
|
|
11
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
12
|
-
import {
|
|
18
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
|
+
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
13
20
|
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import type { SwitchBotPlatform } from '../platform.js';
|
|
17
|
-
import type { colorBulbServiceData } from '../types/bledevicestatus.js';
|
|
18
|
-
import type { colorBulbStatus } from '../types/devicestatus.js';
|
|
19
|
-
import type { colorBulbWebhookContext } from '../types/devicewebhookstatus.js';
|
|
20
|
-
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
21
|
+
import { hs2rgb, m2hs, rgb2hs } from '../utils.js'
|
|
22
|
+
import { deviceBase } from './device.js'
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Platform Accessory
|
|
@@ -27,51 +29,51 @@ import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstru
|
|
|
27
29
|
export class ColorBulb extends deviceBase {
|
|
28
30
|
// Services
|
|
29
31
|
private LightBulb: {
|
|
30
|
-
Name: CharacteristicValue
|
|
31
|
-
Service: Service
|
|
32
|
-
On: CharacteristicValue
|
|
33
|
-
Hue: CharacteristicValue
|
|
34
|
-
Saturation: CharacteristicValue
|
|
35
|
-
Brightness: CharacteristicValue
|
|
36
|
-
ColorTemperature?: CharacteristicValue
|
|
37
|
-
}
|
|
32
|
+
Name: CharacteristicValue
|
|
33
|
+
Service: Service
|
|
34
|
+
On: CharacteristicValue
|
|
35
|
+
Hue: CharacteristicValue
|
|
36
|
+
Saturation: CharacteristicValue
|
|
37
|
+
Brightness: CharacteristicValue
|
|
38
|
+
ColorTemperature?: CharacteristicValue
|
|
39
|
+
}
|
|
38
40
|
|
|
39
41
|
// OpenAPI
|
|
40
|
-
deviceStatus!: colorBulbStatus
|
|
42
|
+
deviceStatus!: colorBulbStatus
|
|
41
43
|
|
|
42
|
-
//Webhook
|
|
43
|
-
webhookContext!: colorBulbWebhookContext
|
|
44
|
+
// Webhook
|
|
45
|
+
webhookContext!: colorBulbWebhookContext
|
|
44
46
|
|
|
45
47
|
// BLE
|
|
46
|
-
serviceData!: colorBulbServiceData
|
|
48
|
+
serviceData!: colorBulbServiceData
|
|
47
49
|
|
|
48
50
|
// Adaptive Lighting
|
|
49
|
-
adaptiveLighting!: boolean
|
|
50
|
-
adaptiveLightingShift!: number
|
|
51
|
-
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap
|
|
51
|
+
adaptiveLighting!: boolean
|
|
52
|
+
adaptiveLightingShift!: number
|
|
53
|
+
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>
|
|
52
54
|
|
|
53
55
|
// Updates
|
|
54
|
-
colorBulbUpdateInProgress!: boolean
|
|
55
|
-
doColorBulbUpdate!: Subject<void
|
|
56
|
+
colorBulbUpdateInProgress!: boolean
|
|
57
|
+
doColorBulbUpdate!: Subject<void>
|
|
56
58
|
|
|
57
59
|
constructor(
|
|
58
60
|
readonly platform: SwitchBotPlatform,
|
|
59
61
|
accessory: PlatformAccessory,
|
|
60
62
|
device: device & devicesConfig,
|
|
61
63
|
) {
|
|
62
|
-
super(platform, accessory, device)
|
|
64
|
+
super(platform, accessory, device)
|
|
63
65
|
// Set category
|
|
64
|
-
accessory.category = this.hap.Categories.LIGHTBULB
|
|
66
|
+
accessory.category = this.hap.Categories.LIGHTBULB
|
|
65
67
|
|
|
66
68
|
// default placeholders
|
|
67
|
-
this.getAdaptiveLightingSettings(accessory, device)
|
|
69
|
+
this.getAdaptiveLightingSettings(accessory, device)
|
|
68
70
|
|
|
69
71
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
70
|
-
this.doColorBulbUpdate = new Subject()
|
|
71
|
-
this.colorBulbUpdateInProgress = false
|
|
72
|
+
this.doColorBulbUpdate = new Subject()
|
|
73
|
+
this.colorBulbUpdateInProgress = false
|
|
72
74
|
|
|
73
75
|
// Initialize LightBulb property
|
|
74
|
-
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
76
|
+
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
75
77
|
this.LightBulb = {
|
|
76
78
|
Name: accessory.displayName,
|
|
77
79
|
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
|
|
@@ -80,234 +82,212 @@ export class ColorBulb extends deviceBase {
|
|
|
80
82
|
Saturation: accessory.context.Saturation ?? 0,
|
|
81
83
|
Brightness: accessory.context.Brightness ?? 0,
|
|
82
84
|
ColorTemperature: accessory.context.ColorTemperature ?? 140,
|
|
83
|
-
}
|
|
84
|
-
accessory.context.LightBulb = this.LightBulb as object
|
|
85
|
+
}
|
|
86
|
+
accessory.context.LightBulb = this.LightBulb as object
|
|
85
87
|
|
|
86
88
|
if (this.adaptiveLighting && this.adaptiveLightingShift === -1 && this.LightBulb) {
|
|
87
|
-
accessory.removeService(this.LightBulb.Service)
|
|
88
|
-
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb)
|
|
89
|
-
accessory.context.adaptiveLighting = false
|
|
90
|
-
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
89
|
+
accessory.removeService(this.LightBulb.Service)
|
|
90
|
+
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb)
|
|
91
|
+
accessory.context.adaptiveLighting = false
|
|
92
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
91
93
|
} else if (this.adaptiveLighting && this.adaptiveLightingShift >= 0 && this.LightBulb) {
|
|
92
94
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
93
95
|
controllerMode: this.hap.AdaptiveLightingControllerMode.AUTOMATIC,
|
|
94
96
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
95
|
-
})
|
|
96
|
-
accessory.configureController(this.AdaptiveLightingController)
|
|
97
|
-
accessory.context.adaptiveLighting = true
|
|
97
|
+
})
|
|
98
|
+
accessory.configureController(this.AdaptiveLightingController)
|
|
99
|
+
accessory.context.adaptiveLighting = true
|
|
98
100
|
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}, adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
99
|
-
)
|
|
101
|
+
)
|
|
100
102
|
} else {
|
|
101
|
-
accessory.context.adaptiveLighting = false
|
|
102
|
-
this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`)
|
|
103
|
+
accessory.context.adaptiveLighting = false
|
|
104
|
+
this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`)
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
// Initialize LightBulb Characteristics
|
|
106
|
-
this.LightBulb.Service
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.LightBulb.Service
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
minValue: 0,
|
|
143
|
-
maxValue: 360,
|
|
144
|
-
validValueRanges: [0, 360],
|
|
145
|
-
})
|
|
146
|
-
.onGet(() => {
|
|
147
|
-
return this.LightBulb.Hue;
|
|
148
|
-
})
|
|
149
|
-
.onSet(this.HueSet.bind(this));
|
|
150
|
-
|
|
151
|
-
this.LightBulb.Service
|
|
152
|
-
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
153
|
-
.setProps({
|
|
154
|
-
minValue: 0,
|
|
155
|
-
maxValue: 100,
|
|
156
|
-
validValueRanges: [0, 100],
|
|
157
|
-
})
|
|
158
|
-
.onGet(() => {
|
|
159
|
-
return this.LightBulb.Saturation;
|
|
160
|
-
})
|
|
161
|
-
.onSet(this.SaturationSet.bind(this));
|
|
108
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
|
|
109
|
+
return this.LightBulb.On
|
|
110
|
+
}).onSet(this.OnSet.bind(this))
|
|
111
|
+
|
|
112
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Brightness).setProps({
|
|
113
|
+
minStep: device.colorbulb?.set_minStep ?? 1,
|
|
114
|
+
minValue: 0,
|
|
115
|
+
maxValue: 100,
|
|
116
|
+
validValueRanges: [0, 100],
|
|
117
|
+
}).onGet(() => {
|
|
118
|
+
return this.LightBulb.Brightness
|
|
119
|
+
}).onSet(this.BrightnessSet.bind(this))
|
|
120
|
+
|
|
121
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.ColorTemperature).setProps({
|
|
122
|
+
minValue: 140,
|
|
123
|
+
maxValue: 500,
|
|
124
|
+
validValueRanges: [140, 500],
|
|
125
|
+
}).onGet(() => {
|
|
126
|
+
return this.LightBulb.ColorTemperature!
|
|
127
|
+
}).onSet(this.ColorTemperatureSet.bind(this))
|
|
128
|
+
|
|
129
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Hue).setProps({
|
|
130
|
+
minValue: 0,
|
|
131
|
+
maxValue: 360,
|
|
132
|
+
validValueRanges: [0, 360],
|
|
133
|
+
}).onGet(() => {
|
|
134
|
+
return this.LightBulb.Hue
|
|
135
|
+
}).onSet(this.HueSet.bind(this))
|
|
136
|
+
|
|
137
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Saturation).setProps({
|
|
138
|
+
minValue: 0,
|
|
139
|
+
maxValue: 100,
|
|
140
|
+
validValueRanges: [0, 100],
|
|
141
|
+
}).onGet(() => {
|
|
142
|
+
return this.LightBulb.Saturation
|
|
143
|
+
}).onSet(this.SaturationSet.bind(this))
|
|
162
144
|
|
|
163
145
|
// Retrieve initial values and updateHomekit
|
|
164
146
|
try {
|
|
165
|
-
this.debugLog('Retrieve initial values and update Homekit')
|
|
166
|
-
this.refreshStatus()
|
|
147
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
148
|
+
this.refreshStatus()
|
|
167
149
|
} catch (e: any) {
|
|
168
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
150
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
169
151
|
}
|
|
170
152
|
|
|
171
|
-
//regisiter webhook event handler if enabled
|
|
153
|
+
// regisiter webhook event handler if enabled
|
|
172
154
|
try {
|
|
173
|
-
this.debugLog('Registering Webhook Event Handler')
|
|
174
|
-
this.registerWebhook()
|
|
155
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
156
|
+
this.registerWebhook()
|
|
175
157
|
} catch (e: any) {
|
|
176
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
158
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
177
159
|
}
|
|
178
160
|
|
|
179
|
-
//regisiter platform BLE event handler if enabled
|
|
161
|
+
// regisiter platform BLE event handler if enabled
|
|
180
162
|
try {
|
|
181
|
-
this.debugLog('Registering Platform BLE Event Handler')
|
|
182
|
-
this.registerPlatformBLE()
|
|
163
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
164
|
+
this.registerPlatformBLE()
|
|
183
165
|
} catch (e: any) {
|
|
184
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
166
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
185
167
|
}
|
|
186
168
|
|
|
187
169
|
// Start an update interval
|
|
188
170
|
interval(this.deviceRefreshRate * 1000)
|
|
189
171
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
190
172
|
.subscribe(async () => {
|
|
191
|
-
await this.refreshStatus()
|
|
192
|
-
})
|
|
173
|
+
await this.refreshStatus()
|
|
174
|
+
})
|
|
193
175
|
|
|
194
176
|
// Watch for Bulb change events
|
|
195
177
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
196
178
|
this.doColorBulbUpdate
|
|
197
179
|
.pipe(
|
|
198
180
|
tap(() => {
|
|
199
|
-
this.colorBulbUpdateInProgress = true
|
|
181
|
+
this.colorBulbUpdateInProgress = true
|
|
200
182
|
}),
|
|
201
183
|
debounceTime(this.devicePushRate * 1000),
|
|
202
184
|
)
|
|
203
185
|
.subscribe(async () => {
|
|
204
186
|
try {
|
|
205
|
-
await this.pushChanges()
|
|
187
|
+
await this.pushChanges()
|
|
206
188
|
} catch (e: any) {
|
|
207
|
-
await this.apiError(e)
|
|
208
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
189
|
+
await this.apiError(e)
|
|
190
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
209
191
|
}
|
|
210
|
-
this.colorBulbUpdateInProgress = false
|
|
211
|
-
})
|
|
192
|
+
this.colorBulbUpdateInProgress = false
|
|
193
|
+
})
|
|
212
194
|
}
|
|
213
195
|
|
|
214
196
|
/**
|
|
215
197
|
* Parse the device status from the SwitchBotBLE API
|
|
216
198
|
*/
|
|
217
199
|
async BLEparseStatus(): Promise<void> {
|
|
218
|
-
await this.debugLog('BLEparseStatus')
|
|
200
|
+
await this.debugLog('BLEparseStatus')
|
|
219
201
|
// On
|
|
220
|
-
this.LightBulb.On = this.serviceData.power
|
|
221
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
202
|
+
this.LightBulb.On = this.serviceData.power
|
|
203
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
222
204
|
// Brightness
|
|
223
|
-
this.LightBulb.Brightness = this.serviceData.brightness
|
|
224
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
205
|
+
this.LightBulb.Brightness = this.serviceData.brightness
|
|
206
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
225
207
|
// Color, Hue & Brightness
|
|
226
|
-
await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`)
|
|
227
|
-
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue)
|
|
228
|
-
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`)
|
|
208
|
+
await this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`)
|
|
209
|
+
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue)
|
|
210
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`)
|
|
229
211
|
// Hue
|
|
230
|
-
this.LightBulb.Hue = hue
|
|
231
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
212
|
+
this.LightBulb.Hue = hue
|
|
213
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
232
214
|
// Saturation
|
|
233
|
-
this.LightBulb.Saturation = saturation
|
|
234
|
-
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
215
|
+
this.LightBulb.Saturation = saturation
|
|
216
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
235
217
|
// ColorTemperature
|
|
236
|
-
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature)
|
|
237
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
238
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
218
|
+
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature)
|
|
219
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
220
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
239
221
|
}
|
|
240
222
|
|
|
241
223
|
/**
|
|
242
224
|
* Parse the device status from the SwitchBot OpenAPI
|
|
243
225
|
*/
|
|
244
226
|
async openAPIparseStatus(): Promise<void> {
|
|
245
|
-
await this.debugLog('openAPIparseStatus')
|
|
227
|
+
await this.debugLog('openAPIparseStatus')
|
|
246
228
|
// On
|
|
247
|
-
this.LightBulb.On = this.deviceStatus.power === 'on'
|
|
248
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
229
|
+
this.LightBulb.On = this.deviceStatus.power === 'on'
|
|
230
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
249
231
|
// Brightness
|
|
250
|
-
this.LightBulb.Brightness = this.deviceStatus.brightness
|
|
251
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
232
|
+
this.LightBulb.Brightness = this.deviceStatus.brightness
|
|
233
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
252
234
|
// Color, Hue & Brightness
|
|
253
|
-
await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`)
|
|
254
|
-
const [red, green, blue] = this.deviceStatus.color.split(':')
|
|
255
|
-
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
256
|
-
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
257
|
-
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
235
|
+
await this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`)
|
|
236
|
+
const [red, green, blue] = this.deviceStatus.color.split(':')
|
|
237
|
+
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
238
|
+
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
239
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
258
240
|
// Hue
|
|
259
|
-
this.LightBulb.Hue = hue
|
|
260
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
241
|
+
this.LightBulb.Hue = hue
|
|
242
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
261
243
|
// Saturation
|
|
262
|
-
this.LightBulb.Saturation = saturation
|
|
263
|
-
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
244
|
+
this.LightBulb.Saturation = saturation
|
|
245
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
264
246
|
// ColorTemperature
|
|
265
|
-
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature)
|
|
266
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
267
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
247
|
+
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature)
|
|
248
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
249
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
268
250
|
// Firmware Version
|
|
269
251
|
if (this.deviceStatus.version) {
|
|
270
|
-
const version = this.deviceStatus.version.toString()
|
|
271
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
272
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
252
|
+
const version = this.deviceStatus.version.toString()
|
|
253
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
254
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
273
255
|
this.accessory
|
|
274
256
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
275
257
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
276
258
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
277
259
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
278
|
-
.updateValue(deviceVersion)
|
|
279
|
-
this.accessory.context.version = deviceVersion
|
|
280
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
260
|
+
.updateValue(deviceVersion)
|
|
261
|
+
this.accessory.context.version = deviceVersion
|
|
262
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
281
263
|
}
|
|
282
264
|
}
|
|
283
265
|
|
|
284
266
|
async parseStatusWebhook(): Promise<void> {
|
|
285
|
-
await this.debugLog('parseStatusWebhook')
|
|
286
|
-
await this.debugLog(`(powerState, brightness, color, colorTemperature) = Webhook:(${this.webhookContext.powerState}
|
|
287
|
-
+ ` ${this.webhookContext.brightness}, ${this.webhookContext.color}, ${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On},`
|
|
288
|
-
+ ` ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation}, ${this.LightBulb.ColorTemperature})`);
|
|
267
|
+
await this.debugLog('parseStatusWebhook')
|
|
268
|
+
await this.debugLog(`(powerState, brightness, color, colorTemperature) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.color}, ${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation}, ${this.LightBulb.ColorTemperature})`)
|
|
289
269
|
// On
|
|
290
|
-
this.LightBulb.On = this.webhookContext.powerState === 'ON'
|
|
291
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
270
|
+
this.LightBulb.On = this.webhookContext.powerState === 'ON'
|
|
271
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
292
272
|
// Brightness
|
|
293
|
-
this.LightBulb.Brightness = this.webhookContext.brightness
|
|
294
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
273
|
+
this.LightBulb.Brightness = this.webhookContext.brightness
|
|
274
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
295
275
|
// Color, Hue & Brightness
|
|
296
|
-
await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`)
|
|
297
|
-
const [red, green, blue] = this.webhookContext.color.split(':')
|
|
298
|
-
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
299
|
-
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
300
|
-
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
276
|
+
await this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`)
|
|
277
|
+
const [red, green, blue] = this.webhookContext.color.split(':')
|
|
278
|
+
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
279
|
+
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
280
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
301
281
|
// Hue
|
|
302
|
-
this.LightBulb.Hue = hue
|
|
303
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
282
|
+
this.LightBulb.Hue = hue
|
|
283
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
304
284
|
// Saturation
|
|
305
|
-
this.LightBulb.Saturation = saturation
|
|
306
|
-
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
285
|
+
this.LightBulb.Saturation = saturation
|
|
286
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
307
287
|
// ColorTemperature
|
|
308
|
-
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature)
|
|
309
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
310
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
288
|
+
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature)
|
|
289
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
290
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
311
291
|
}
|
|
312
292
|
|
|
313
293
|
/**
|
|
@@ -315,422 +295,411 @@ export class ColorBulb extends deviceBase {
|
|
|
315
295
|
*/
|
|
316
296
|
async refreshStatus(): Promise<void> {
|
|
317
297
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
318
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
298
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
319
299
|
} else if (this.BLE) {
|
|
320
|
-
await this.BLERefreshStatus()
|
|
300
|
+
await this.BLERefreshStatus()
|
|
321
301
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
322
|
-
await this.openAPIRefreshStatus()
|
|
302
|
+
await this.openAPIRefreshStatus()
|
|
323
303
|
} else {
|
|
324
|
-
await this.offlineOff()
|
|
325
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
304
|
+
await this.offlineOff()
|
|
305
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
326
306
|
}
|
|
327
307
|
}
|
|
328
308
|
|
|
329
309
|
async BLERefreshStatus(): Promise<void> {
|
|
330
|
-
await this.debugLog('BLERefreshStatus')
|
|
331
|
-
const switchbot = await this.switchbotBLE()
|
|
310
|
+
await this.debugLog('BLERefreshStatus')
|
|
311
|
+
const switchbot = await this.switchbotBLE()
|
|
332
312
|
if (switchbot === undefined) {
|
|
333
|
-
await this.BLERefreshConnection(switchbot)
|
|
313
|
+
await this.BLERefreshConnection(switchbot)
|
|
334
314
|
} else {
|
|
335
315
|
// Start to monitor advertisement packets
|
|
336
316
|
(async () => {
|
|
337
317
|
// Start to monitor advertisement packets
|
|
338
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData
|
|
318
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData
|
|
339
319
|
// Update HomeKit
|
|
340
320
|
if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
|
|
341
|
-
this.serviceData = serviceData
|
|
342
|
-
await this.BLEparseStatus()
|
|
343
|
-
await this.updateHomeKitCharacteristics()
|
|
321
|
+
this.serviceData = serviceData
|
|
322
|
+
await this.BLEparseStatus()
|
|
323
|
+
await this.updateHomeKitCharacteristics()
|
|
344
324
|
} else {
|
|
345
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
346
|
-
await this.BLERefreshConnection(switchbot)
|
|
325
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
326
|
+
await this.BLERefreshConnection(switchbot)
|
|
347
327
|
}
|
|
348
|
-
})()
|
|
328
|
+
})()
|
|
349
329
|
}
|
|
350
330
|
}
|
|
351
331
|
|
|
352
332
|
async registerPlatformBLE(): Promise<void> {
|
|
353
|
-
await this.debugLog('registerPlatformBLE')
|
|
333
|
+
await this.debugLog('registerPlatformBLE')
|
|
354
334
|
if (this.config.options?.BLE) {
|
|
355
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
356
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
357
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
335
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
336
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
337
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
358
338
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: colorBulbServiceData) => {
|
|
359
339
|
try {
|
|
360
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
361
|
-
this.serviceData = context
|
|
362
|
-
await this.BLEparseStatus()
|
|
363
|
-
await this.updateHomeKitCharacteristics()
|
|
340
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
341
|
+
this.serviceData = context
|
|
342
|
+
await this.BLEparseStatus()
|
|
343
|
+
await this.updateHomeKitCharacteristics()
|
|
364
344
|
} catch (e: any) {
|
|
365
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
345
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
366
346
|
}
|
|
367
|
-
}
|
|
347
|
+
}
|
|
368
348
|
} else {
|
|
369
|
-
await this.debugLog('is not listening to Platform BLE')
|
|
349
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
370
350
|
}
|
|
371
351
|
}
|
|
372
352
|
|
|
373
353
|
async openAPIRefreshStatus(): Promise<void> {
|
|
374
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
354
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
375
355
|
try {
|
|
376
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
377
|
-
const deviceStatus: any = await body.json()
|
|
378
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
356
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
357
|
+
const deviceStatus: any = await body.json()
|
|
358
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
379
359
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
380
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
381
|
-
this.deviceStatus = deviceStatus.body
|
|
382
|
-
await this.openAPIparseStatus()
|
|
383
|
-
await this.updateHomeKitCharacteristics()
|
|
360
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
361
|
+
this.deviceStatus = deviceStatus.body
|
|
362
|
+
await this.openAPIparseStatus()
|
|
363
|
+
await this.updateHomeKitCharacteristics()
|
|
384
364
|
} else {
|
|
385
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
386
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
365
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
366
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
387
367
|
}
|
|
388
368
|
} catch (e: any) {
|
|
389
|
-
await this.apiError(e)
|
|
390
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
369
|
+
await this.apiError(e)
|
|
370
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
391
371
|
}
|
|
392
372
|
}
|
|
393
373
|
|
|
394
374
|
async registerWebhook() {
|
|
395
375
|
if (this.device.webhook) {
|
|
396
|
-
await this.debugLog('is listening webhook.')
|
|
376
|
+
await this.debugLog('is listening webhook.')
|
|
397
377
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: colorBulbWebhookContext) => {
|
|
398
378
|
try {
|
|
399
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
400
|
-
this.webhookContext = context
|
|
401
|
-
await this.parseStatusWebhook()
|
|
402
|
-
await this.updateHomeKitCharacteristics()
|
|
379
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
380
|
+
this.webhookContext = context
|
|
381
|
+
await this.parseStatusWebhook()
|
|
382
|
+
await this.updateHomeKitCharacteristics()
|
|
403
383
|
} catch (e: any) {
|
|
404
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
384
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
405
385
|
}
|
|
406
|
-
}
|
|
386
|
+
}
|
|
407
387
|
} else {
|
|
408
|
-
await this.debugLog('is not listening webhook.')
|
|
388
|
+
await this.debugLog('is not listening webhook.')
|
|
409
389
|
}
|
|
410
390
|
}
|
|
411
391
|
|
|
412
392
|
/**
|
|
413
393
|
* Pushes the requested changes to the SwitchBot API
|
|
414
|
-
* deviceType
|
|
415
|
-
* Color Bulb - "command"
|
|
416
|
-
* Color Bulb - "command"
|
|
417
|
-
* Color Bulb - "command"
|
|
418
|
-
* Color Bulb - "command" "setBrightness"
|
|
419
|
-
* Color Bulb - "command"
|
|
420
|
-
* Color Bulb - "command"
|
|
394
|
+
* deviceType commandType Command command parameter Description
|
|
395
|
+
* Color Bulb - "command" "turnOff" "default" = set to OFF state
|
|
396
|
+
* Color Bulb - "command" "turnOn" "default" = set to ON state
|
|
397
|
+
* Color Bulb - "command" "toggle" "default" = toggle state
|
|
398
|
+
* Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
|
|
399
|
+
* Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
|
|
400
|
+
* Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
|
|
421
401
|
*
|
|
422
402
|
*/
|
|
423
403
|
async pushChanges(): Promise<void> {
|
|
424
404
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
425
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
405
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
426
406
|
} else if (this.BLE) {
|
|
427
|
-
await this.BLEpushChanges()
|
|
407
|
+
await this.BLEpushChanges()
|
|
428
408
|
if (this.LightBulb.On) {
|
|
429
|
-
|
|
430
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
431
|
-
await this.BLEpushBrightnessChanges()
|
|
409
|
+
// Push Brightness Update
|
|
410
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
411
|
+
await this.BLEpushBrightnessChanges()
|
|
432
412
|
// Push ColorTemperature Update
|
|
433
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
434
|
-
await this.BLEpushColorTemperatureChanges()
|
|
413
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
414
|
+
await this.BLEpushColorTemperatureChanges()
|
|
435
415
|
// Push Hue & Saturation Update
|
|
436
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
437
|
-
await this.BLEpushRGBChanges()
|
|
416
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
417
|
+
await this.BLEpushRGBChanges()
|
|
438
418
|
} else {
|
|
439
|
-
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
419
|
+
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
440
420
|
}
|
|
441
421
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
442
|
-
await this.openAPIpushChanges()
|
|
422
|
+
await this.openAPIpushChanges()
|
|
443
423
|
if (this.LightBulb.On) {
|
|
444
424
|
// Push Brightness Update
|
|
445
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
446
|
-
await this.pushBrightnessChanges()
|
|
425
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
426
|
+
await this.pushBrightnessChanges()
|
|
447
427
|
// Push ColorTemperature Update
|
|
448
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
449
|
-
await this.pushColorTemperatureChanges()
|
|
428
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
429
|
+
await this.pushColorTemperatureChanges()
|
|
450
430
|
// Push Hue & Saturation Update
|
|
451
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
452
|
-
await this.pushHueSaturationChanges()
|
|
431
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
432
|
+
await this.pushHueSaturationChanges()
|
|
453
433
|
} else {
|
|
454
|
-
await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
434
|
+
await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
455
435
|
}
|
|
456
436
|
} else {
|
|
457
|
-
await this.offlineOff()
|
|
458
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
437
|
+
await this.offlineOff()
|
|
438
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
459
439
|
}
|
|
460
440
|
// Refresh the status from the API
|
|
461
441
|
interval(15000)
|
|
462
442
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
463
443
|
.pipe(take(1))
|
|
464
444
|
.subscribe(async () => {
|
|
465
|
-
await this.refreshStatus()
|
|
466
|
-
})
|
|
445
|
+
await this.refreshStatus()
|
|
446
|
+
})
|
|
467
447
|
}
|
|
468
448
|
|
|
469
449
|
async BLEpushChanges(): Promise<void> {
|
|
470
|
-
await this.debugLog('BLEpushChanges')
|
|
450
|
+
await this.debugLog('BLEpushChanges')
|
|
471
451
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
472
|
-
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
473
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
474
|
-
await this.convertBLEAddress()
|
|
452
|
+
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
453
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
454
|
+
await this.convertBLEAddress()
|
|
475
455
|
if (switchbot !== false) {
|
|
476
456
|
switchbot
|
|
477
457
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
478
458
|
.then(async (device_list: any) => {
|
|
479
|
-
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
459
|
+
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
480
460
|
return await this.retryBLE({
|
|
481
461
|
max: await this.maxRetryBLE(),
|
|
482
462
|
fn: async () => {
|
|
483
463
|
if (this.LightBulb.On) {
|
|
484
|
-
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
464
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
485
465
|
} else {
|
|
486
|
-
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
466
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
487
467
|
}
|
|
488
468
|
},
|
|
489
|
-
})
|
|
469
|
+
})
|
|
490
470
|
})
|
|
491
471
|
.then(async () => {
|
|
492
|
-
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
493
|
-
await this.updateHomeKitCharacteristics()
|
|
472
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
473
|
+
await this.updateHomeKitCharacteristics()
|
|
494
474
|
})
|
|
495
475
|
.catch(async (e: any) => {
|
|
496
|
-
await this.apiError(e)
|
|
497
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
498
|
-
await this.BLEPushConnection()
|
|
499
|
-
})
|
|
476
|
+
await this.apiError(e)
|
|
477
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
478
|
+
await this.BLEPushConnection()
|
|
479
|
+
})
|
|
500
480
|
} else {
|
|
501
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
502
|
-
await this.BLEPushConnection()
|
|
481
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
482
|
+
await this.BLEPushConnection()
|
|
503
483
|
}
|
|
504
484
|
} else {
|
|
505
|
-
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
485
|
+
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
506
486
|
}
|
|
507
487
|
}
|
|
508
488
|
|
|
509
489
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
510
|
-
await this.debugLog('BLEpushBrightnessChanges')
|
|
490
|
+
await this.debugLog('BLEpushBrightnessChanges')
|
|
511
491
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
512
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
513
|
-
await this.convertBLEAddress()
|
|
492
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
493
|
+
await this.convertBLEAddress()
|
|
514
494
|
if (switchbot !== false) {
|
|
515
495
|
switchbot
|
|
516
496
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
517
497
|
.then(async (device_list: any) => {
|
|
518
|
-
await this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`)
|
|
519
|
-
return await device_list[0].setBrightness(this.LightBulb.Brightness)
|
|
498
|
+
await this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`)
|
|
499
|
+
return await device_list[0].setBrightness(this.LightBulb.Brightness)
|
|
520
500
|
})
|
|
521
501
|
.then(async () => {
|
|
522
|
-
await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
|
|
523
|
-
await this.updateHomeKitCharacteristics()
|
|
502
|
+
await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
|
|
503
|
+
await this.updateHomeKitCharacteristics()
|
|
524
504
|
})
|
|
525
505
|
.catch(async (e: any) => {
|
|
526
|
-
await this.apiError(e)
|
|
527
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
528
|
-
await this.BLEPushConnection()
|
|
529
|
-
})
|
|
506
|
+
await this.apiError(e)
|
|
507
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
508
|
+
await this.BLEPushConnection()
|
|
509
|
+
})
|
|
530
510
|
} else {
|
|
531
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
532
|
-
await this.BLEPushConnection()
|
|
511
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
512
|
+
await this.BLEPushConnection()
|
|
533
513
|
}
|
|
534
514
|
} else {
|
|
535
|
-
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}
|
|
536
|
-
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
515
|
+
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
537
516
|
}
|
|
538
517
|
}
|
|
539
518
|
|
|
540
519
|
async BLEpushColorTemperatureChanges(): Promise<void> {
|
|
541
|
-
await this.debugLog('BLEpushColorTemperatureChanges')
|
|
520
|
+
await this.debugLog('BLEpushColorTemperatureChanges')
|
|
542
521
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
543
|
-
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
544
|
-
this.accessory.context.kelvin = kelvin
|
|
545
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
546
|
-
await this.convertBLEAddress()
|
|
522
|
+
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
523
|
+
this.accessory.context.kelvin = kelvin
|
|
524
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
525
|
+
await this.convertBLEAddress()
|
|
547
526
|
if (switchbot !== false) {
|
|
548
527
|
switchbot
|
|
549
528
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
550
529
|
.then(async (device_list: any) => {
|
|
551
|
-
await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
552
|
-
return await device_list[0].setColorTemperature(kelvin)
|
|
530
|
+
await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
531
|
+
return await device_list[0].setColorTemperature(kelvin)
|
|
553
532
|
})
|
|
554
533
|
.then(async () => {
|
|
555
|
-
await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`)
|
|
556
|
-
await this.updateHomeKitCharacteristics()
|
|
534
|
+
await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`)
|
|
535
|
+
await this.updateHomeKitCharacteristics()
|
|
557
536
|
})
|
|
558
537
|
.catch(async (e: any) => {
|
|
559
|
-
await this.apiError(e)
|
|
560
|
-
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
});
|
|
538
|
+
await this.apiError(e)
|
|
539
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
540
|
+
await this.BLEPushConnection()
|
|
541
|
+
})
|
|
564
542
|
} else {
|
|
565
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
566
|
-
await this.BLEPushConnection()
|
|
543
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
544
|
+
await this.BLEPushConnection()
|
|
567
545
|
}
|
|
568
546
|
} else {
|
|
569
|
-
await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}
|
|
570
|
-
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
547
|
+
await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
|
|
571
548
|
}
|
|
572
549
|
}
|
|
573
550
|
|
|
574
551
|
async BLEpushRGBChanges(): Promise<void> {
|
|
575
|
-
await this.debugLog('BLEpushRGBChanges')
|
|
552
|
+
await this.debugLog('BLEpushRGBChanges')
|
|
576
553
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
577
|
-
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
578
|
-
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
579
|
-
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
580
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
581
|
-
await this.convertBLEAddress()
|
|
554
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
555
|
+
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
556
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
557
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
558
|
+
await this.convertBLEAddress()
|
|
582
559
|
if (switchbot !== false) {
|
|
583
560
|
switchbot
|
|
584
561
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
585
562
|
.then(async (device_list: any) => {
|
|
586
|
-
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
587
|
-
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
|
|
563
|
+
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
564
|
+
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
|
|
588
565
|
})
|
|
589
566
|
.then(async () => {
|
|
590
|
-
await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
|
|
591
|
-
await this.updateHomeKitCharacteristics()
|
|
567
|
+
await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
|
|
568
|
+
await this.updateHomeKitCharacteristics()
|
|
592
569
|
})
|
|
593
570
|
.catch(async (e: any) => {
|
|
594
|
-
await this.apiError(e)
|
|
595
|
-
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
});
|
|
571
|
+
await this.apiError(e)
|
|
572
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
573
|
+
await this.BLEPushConnection()
|
|
574
|
+
})
|
|
599
575
|
} else {
|
|
600
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
601
|
-
await this.BLEPushConnection()
|
|
576
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
577
|
+
await this.BLEPushConnection()
|
|
602
578
|
}
|
|
603
579
|
} else {
|
|
604
|
-
await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}
|
|
605
|
-
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
580
|
+
await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
|
606
581
|
}
|
|
607
582
|
}
|
|
608
583
|
|
|
609
584
|
async openAPIpushChanges(): Promise<void> {
|
|
610
|
-
await this.debugLog('openAPIpushChanges')
|
|
585
|
+
await this.debugLog('openAPIpushChanges')
|
|
611
586
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
612
|
-
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
587
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
613
588
|
const bodyChange = JSON.stringify({
|
|
614
589
|
command: `${command}`,
|
|
615
590
|
parameter: 'default',
|
|
616
591
|
commandType: 'command',
|
|
617
|
-
})
|
|
618
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
592
|
+
})
|
|
593
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
619
594
|
try {
|
|
620
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
621
|
-
const deviceStatus: any = await body.json()
|
|
622
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
595
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
596
|
+
const deviceStatus: any = await body.json()
|
|
597
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
623
598
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
624
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
625
|
-
await this.updateHomeKitCharacteristics()
|
|
599
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
600
|
+
await this.updateHomeKitCharacteristics()
|
|
626
601
|
} else {
|
|
627
|
-
await this.statusCode(statusCode)
|
|
628
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
602
|
+
await this.statusCode(statusCode)
|
|
603
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
629
604
|
}
|
|
630
605
|
} catch (e: any) {
|
|
631
|
-
await this.apiError(e)
|
|
632
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
606
|
+
await this.apiError(e)
|
|
607
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
633
608
|
}
|
|
634
609
|
} else {
|
|
635
|
-
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
610
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
636
611
|
}
|
|
637
612
|
}
|
|
638
613
|
|
|
639
614
|
async pushHueSaturationChanges(): Promise<void> {
|
|
640
|
-
await this.debugLog('pushHueSaturationChanges')
|
|
615
|
+
await this.debugLog('pushHueSaturationChanges')
|
|
641
616
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
642
|
-
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
643
|
-
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
644
|
-
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
617
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
618
|
+
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
619
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
645
620
|
const bodyChange = JSON.stringify({
|
|
646
621
|
command: 'setColor',
|
|
647
622
|
parameter: `${red}:${green}:${blue}`,
|
|
648
623
|
commandType: 'command',
|
|
649
|
-
})
|
|
650
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
624
|
+
})
|
|
625
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
651
626
|
try {
|
|
652
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
653
|
-
const deviceStatus: any = await body.json()
|
|
654
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
627
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
628
|
+
const deviceStatus: any = await body.json()
|
|
629
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
655
630
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
656
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
657
|
-
await this.updateHomeKitCharacteristics()
|
|
631
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
632
|
+
await this.updateHomeKitCharacteristics()
|
|
658
633
|
} else {
|
|
659
|
-
await this.statusCode(statusCode)
|
|
660
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
634
|
+
await this.statusCode(statusCode)
|
|
635
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
661
636
|
}
|
|
662
637
|
} catch (e: any) {
|
|
663
|
-
await this.apiError(e)
|
|
664
|
-
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection
|
|
665
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
638
|
+
await this.apiError(e)
|
|
639
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
666
640
|
}
|
|
667
641
|
} else {
|
|
668
|
-
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}
|
|
669
|
-
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
642
|
+
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
|
670
643
|
}
|
|
671
644
|
}
|
|
672
645
|
|
|
673
646
|
async pushColorTemperatureChanges(): Promise<void> {
|
|
674
|
-
await this.debugLog('pushColorTemperatureChanges')
|
|
647
|
+
await this.debugLog('pushColorTemperatureChanges')
|
|
675
648
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
676
|
-
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
677
|
-
this.accessory.context.kelvin = kelvin
|
|
649
|
+
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
650
|
+
this.accessory.context.kelvin = kelvin
|
|
678
651
|
const bodyChange = JSON.stringify({
|
|
679
652
|
command: 'setColorTemperature',
|
|
680
653
|
parameter: `${kelvin}`,
|
|
681
654
|
commandType: 'command',
|
|
682
|
-
})
|
|
683
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
655
|
+
})
|
|
656
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
684
657
|
try {
|
|
685
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
686
|
-
const deviceStatus: any = await body.json()
|
|
687
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
658
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
659
|
+
const deviceStatus: any = await body.json()
|
|
660
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
688
661
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
689
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
690
|
-
await this.updateHomeKitCharacteristics()
|
|
662
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
663
|
+
await this.updateHomeKitCharacteristics()
|
|
691
664
|
} else {
|
|
692
|
-
await this.statusCode(statusCode)
|
|
693
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
665
|
+
await this.statusCode(statusCode)
|
|
666
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
694
667
|
}
|
|
695
668
|
} catch (e: any) {
|
|
696
|
-
await this.apiError(e)
|
|
697
|
-
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection
|
|
698
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
669
|
+
await this.apiError(e)
|
|
670
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
699
671
|
}
|
|
700
672
|
} else {
|
|
701
|
-
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}
|
|
702
|
-
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
673
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
|
|
703
674
|
}
|
|
704
675
|
}
|
|
705
676
|
|
|
706
677
|
async pushBrightnessChanges(): Promise<void> {
|
|
707
|
-
await this.debugLog('pushBrightnessChanges')
|
|
678
|
+
await this.debugLog('pushBrightnessChanges')
|
|
708
679
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
709
680
|
const bodyChange = JSON.stringify({
|
|
710
681
|
command: 'setBrightness',
|
|
711
682
|
parameter: `${this.LightBulb.Brightness}`,
|
|
712
683
|
commandType: 'command',
|
|
713
|
-
})
|
|
714
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
684
|
+
})
|
|
685
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
715
686
|
try {
|
|
716
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
717
|
-
const deviceStatus: any = await body.json()
|
|
718
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
687
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
688
|
+
const deviceStatus: any = await body.json()
|
|
689
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
719
690
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
720
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
721
|
-
await this.updateHomeKitCharacteristics()
|
|
691
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
692
|
+
await this.updateHomeKitCharacteristics()
|
|
722
693
|
} else {
|
|
723
|
-
await this.statusCode(statusCode)
|
|
724
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
694
|
+
await this.statusCode(statusCode)
|
|
695
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
725
696
|
}
|
|
726
697
|
} catch (e: any) {
|
|
727
|
-
await this.apiError(e)
|
|
728
|
-
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection
|
|
729
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
698
|
+
await this.apiError(e)
|
|
699
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
730
700
|
}
|
|
731
701
|
} else {
|
|
732
|
-
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}
|
|
733
|
-
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
702
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
734
703
|
}
|
|
735
704
|
}
|
|
736
705
|
|
|
@@ -739,13 +708,13 @@ export class ColorBulb extends deviceBase {
|
|
|
739
708
|
*/
|
|
740
709
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
741
710
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
742
|
-
await this.infoLog(`Set On: ${value}`)
|
|
711
|
+
await this.infoLog(`Set On: ${value}`)
|
|
743
712
|
} else {
|
|
744
|
-
await this.debugLog(`No Changes, On: ${value}`)
|
|
713
|
+
await this.debugLog(`No Changes, On: ${value}`)
|
|
745
714
|
}
|
|
746
715
|
|
|
747
|
-
this.LightBulb.On = value
|
|
748
|
-
this.doColorBulbUpdate.next()
|
|
716
|
+
this.LightBulb.On = value
|
|
717
|
+
this.doColorBulbUpdate.next()
|
|
749
718
|
}
|
|
750
719
|
|
|
751
720
|
/**
|
|
@@ -753,17 +722,17 @@ export class ColorBulb extends deviceBase {
|
|
|
753
722
|
*/
|
|
754
723
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
755
724
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
756
|
-
await this.infoLog(`Set Brightness: ${value}`)
|
|
725
|
+
await this.infoLog(`Set Brightness: ${value}`)
|
|
757
726
|
} else {
|
|
758
727
|
if (this.LightBulb.On) {
|
|
759
|
-
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
728
|
+
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
760
729
|
} else {
|
|
761
|
-
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
730
|
+
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
762
731
|
}
|
|
763
732
|
}
|
|
764
733
|
|
|
765
|
-
this.LightBulb.Brightness = value
|
|
766
|
-
this.doColorBulbUpdate.next()
|
|
734
|
+
this.LightBulb.Brightness = value
|
|
735
|
+
this.doColorBulbUpdate.next()
|
|
767
736
|
}
|
|
768
737
|
|
|
769
738
|
/**
|
|
@@ -771,34 +740,34 @@ export class ColorBulb extends deviceBase {
|
|
|
771
740
|
*/
|
|
772
741
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
773
742
|
if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
|
|
774
|
-
this.infoLog(`Set ColorTemperature: ${value}`)
|
|
743
|
+
this.infoLog(`Set ColorTemperature: ${value}`)
|
|
775
744
|
} else {
|
|
776
745
|
if (this.LightBulb.On) {
|
|
777
|
-
this.debugLog(`No Changes, ColorTemperature: ${value}`)
|
|
746
|
+
this.debugLog(`No Changes, ColorTemperature: ${value}`)
|
|
778
747
|
} else {
|
|
779
|
-
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`)
|
|
748
|
+
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`)
|
|
780
749
|
}
|
|
781
750
|
}
|
|
782
751
|
|
|
783
|
-
const minKelvin = 2000
|
|
784
|
-
const maxKelvin = 9000
|
|
752
|
+
const minKelvin = 2000
|
|
753
|
+
const maxKelvin = 9000
|
|
785
754
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
786
|
-
const kelvin = Math.round(1000000 / Number(value) / 100) * 100
|
|
755
|
+
const kelvin = Math.round(1000000 / Number(value) / 100) * 100
|
|
787
756
|
|
|
788
757
|
// Check and increase/decrease kelvin to range of device
|
|
789
|
-
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin)
|
|
758
|
+
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin)
|
|
790
759
|
|
|
791
760
|
if (!this.accessory.context.On || this.accessory.context.kelvin === k) {
|
|
792
|
-
return
|
|
761
|
+
return
|
|
793
762
|
}
|
|
794
763
|
|
|
795
764
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
796
|
-
const hs = m2hs(value)
|
|
797
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0])
|
|
798
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1])
|
|
765
|
+
const hs = m2hs(value)
|
|
766
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0])
|
|
767
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1])
|
|
799
768
|
|
|
800
|
-
this.LightBulb.ColorTemperature = value
|
|
801
|
-
this.doColorBulbUpdate.next()
|
|
769
|
+
this.LightBulb.ColorTemperature = value
|
|
770
|
+
this.doColorBulbUpdate.next()
|
|
802
771
|
}
|
|
803
772
|
|
|
804
773
|
/**
|
|
@@ -806,19 +775,19 @@ export class ColorBulb extends deviceBase {
|
|
|
806
775
|
*/
|
|
807
776
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
808
777
|
if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
|
|
809
|
-
this.infoLog(`Set Hue: ${value}`)
|
|
778
|
+
this.infoLog(`Set Hue: ${value}`)
|
|
810
779
|
} else {
|
|
811
780
|
if (this.LightBulb.On) {
|
|
812
|
-
this.debugLog(`No Changes, Hue: ${value}`)
|
|
781
|
+
this.debugLog(`No Changes, Hue: ${value}`)
|
|
813
782
|
} else {
|
|
814
|
-
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`)
|
|
783
|
+
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`)
|
|
815
784
|
}
|
|
816
785
|
}
|
|
817
786
|
|
|
818
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
787
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
819
788
|
|
|
820
|
-
this.LightBulb.Hue = value
|
|
821
|
-
this.doColorBulbUpdate.next()
|
|
789
|
+
this.LightBulb.Hue = value
|
|
790
|
+
this.doColorBulbUpdate.next()
|
|
822
791
|
}
|
|
823
792
|
|
|
824
793
|
/**
|
|
@@ -826,79 +795,74 @@ export class ColorBulb extends deviceBase {
|
|
|
826
795
|
*/
|
|
827
796
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
828
797
|
if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
829
|
-
this.infoLog(`Set Saturation: ${value}`)
|
|
798
|
+
this.infoLog(`Set Saturation: ${value}`)
|
|
830
799
|
} else {
|
|
831
800
|
if (this.LightBulb.On) {
|
|
832
|
-
this.debugLog(`No Changes, Saturation: ${value}`)
|
|
801
|
+
this.debugLog(`No Changes, Saturation: ${value}`)
|
|
833
802
|
} else {
|
|
834
|
-
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`)
|
|
803
|
+
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`)
|
|
835
804
|
}
|
|
836
805
|
}
|
|
837
806
|
|
|
838
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
807
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
839
808
|
|
|
840
|
-
this.LightBulb.Saturation = value
|
|
841
|
-
this.doColorBulbUpdate.next()
|
|
809
|
+
this.LightBulb.Saturation = value
|
|
810
|
+
this.doColorBulbUpdate.next()
|
|
842
811
|
}
|
|
843
812
|
|
|
844
813
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
845
814
|
// On
|
|
846
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
847
|
-
this.LightBulb.On, 'On');
|
|
815
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
|
|
848
816
|
// Brightness
|
|
849
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
|
|
850
|
-
this.LightBulb.Brightness, 'Brightness');
|
|
817
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness')
|
|
851
818
|
// ColorTemperature
|
|
852
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
|
|
853
|
-
this.LightBulb.ColorTemperature, 'ColorTemperature');
|
|
819
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature, 'ColorTemperature')
|
|
854
820
|
// Hue
|
|
855
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
|
|
856
|
-
this.LightBulb.Hue, 'Hue');
|
|
821
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue, this.LightBulb.Hue, 'Hue')
|
|
857
822
|
// Saturation
|
|
858
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
|
|
859
|
-
this.LightBulb.Saturation, 'Saturation');
|
|
823
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation, this.LightBulb.Saturation, 'Saturation')
|
|
860
824
|
}
|
|
861
825
|
|
|
862
826
|
async getAdaptiveLightingSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
863
827
|
// Adaptive Lighting
|
|
864
|
-
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
|
|
865
|
-
await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
828
|
+
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
|
|
829
|
+
await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
866
830
|
// Adaptive Lighting Shift
|
|
867
831
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
868
|
-
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift
|
|
869
|
-
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
832
|
+
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift
|
|
833
|
+
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
870
834
|
} else {
|
|
871
|
-
this.adaptiveLightingShift = 0
|
|
872
|
-
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
835
|
+
this.adaptiveLightingShift = 0
|
|
836
|
+
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
873
837
|
}
|
|
874
838
|
}
|
|
875
839
|
|
|
876
840
|
async BLEPushConnection() {
|
|
877
841
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
878
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
879
|
-
await this.openAPIpushChanges()
|
|
842
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
843
|
+
await this.openAPIpushChanges()
|
|
880
844
|
}
|
|
881
845
|
}
|
|
882
846
|
|
|
883
847
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
884
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
848
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
885
849
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
886
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
887
|
-
await this.openAPIRefreshStatus()
|
|
850
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
851
|
+
await this.openAPIRefreshStatus()
|
|
888
852
|
}
|
|
889
853
|
}
|
|
890
854
|
|
|
891
855
|
async offlineOff(): Promise<void> {
|
|
892
856
|
if (this.device.offline) {
|
|
893
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
857
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
894
858
|
}
|
|
895
859
|
}
|
|
896
860
|
|
|
897
861
|
async apiError(e: any): Promise<void> {
|
|
898
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
899
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e)
|
|
900
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e)
|
|
901
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e)
|
|
902
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e)
|
|
862
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
863
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e)
|
|
864
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e)
|
|
865
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e)
|
|
866
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e)
|
|
903
867
|
}
|
|
904
868
|
}
|