@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
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
*
|
|
3
3
|
* ceilinglight.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 { ceilingLightProServiceData, ceilingLightServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { ceilingLightProStatus, ceilingLightStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { ceilingLightProWebhookContext, ceilingLightWebhookContext } 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 } 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 CeilingLight 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!: ceilingLightStatus | ceilingLightProStatus
|
|
42
|
+
deviceStatus!: ceilingLightStatus | ceilingLightProStatus
|
|
37
43
|
|
|
38
|
-
//Webhook
|
|
39
|
-
webhookContext!: ceilingLightWebhookContext | ceilingLightProWebhookContext
|
|
44
|
+
// Webhook
|
|
45
|
+
webhookContext!: ceilingLightWebhookContext | ceilingLightProWebhookContext
|
|
40
46
|
|
|
41
47
|
// BLE
|
|
42
|
-
serviceData!: ceilingLightServiceData | ceilingLightProServiceData
|
|
48
|
+
serviceData!: ceilingLightServiceData | ceilingLightProServiceData
|
|
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
|
-
ceilingLightUpdateInProgress!: boolean
|
|
51
|
-
doCeilingLightUpdate!: Subject<void
|
|
56
|
+
ceilingLightUpdateInProgress!: boolean
|
|
57
|
+
doCeilingLightUpdate!: 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.doCeilingLightUpdate = new Subject()
|
|
67
|
-
this.ceilingLightUpdateInProgress = false
|
|
72
|
+
this.doCeilingLightUpdate = new Subject()
|
|
73
|
+
this.ceilingLightUpdateInProgress = false
|
|
68
74
|
|
|
69
75
|
// Initialize LightBulb Service
|
|
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,197 +82,190 @@ export class CeilingLight 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
|
-
.onGet(() => {
|
|
106
|
-
return this.LightBulb.On;
|
|
107
|
-
})
|
|
108
|
-
.onSet(this.OnSet.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))
|
|
109
111
|
|
|
110
112
|
// Initialize LightBulb Brightness
|
|
111
|
-
this.LightBulb.Service
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.onGet(() => {
|
|
120
|
-
return this.LightBulb.Brightness;
|
|
121
|
-
})
|
|
122
|
-
.onSet(this.BrightnessSet.bind(this));
|
|
113
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Brightness).setProps({
|
|
114
|
+
minStep: device.ceilinglight?.set_minStep ?? 1,
|
|
115
|
+
minValue: 0,
|
|
116
|
+
maxValue: 100,
|
|
117
|
+
validValueRanges: [0, 100],
|
|
118
|
+
}).onGet(() => {
|
|
119
|
+
return this.LightBulb.Brightness
|
|
120
|
+
}).onSet(this.BrightnessSet.bind(this))
|
|
123
121
|
|
|
124
122
|
// Initialize LightBulb ColorTemperature
|
|
125
|
-
this.LightBulb.Service
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
.onGet(() => {
|
|
133
|
-
return this.LightBulb.ColorTemperature!;
|
|
134
|
-
})
|
|
135
|
-
.onSet(this.ColorTemperatureSet.bind(this));
|
|
123
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.ColorTemperature).setProps({
|
|
124
|
+
minValue: 140,
|
|
125
|
+
maxValue: 500,
|
|
126
|
+
validValueRanges: [140, 500],
|
|
127
|
+
}).onGet(() => {
|
|
128
|
+
return this.LightBulb.ColorTemperature!
|
|
129
|
+
}).onSet(this.ColorTemperatureSet.bind(this))
|
|
136
130
|
|
|
137
131
|
// Initialize LightBulb Hue
|
|
138
|
-
this.LightBulb.Service
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.onGet(() => {
|
|
146
|
-
return this.LightBulb.Hue;
|
|
147
|
-
})
|
|
148
|
-
.onSet(this.HueSet.bind(this));
|
|
132
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Hue).setProps({
|
|
133
|
+
minValue: 0,
|
|
134
|
+
maxValue: 360,
|
|
135
|
+
validValueRanges: [0, 360],
|
|
136
|
+
}).onGet(() => {
|
|
137
|
+
return this.LightBulb.Hue
|
|
138
|
+
}).onSet(this.HueSet.bind(this))
|
|
149
139
|
|
|
150
140
|
// Initialize LightBulb Saturation
|
|
151
|
-
this.LightBulb.Service
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
.onGet(() => {
|
|
159
|
-
return this.LightBulb.Saturation;
|
|
160
|
-
})
|
|
161
|
-
.onSet(this.SaturationSet.bind(this));
|
|
141
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.Saturation).setProps({
|
|
142
|
+
minValue: 0,
|
|
143
|
+
maxValue: 100,
|
|
144
|
+
validValueRanges: [0, 100],
|
|
145
|
+
}).onGet(() => {
|
|
146
|
+
return this.LightBulb.Saturation
|
|
147
|
+
}).onSet(this.SaturationSet.bind(this))
|
|
162
148
|
|
|
163
149
|
// Retrieve initial values and updateHomekit
|
|
164
|
-
|
|
165
|
-
|
|
150
|
+
try {
|
|
151
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
152
|
+
this.refreshStatus()
|
|
153
|
+
} catch (e: any) {
|
|
154
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
155
|
+
}
|
|
166
156
|
|
|
167
|
-
//regisiter webhook event handler
|
|
168
|
-
|
|
169
|
-
|
|
157
|
+
// regisiter webhook event handler if enabled
|
|
158
|
+
try {
|
|
159
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
160
|
+
this.registerWebhook()
|
|
161
|
+
} catch (e: any) {
|
|
162
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// regisiter platform BLE event handler if enabled
|
|
166
|
+
try {
|
|
167
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
168
|
+
this.registerPlatformBLE()
|
|
169
|
+
} catch (e: any) {
|
|
170
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
171
|
+
}
|
|
170
172
|
|
|
171
173
|
// Start an update interval
|
|
172
174
|
interval(this.deviceRefreshRate * 1000)
|
|
173
175
|
.pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
|
|
174
176
|
.subscribe(async () => {
|
|
175
|
-
await this.refreshStatus()
|
|
176
|
-
})
|
|
177
|
+
await this.refreshStatus()
|
|
178
|
+
})
|
|
177
179
|
|
|
178
180
|
// Watch for Bulb change events
|
|
179
181
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
180
182
|
this.doCeilingLightUpdate
|
|
181
183
|
.pipe(
|
|
182
184
|
tap(() => {
|
|
183
|
-
this.ceilingLightUpdateInProgress = true
|
|
185
|
+
this.ceilingLightUpdateInProgress = true
|
|
184
186
|
}),
|
|
185
187
|
debounceTime(this.devicePushRate * 1000),
|
|
186
188
|
)
|
|
187
189
|
.subscribe(async () => {
|
|
188
190
|
try {
|
|
189
|
-
await this.pushChanges()
|
|
191
|
+
await this.pushChanges()
|
|
190
192
|
} catch (e: any) {
|
|
191
|
-
await this.apiError(e)
|
|
192
|
-
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
193
|
+
await this.apiError(e)
|
|
194
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
193
195
|
}
|
|
194
|
-
this.ceilingLightUpdateInProgress = false
|
|
195
|
-
})
|
|
196
|
+
this.ceilingLightUpdateInProgress = false
|
|
197
|
+
})
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
/**
|
|
199
201
|
* Parse the device status from the SwitchBotBLE API
|
|
200
202
|
*/
|
|
201
203
|
async BLEparseStatus(): Promise<void> {
|
|
202
|
-
await this.debugLog('BLEparseStatus')
|
|
203
|
-
await this.debugLog(`(power, brightness, colorTemperature) = BLE:(${this.serviceData.state}, ${this.serviceData.brightness}, `
|
|
204
|
-
+ `${this.serviceData.color_temperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
204
|
+
await this.debugLog('BLEparseStatus')
|
|
205
|
+
await this.debugLog(`(power, brightness, colorTemperature) = BLE:(${this.serviceData.state}, ${this.serviceData.brightness}, ${this.serviceData.color_temperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`)
|
|
205
206
|
|
|
206
207
|
// On
|
|
207
|
-
this.LightBulb.On = this.serviceData.state
|
|
208
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
208
|
+
this.LightBulb.On = this.serviceData.state
|
|
209
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
209
210
|
|
|
210
211
|
// ColorTemperature
|
|
211
|
-
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature)
|
|
212
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
213
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
212
|
+
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature)
|
|
213
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
214
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
/**
|
|
217
218
|
* Parse the device status from the SwitchBot OpenAPI
|
|
218
219
|
*/
|
|
219
220
|
async openAPIparseStatus(): Promise<void> {
|
|
220
|
-
await this.debugLog('openAPIparseStatus')
|
|
221
|
-
await this.debugLog(`(power, brightness, colorTemperature) = OpenAPI:(${this.deviceStatus.power}, ${this.deviceStatus.brightness}, `
|
|
222
|
-
+ `${this.deviceStatus.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
221
|
+
await this.debugLog('openAPIparseStatus')
|
|
222
|
+
await this.debugLog(`(power, brightness, colorTemperature) = OpenAPI:(${this.deviceStatus.power}, ${this.deviceStatus.brightness}, ${this.deviceStatus.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`)
|
|
223
223
|
|
|
224
224
|
// On
|
|
225
|
-
this.LightBulb.On = this.deviceStatus.power
|
|
226
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
225
|
+
this.LightBulb.On = this.deviceStatus.power
|
|
226
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
227
227
|
|
|
228
228
|
// Brightness
|
|
229
|
-
this.LightBulb.Brightness = this.deviceStatus.brightness
|
|
230
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
229
|
+
this.LightBulb.Brightness = this.deviceStatus.brightness
|
|
230
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
231
231
|
|
|
232
232
|
// ColorTemperature
|
|
233
|
-
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature)
|
|
234
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
235
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
233
|
+
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature)
|
|
234
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
235
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
236
236
|
|
|
237
237
|
// Firmware Version
|
|
238
238
|
if (this.deviceStatus.version) {
|
|
239
|
-
const version = this.deviceStatus.version.toString()
|
|
240
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
241
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
239
|
+
const version = this.deviceStatus.version.toString()
|
|
240
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
241
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
242
242
|
this.accessory
|
|
243
243
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
244
244
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
245
245
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
246
246
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
247
|
-
.updateValue(deviceVersion)
|
|
248
|
-
this.accessory.context.version = deviceVersion
|
|
249
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
247
|
+
.updateValue(deviceVersion)
|
|
248
|
+
this.accessory.context.version = deviceVersion
|
|
249
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
async parseStatusWebhook(): Promise<void> {
|
|
254
|
-
await this.debugLog('parseStatusWebhook')
|
|
255
|
-
await this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, `
|
|
256
|
-
+ `${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
254
|
+
await this.debugLog('parseStatusWebhook')
|
|
255
|
+
await this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`)
|
|
257
256
|
|
|
258
257
|
// On
|
|
259
|
-
this.LightBulb.On = this.webhookContext.powerState === 'ON'
|
|
260
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
258
|
+
this.LightBulb.On = this.webhookContext.powerState === 'ON'
|
|
259
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
261
260
|
|
|
262
261
|
// Brightness
|
|
263
|
-
this.LightBulb.Brightness = this.webhookContext.brightness
|
|
264
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
262
|
+
this.LightBulb.Brightness = this.webhookContext.brightness
|
|
263
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
265
264
|
|
|
266
265
|
// ColorTemperature
|
|
267
|
-
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature)
|
|
268
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
269
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
266
|
+
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature)
|
|
267
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140)
|
|
268
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
270
269
|
}
|
|
271
270
|
|
|
272
271
|
/**
|
|
@@ -274,307 +273,304 @@ export class CeilingLight extends deviceBase {
|
|
|
274
273
|
*/
|
|
275
274
|
async refreshStatus(): Promise<void> {
|
|
276
275
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
277
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
278
|
-
} else if (this.BLE
|
|
279
|
-
await this.BLERefreshStatus()
|
|
276
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
277
|
+
} else if (this.BLE) {
|
|
278
|
+
await this.BLERefreshStatus()
|
|
280
279
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
281
|
-
await this.openAPIRefreshStatus()
|
|
280
|
+
await this.openAPIRefreshStatus()
|
|
282
281
|
} else {
|
|
283
|
-
await this.offlineOff()
|
|
284
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
282
|
+
await this.offlineOff()
|
|
283
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
285
284
|
}
|
|
286
285
|
}
|
|
287
286
|
|
|
288
287
|
async BLERefreshStatus(): Promise<void> {
|
|
289
|
-
await this.debugLog('BLERefreshStatus')
|
|
288
|
+
await this.debugLog('BLERefreshStatus')
|
|
289
|
+
const switchbot = await this.switchbotBLE()
|
|
290
|
+
if (switchbot === undefined) {
|
|
291
|
+
await this.BLERefreshConnection(switchbot)
|
|
292
|
+
} else {
|
|
293
|
+
(async () => {
|
|
294
|
+
// Start to monitor advertisement packets
|
|
295
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData
|
|
296
|
+
// Update HomeKit
|
|
297
|
+
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro) && (serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro)) {
|
|
298
|
+
this.serviceData = serviceData
|
|
299
|
+
await this.BLEparseStatus()
|
|
300
|
+
await this.updateHomeKitCharacteristics()
|
|
301
|
+
} else {
|
|
302
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
303
|
+
await this.BLERefreshConnection(switchbot)
|
|
304
|
+
}
|
|
305
|
+
})()
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async registerPlatformBLE(): Promise<void> {
|
|
310
|
+
await this.debugLog('registerPlatformBLE')
|
|
290
311
|
if (this.config.options?.BLE) {
|
|
291
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
292
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
293
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
294
|
-
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData) => {
|
|
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}`)
|
|
315
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData | ceilingLightProServiceData) => {
|
|
295
316
|
try {
|
|
296
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
297
|
-
this.serviceData = context
|
|
298
|
-
await this.BLEparseStatus()
|
|
299
|
-
await this.updateHomeKitCharacteristics()
|
|
317
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
318
|
+
this.serviceData = context
|
|
319
|
+
await this.BLEparseStatus()
|
|
320
|
+
await this.updateHomeKitCharacteristics()
|
|
300
321
|
} catch (e: any) {
|
|
301
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
322
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
302
323
|
}
|
|
303
|
-
};
|
|
304
|
-
} else {
|
|
305
|
-
await this.debugLog('is using Device BLE Scanning.');
|
|
306
|
-
const switchbot = await this.switchbotBLE();
|
|
307
|
-
if (switchbot === undefined) {
|
|
308
|
-
await this.BLERefreshConnection(switchbot);
|
|
309
|
-
} else {
|
|
310
|
-
(async () => {
|
|
311
|
-
// Start to monitor advertisement packets
|
|
312
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
|
|
313
|
-
// Update HomeKit
|
|
314
|
-
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
315
|
-
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
316
|
-
this.serviceData = serviceData;
|
|
317
|
-
await this.BLEparseStatus();
|
|
318
|
-
await this.updateHomeKitCharacteristics();
|
|
319
|
-
} else {
|
|
320
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
321
|
-
await this.BLERefreshConnection(switchbot);
|
|
322
|
-
}
|
|
323
|
-
})();
|
|
324
324
|
}
|
|
325
|
+
} else {
|
|
326
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
325
327
|
}
|
|
326
328
|
}
|
|
327
329
|
|
|
328
330
|
async openAPIRefreshStatus(): Promise<void> {
|
|
329
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
331
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
330
332
|
try {
|
|
331
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
332
|
-
const deviceStatus: any = await body.json()
|
|
333
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
333
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
334
|
+
const deviceStatus: any = await body.json()
|
|
335
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
334
336
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
335
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
336
|
-
this.deviceStatus = deviceStatus.body
|
|
337
|
-
await this.openAPIparseStatus()
|
|
338
|
-
await this.updateHomeKitCharacteristics()
|
|
337
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
+
this.deviceStatus = deviceStatus.body
|
|
339
|
+
await this.openAPIparseStatus()
|
|
340
|
+
await this.updateHomeKitCharacteristics()
|
|
339
341
|
} else {
|
|
340
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
341
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
342
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
342
344
|
}
|
|
343
345
|
} catch (e: any) {
|
|
344
|
-
await this.apiError(e)
|
|
345
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
346
|
+
await this.apiError(e)
|
|
347
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
346
348
|
}
|
|
347
349
|
}
|
|
348
350
|
|
|
349
351
|
async registerWebhook() {
|
|
350
352
|
if (this.device.webhook) {
|
|
351
|
-
await this.debugLog('is listening webhook.')
|
|
353
|
+
await this.debugLog('is listening webhook.')
|
|
352
354
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: ceilingLightWebhookContext | ceilingLightProWebhookContext) => {
|
|
353
355
|
try {
|
|
354
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
355
|
-
this.webhookContext = context
|
|
356
|
-
await this.parseStatusWebhook()
|
|
357
|
-
await this.updateHomeKitCharacteristics()
|
|
356
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
357
|
+
this.webhookContext = context
|
|
358
|
+
await this.parseStatusWebhook()
|
|
359
|
+
await this.updateHomeKitCharacteristics()
|
|
358
360
|
} catch (e: any) {
|
|
359
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
361
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
360
362
|
}
|
|
361
|
-
}
|
|
363
|
+
}
|
|
362
364
|
} else {
|
|
363
|
-
await this.debugLog('is not listening webhook.')
|
|
365
|
+
await this.debugLog('is not listening webhook.')
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
/**
|
|
368
370
|
* Pushes the requested changes to the SwitchBot API
|
|
369
|
-
* deviceType
|
|
370
|
-
* Color Bulb -
|
|
371
|
-
* Color Bulb -
|
|
372
|
-
* Color Bulb -
|
|
373
|
-
* Color Bulb -
|
|
374
|
-
* Color Bulb -
|
|
375
|
-
* Color Bulb -
|
|
371
|
+
* deviceType commandType Command command parameter Description
|
|
372
|
+
* Color Bulb - "command" "turnOff" "default" = set to OFF state
|
|
373
|
+
* Color Bulb - "command" "turnOn" "default" = set to ON state
|
|
374
|
+
* Color Bulb - "command" "toggle" "default" = toggle state
|
|
375
|
+
* Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
|
|
376
|
+
* Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
|
|
377
|
+
* Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
|
|
376
378
|
*
|
|
377
379
|
*/
|
|
378
380
|
async pushChanges(): Promise<void> {
|
|
379
381
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
380
|
-
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
382
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
381
383
|
} else if (this.BLE) {
|
|
382
|
-
await this.BLEpushChanges()
|
|
384
|
+
await this.BLEpushChanges()
|
|
383
385
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
384
|
-
await this.openAPIpushChanges()
|
|
386
|
+
await this.openAPIpushChanges()
|
|
385
387
|
if (this.LightBulb.On) {
|
|
386
|
-
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
388
|
+
await this.debugLog(`On: ${this.LightBulb.On}`)
|
|
387
389
|
// Push Brightness Update
|
|
388
|
-
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
389
|
-
await this.pushBrightnessChanges()
|
|
390
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
391
|
+
await this.pushBrightnessChanges()
|
|
390
392
|
// Push ColorTemperature Update
|
|
391
|
-
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
392
|
-
await this.pushColorTemperatureChanges()
|
|
393
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
394
|
+
await this.pushColorTemperatureChanges()
|
|
393
395
|
// Push Hue & Saturation Update
|
|
394
|
-
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
395
|
-
await this.pushHueSaturationChanges()
|
|
396
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
397
|
+
await this.pushHueSaturationChanges()
|
|
396
398
|
} else {
|
|
397
|
-
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
399
|
+
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
398
400
|
}
|
|
399
401
|
} else {
|
|
400
|
-
await this.offlineOff()
|
|
401
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
402
|
+
await this.offlineOff()
|
|
403
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
402
404
|
}
|
|
403
405
|
// Refresh the status from the API
|
|
404
406
|
interval(15000)
|
|
405
407
|
.pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
|
|
406
408
|
.pipe(take(1))
|
|
407
409
|
.subscribe(async () => {
|
|
408
|
-
await this.refreshStatus()
|
|
409
|
-
})
|
|
410
|
+
await this.refreshStatus()
|
|
411
|
+
})
|
|
410
412
|
}
|
|
411
413
|
|
|
412
414
|
async BLEpushChanges(): Promise<void> {
|
|
413
|
-
await this.debugLog('BLEpushChanges')
|
|
415
|
+
await this.debugLog('BLEpushChanges')
|
|
414
416
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
415
|
-
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`)
|
|
416
|
-
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
417
|
-
await this.convertBLEAddress()
|
|
417
|
+
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`)
|
|
418
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
419
|
+
await this.convertBLEAddress()
|
|
418
420
|
if (switchbot !== false) {
|
|
419
421
|
switchbot
|
|
420
422
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
421
423
|
.then(async (device_list: any) => {
|
|
422
|
-
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
424
|
+
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
423
425
|
return await this.retryBLE({
|
|
424
426
|
max: await this.maxRetryBLE(),
|
|
425
427
|
fn: async () => {
|
|
426
428
|
if (this.LightBulb.On) {
|
|
427
|
-
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
429
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
428
430
|
} else {
|
|
429
|
-
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
431
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
430
432
|
}
|
|
431
433
|
},
|
|
432
|
-
})
|
|
434
|
+
})
|
|
433
435
|
})
|
|
434
436
|
.then(async () => {
|
|
435
|
-
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
436
|
-
this.LightBulb.On = false
|
|
437
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
438
|
+
this.LightBulb.On = false
|
|
437
439
|
})
|
|
438
440
|
.catch(async (e: any) => {
|
|
439
|
-
await this.apiError(e)
|
|
440
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
441
|
-
await this.BLEPushConnection()
|
|
442
|
-
})
|
|
441
|
+
await this.apiError(e)
|
|
442
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
443
|
+
await this.BLEPushConnection()
|
|
444
|
+
})
|
|
443
445
|
} else {
|
|
444
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
445
|
-
await this.BLEPushConnection()
|
|
446
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
447
|
+
await this.BLEPushConnection()
|
|
446
448
|
}
|
|
447
449
|
} else {
|
|
448
|
-
await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
450
|
+
await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
449
451
|
}
|
|
450
452
|
}
|
|
451
453
|
|
|
452
454
|
async openAPIpushChanges(): Promise<void> {
|
|
453
|
-
await this.debugLog('openAPIpushChanges')
|
|
455
|
+
await this.debugLog('openAPIpushChanges')
|
|
454
456
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
455
|
-
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
457
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
456
458
|
const bodyChange = JSON.stringify({
|
|
457
459
|
command: `${command}`,
|
|
458
460
|
parameter: 'default',
|
|
459
461
|
commandType: 'command',
|
|
460
|
-
})
|
|
461
|
-
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
462
|
+
})
|
|
463
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
462
464
|
try {
|
|
463
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
464
|
-
const deviceStatus: any = await body.json()
|
|
465
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
465
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
466
|
+
const deviceStatus: any = await body.json()
|
|
467
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
466
468
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
467
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
468
|
-
await this.updateHomeKitCharacteristics()
|
|
469
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
470
|
+
await this.updateHomeKitCharacteristics()
|
|
469
471
|
} else {
|
|
470
|
-
await this.statusCode(statusCode)
|
|
471
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
472
|
+
await this.statusCode(statusCode)
|
|
473
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
472
474
|
}
|
|
473
475
|
} catch (e: any) {
|
|
474
|
-
await this.apiError(e)
|
|
475
|
-
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
476
|
+
await this.apiError(e)
|
|
477
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
476
478
|
}
|
|
477
479
|
} else {
|
|
478
|
-
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
480
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
479
481
|
}
|
|
480
482
|
}
|
|
481
483
|
|
|
482
484
|
async pushHueSaturationChanges(): Promise<void> {
|
|
483
|
-
await this.debugLog('pushHueSaturationChanges')
|
|
485
|
+
await this.debugLog('pushHueSaturationChanges')
|
|
484
486
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
485
|
-
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`)
|
|
486
|
-
await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
487
|
-
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation))
|
|
488
|
-
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
487
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`)
|
|
488
|
+
await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
489
|
+
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation))
|
|
490
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
489
491
|
const bodyChange = JSON.stringify({
|
|
490
492
|
command: 'setColor',
|
|
491
493
|
parameter: `${red}:${green}:${blue}`,
|
|
492
494
|
commandType: 'command',
|
|
493
|
-
})
|
|
494
|
-
await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
495
|
+
})
|
|
496
|
+
await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
495
497
|
try {
|
|
496
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
497
|
-
const deviceStatus: any = await body.json()
|
|
498
|
-
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
498
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
499
|
+
const deviceStatus: any = await body.json()
|
|
500
|
+
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
499
501
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
500
|
-
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
501
|
-
await this.updateHomeKitCharacteristics()
|
|
502
|
+
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
503
|
+
await this.updateHomeKitCharacteristics()
|
|
502
504
|
} else {
|
|
503
|
-
await this.statusCode(statusCode)
|
|
504
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
505
|
+
await this.statusCode(statusCode)
|
|
506
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
505
507
|
}
|
|
506
508
|
} catch (e: any) {
|
|
507
|
-
await this.apiError(e)
|
|
508
|
-
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection
|
|
509
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
509
|
+
await this.apiError(e)
|
|
510
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
510
511
|
}
|
|
511
512
|
} else {
|
|
512
|
-
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}
|
|
513
|
-
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
513
|
+
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
|
|
517
517
|
async pushColorTemperatureChanges(): Promise<void> {
|
|
518
|
-
await this.debugLog('pushColorTemperatureChanges')
|
|
518
|
+
await this.debugLog('pushColorTemperatureChanges')
|
|
519
519
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
520
|
-
const kelvin = Math.round(1000000 * Number(this.LightBulb.ColorTemperature))
|
|
521
|
-
this.accessory.context.kelvin = kelvin
|
|
520
|
+
const kelvin = Math.round(1000000 * Number(this.LightBulb.ColorTemperature))
|
|
521
|
+
this.accessory.context.kelvin = kelvin
|
|
522
522
|
const bodyChange = JSON.stringify({
|
|
523
523
|
command: 'setColorTemperature',
|
|
524
524
|
parameter: `${kelvin}`,
|
|
525
525
|
commandType: 'command',
|
|
526
|
-
})
|
|
527
|
-
await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
526
|
+
})
|
|
527
|
+
await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
528
528
|
try {
|
|
529
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
530
|
-
const deviceStatus: any = await body.json()
|
|
531
|
-
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
529
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
530
|
+
const deviceStatus: any = await body.json()
|
|
531
|
+
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
532
532
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
533
|
-
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
534
|
-
await this.updateHomeKitCharacteristics()
|
|
533
|
+
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
534
|
+
await this.updateHomeKitCharacteristics()
|
|
535
535
|
} else {
|
|
536
|
-
await this.statusCode(statusCode)
|
|
537
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
536
|
+
await this.statusCode(statusCode)
|
|
537
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
538
538
|
}
|
|
539
539
|
} catch (e: any) {
|
|
540
|
-
await this.apiError(e)
|
|
541
|
-
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection
|
|
542
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
540
|
+
await this.apiError(e)
|
|
541
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
543
542
|
}
|
|
544
543
|
} else {
|
|
545
|
-
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}
|
|
546
|
-
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
544
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
|
|
547
545
|
}
|
|
548
546
|
}
|
|
549
547
|
|
|
550
548
|
async pushBrightnessChanges(): Promise<void> {
|
|
551
|
-
await this.debugLog('pushBrightnessChanges')
|
|
549
|
+
await this.debugLog('pushBrightnessChanges')
|
|
552
550
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
553
551
|
const bodyChange = JSON.stringify({
|
|
554
552
|
command: 'setBrightness',
|
|
555
553
|
parameter: `${this.LightBulb.Brightness}`,
|
|
556
554
|
commandType: 'command',
|
|
557
|
-
})
|
|
558
|
-
await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
555
|
+
})
|
|
556
|
+
await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
559
557
|
try {
|
|
560
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
561
|
-
const deviceStatus: any = await body.json()
|
|
562
|
-
await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
558
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
559
|
+
const deviceStatus: any = await body.json()
|
|
560
|
+
await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
563
561
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
564
|
-
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
565
|
-
await this.updateHomeKitCharacteristics()
|
|
562
|
+
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
563
|
+
await this.updateHomeKitCharacteristics()
|
|
566
564
|
} else {
|
|
567
|
-
await this.statusCode(statusCode)
|
|
568
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
565
|
+
await this.statusCode(statusCode)
|
|
566
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
569
567
|
}
|
|
570
568
|
} catch (e: any) {
|
|
571
|
-
await this.apiError(e)
|
|
572
|
-
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection
|
|
573
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
569
|
+
await this.apiError(e)
|
|
570
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
574
571
|
}
|
|
575
572
|
} else {
|
|
576
|
-
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}
|
|
577
|
-
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
573
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
578
574
|
}
|
|
579
575
|
}
|
|
580
576
|
|
|
@@ -583,13 +579,13 @@ export class CeilingLight extends deviceBase {
|
|
|
583
579
|
*/
|
|
584
580
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
585
581
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
586
|
-
await this.infoLog(`Set On: ${value}`)
|
|
582
|
+
await this.infoLog(`Set On: ${value}`)
|
|
587
583
|
} else {
|
|
588
|
-
await this.debugLog(`No Changes, Set On: ${value}`)
|
|
584
|
+
await this.debugLog(`No Changes, Set On: ${value}`)
|
|
589
585
|
}
|
|
590
586
|
|
|
591
|
-
this.LightBulb.On = value
|
|
592
|
-
this.doCeilingLightUpdate.next()
|
|
587
|
+
this.LightBulb.On = value
|
|
588
|
+
this.doCeilingLightUpdate.next()
|
|
593
589
|
}
|
|
594
590
|
|
|
595
591
|
/**
|
|
@@ -597,16 +593,16 @@ export class CeilingLight extends deviceBase {
|
|
|
597
593
|
*/
|
|
598
594
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
599
595
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
600
|
-
await this.infoLog(`Set Brightness: ${value}`)
|
|
596
|
+
await this.infoLog(`Set Brightness: ${value}`)
|
|
601
597
|
} else {
|
|
602
598
|
if (this.LightBulb.On) {
|
|
603
|
-
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
599
|
+
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
604
600
|
} else {
|
|
605
|
-
this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
601
|
+
this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`)
|
|
606
602
|
}
|
|
607
603
|
}
|
|
608
|
-
this.LightBulb.Brightness = value
|
|
609
|
-
this.doCeilingLightUpdate.next()
|
|
604
|
+
this.LightBulb.Brightness = value
|
|
605
|
+
this.doCeilingLightUpdate.next()
|
|
610
606
|
}
|
|
611
607
|
|
|
612
608
|
/**
|
|
@@ -614,34 +610,34 @@ export class CeilingLight extends deviceBase {
|
|
|
614
610
|
*/
|
|
615
611
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
616
612
|
if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
|
|
617
|
-
this.infoLog(`Set ColorTemperature: ${value}`)
|
|
613
|
+
this.infoLog(`Set ColorTemperature: ${value}`)
|
|
618
614
|
} else {
|
|
619
615
|
if (this.LightBulb.On) {
|
|
620
|
-
this.debugLog(`No Changes, ColorTemperature: ${value}`)
|
|
616
|
+
this.debugLog(`No Changes, ColorTemperature: ${value}`)
|
|
621
617
|
} else {
|
|
622
|
-
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`)
|
|
618
|
+
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`)
|
|
623
619
|
}
|
|
624
620
|
}
|
|
625
621
|
|
|
626
|
-
const minKelvin = 2000
|
|
627
|
-
const maxKelvin = 9000
|
|
622
|
+
const minKelvin = 2000
|
|
623
|
+
const maxKelvin = 9000
|
|
628
624
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
629
|
-
const kelvin = Math.round(1000000 / Number(value) / 100) * 100
|
|
625
|
+
const kelvin = Math.round(1000000 / Number(value) / 100) * 100
|
|
630
626
|
|
|
631
627
|
// Check and increase/decrease kelvin to range of device
|
|
632
|
-
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin)
|
|
628
|
+
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin)
|
|
633
629
|
|
|
634
630
|
if (!this.accessory.context.On || this.accessory.context.kelvin === k) {
|
|
635
|
-
return
|
|
631
|
+
return
|
|
636
632
|
}
|
|
637
633
|
|
|
638
634
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
639
|
-
const hs = m2hs(value)
|
|
640
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0])
|
|
641
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1])
|
|
635
|
+
const hs = m2hs(value)
|
|
636
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0])
|
|
637
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1])
|
|
642
638
|
|
|
643
|
-
this.LightBulb.ColorTemperature = value
|
|
644
|
-
this.doCeilingLightUpdate.next()
|
|
639
|
+
this.LightBulb.ColorTemperature = value
|
|
640
|
+
this.doCeilingLightUpdate.next()
|
|
645
641
|
}
|
|
646
642
|
|
|
647
643
|
/**
|
|
@@ -649,19 +645,19 @@ export class CeilingLight extends deviceBase {
|
|
|
649
645
|
*/
|
|
650
646
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
651
647
|
if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
|
|
652
|
-
this.infoLog(`Set Hue: ${value}`)
|
|
648
|
+
this.infoLog(`Set Hue: ${value}`)
|
|
653
649
|
} else {
|
|
654
650
|
if (this.LightBulb.On) {
|
|
655
|
-
this.debugLog(`No Changes, Hue: ${value}`)
|
|
651
|
+
this.debugLog(`No Changes, Hue: ${value}`)
|
|
656
652
|
} else {
|
|
657
|
-
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`)
|
|
653
|
+
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`)
|
|
658
654
|
}
|
|
659
655
|
}
|
|
660
656
|
|
|
661
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
657
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
662
658
|
|
|
663
|
-
this.LightBulb.Hue = value
|
|
664
|
-
this.doCeilingLightUpdate.next()
|
|
659
|
+
this.LightBulb.Hue = value
|
|
660
|
+
this.doCeilingLightUpdate.next()
|
|
665
661
|
}
|
|
666
662
|
|
|
667
663
|
/**
|
|
@@ -669,79 +665,74 @@ export class CeilingLight extends deviceBase {
|
|
|
669
665
|
*/
|
|
670
666
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
671
667
|
if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
672
|
-
this.infoLog(`Set Saturation: ${value}`)
|
|
668
|
+
this.infoLog(`Set Saturation: ${value}`)
|
|
673
669
|
} else {
|
|
674
670
|
if (this.LightBulb.On) {
|
|
675
|
-
this.debugLog(`No Changes, Saturation: ${value}`)
|
|
671
|
+
this.debugLog(`No Changes, Saturation: ${value}`)
|
|
676
672
|
} else {
|
|
677
|
-
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`)
|
|
673
|
+
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`)
|
|
678
674
|
}
|
|
679
675
|
}
|
|
680
676
|
|
|
681
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
677
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140)
|
|
682
678
|
|
|
683
|
-
this.LightBulb.Saturation = value
|
|
684
|
-
this.doCeilingLightUpdate.next()
|
|
679
|
+
this.LightBulb.Saturation = value
|
|
680
|
+
this.doCeilingLightUpdate.next()
|
|
685
681
|
}
|
|
686
682
|
|
|
687
683
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
688
684
|
// On
|
|
689
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
690
|
-
this.LightBulb.On, 'On');
|
|
685
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
|
|
691
686
|
// Brightness
|
|
692
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
|
|
693
|
-
this.LightBulb.Brightness, 'Brightness');
|
|
687
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness')
|
|
694
688
|
// ColorTemperature
|
|
695
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
|
|
696
|
-
this.LightBulb.ColorTemperature, 'ColorTemperature');
|
|
689
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature, 'ColorTemperature')
|
|
697
690
|
// Hue
|
|
698
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
|
|
699
|
-
this.LightBulb.Hue, 'Hue');
|
|
691
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue, this.LightBulb.Hue, 'Hue')
|
|
700
692
|
// Saturation
|
|
701
|
-
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
|
|
702
|
-
this.LightBulb.Saturation, 'Saturation');
|
|
693
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation, this.LightBulb.Saturation, 'Saturation')
|
|
703
694
|
}
|
|
704
695
|
|
|
705
696
|
async getAdaptiveLightingSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
706
697
|
// Adaptive Lighting
|
|
707
|
-
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
|
|
708
|
-
await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
698
|
+
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
|
|
699
|
+
await this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
709
700
|
// Adaptive Lighting Shift
|
|
710
701
|
if (device.ceilinglight?.adaptiveLightingShift) {
|
|
711
|
-
this.adaptiveLightingShift = device.ceilinglight.adaptiveLightingShift
|
|
712
|
-
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
702
|
+
this.adaptiveLightingShift = device.ceilinglight.adaptiveLightingShift
|
|
703
|
+
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
713
704
|
} else {
|
|
714
|
-
this.adaptiveLightingShift = 0
|
|
715
|
-
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
705
|
+
this.adaptiveLightingShift = 0
|
|
706
|
+
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
716
707
|
}
|
|
717
708
|
}
|
|
718
709
|
|
|
719
710
|
async BLEPushConnection() {
|
|
720
711
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
721
|
-
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
722
|
-
await this.openAPIpushChanges()
|
|
712
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
713
|
+
await this.openAPIpushChanges()
|
|
723
714
|
}
|
|
724
715
|
}
|
|
725
716
|
|
|
726
717
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
727
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
718
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
728
719
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
729
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
730
|
-
await this.openAPIRefreshStatus()
|
|
720
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
721
|
+
await this.openAPIRefreshStatus()
|
|
731
722
|
}
|
|
732
723
|
}
|
|
733
724
|
|
|
734
725
|
async offlineOff(): Promise<void> {
|
|
735
726
|
if (this.device.offline) {
|
|
736
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
727
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false)
|
|
737
728
|
}
|
|
738
729
|
}
|
|
739
730
|
|
|
740
731
|
async apiError(e: any): Promise<void> {
|
|
741
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
742
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e)
|
|
743
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e)
|
|
744
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e)
|
|
745
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e)
|
|
732
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
733
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e)
|
|
734
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e)
|
|
735
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e)
|
|
736
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e)
|
|
746
737
|
}
|
|
747
738
|
}
|