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