@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.0

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