@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.11

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 (197) hide show
  1. package/README.md +16 -0
  2. package/dist/device/blindtilt.d.ts +15 -6
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +203 -255
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +9 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +196 -218
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +9 -4
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +203 -249
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +10 -5
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +329 -378
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +9 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +99 -142
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +19 -7
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +203 -264
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +28 -32
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +186 -225
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +9 -4
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +198 -227
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +9 -5
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +106 -231
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +12 -4
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +192 -232
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +9 -4
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +91 -157
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +10 -5
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +287 -367
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +10 -5
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +171 -216
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +9 -4
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +93 -158
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +9 -4
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +94 -155
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +9 -4
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +84 -142
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +9 -4
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +99 -124
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +170 -253
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +12 -4
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +105 -129
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +2 -1
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +45 -51
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +2 -1
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +17 -17
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +2 -1
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +9 -9
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +2 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +19 -19
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +24 -11
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +90 -68
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts +2 -1
  99. package/dist/irdevice/light.d.ts.map +1 -1
  100. package/dist/irdevice/light.js +15 -17
  101. package/dist/irdevice/light.js.map +1 -1
  102. package/dist/irdevice/other.d.ts +2 -1
  103. package/dist/irdevice/other.d.ts.map +1 -1
  104. package/dist/irdevice/other.js +76 -76
  105. package/dist/irdevice/other.js.map +1 -1
  106. package/dist/irdevice/tv.d.ts +2 -1
  107. package/dist/irdevice/tv.d.ts.map +1 -1
  108. package/dist/irdevice/tv.js +35 -35
  109. package/dist/irdevice/tv.js.map +1 -1
  110. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  111. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.js +9 -9
  113. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  114. package/dist/irdevice/waterheater.d.ts +2 -1
  115. package/dist/irdevice/waterheater.d.ts.map +1 -1
  116. package/dist/irdevice/waterheater.js +9 -9
  117. package/dist/irdevice/waterheater.js.map +1 -1
  118. package/dist/platform.d.ts +15 -15
  119. package/dist/platform.d.ts.map +1 -1
  120. package/dist/platform.js +288 -271
  121. package/dist/platform.js.map +1 -1
  122. package/dist/settings.d.ts +49 -191
  123. package/dist/settings.d.ts.map +1 -1
  124. package/dist/settings.js +19 -0
  125. package/dist/settings.js.map +1 -1
  126. package/dist/types/bledevicestatus.d.ts +279 -0
  127. package/dist/types/bledevicestatus.d.ts.map +1 -0
  128. package/dist/types/bledevicestatus.js +2 -0
  129. package/dist/types/bledevicestatus.js.map +1 -0
  130. package/dist/types/devicelist.d.ts +89 -0
  131. package/dist/types/devicelist.d.ts.map +1 -0
  132. package/dist/types/devicelist.js +6 -0
  133. package/dist/types/devicelist.js.map +1 -0
  134. package/dist/types/deviceresponse.d.ts +13 -0
  135. package/dist/types/deviceresponse.d.ts.map +1 -0
  136. package/dist/types/deviceresponse.js +2 -0
  137. package/dist/types/deviceresponse.js.map +1 -0
  138. package/dist/types/devicestatus.d.ts +149 -0
  139. package/dist/types/devicestatus.d.ts.map +1 -0
  140. package/dist/types/devicestatus.js +3 -0
  141. package/dist/types/devicestatus.js.map +1 -0
  142. package/dist/types/devicewebhookstatus.d.ts +156 -0
  143. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  144. package/dist/types/devicewebhookstatus.js +2 -0
  145. package/dist/types/devicewebhookstatus.js.map +1 -0
  146. package/dist/types/irdevicelist.d.ts +10 -0
  147. package/dist/types/irdevicelist.d.ts.map +1 -0
  148. package/dist/types/irdevicelist.js +2 -0
  149. package/dist/types/irdevicelist.js.map +1 -0
  150. package/dist/types/pushbody.d.ts +6 -0
  151. package/dist/types/pushbody.d.ts.map +1 -0
  152. package/dist/types/pushbody.js +2 -0
  153. package/dist/types/pushbody.js.map +1 -0
  154. package/dist/utils.d.ts +25 -0
  155. package/dist/utils.d.ts.map +1 -1
  156. package/dist/utils.js +28 -0
  157. package/dist/utils.js.map +1 -1
  158. package/package.json +10 -10
  159. package/src/device/blindtilt.ts +224 -264
  160. package/src/device/bot.ts +208 -221
  161. package/src/device/ceilinglight.ts +211 -261
  162. package/src/device/colorbulb.ts +334 -397
  163. package/src/device/contact.ts +111 -146
  164. package/src/device/curtain.ts +220 -283
  165. package/src/device/device.ts +194 -245
  166. package/src/device/fan.ts +214 -230
  167. package/src/device/hub.ts +126 -246
  168. package/src/device/humidifier.ts +216 -243
  169. package/src/device/iosensor.ts +114 -166
  170. package/src/device/lightstrip.ts +302 -377
  171. package/src/device/lock.ts +187 -221
  172. package/src/device/meter.ts +116 -177
  173. package/src/device/meterplus.ts +117 -174
  174. package/src/device/motion.ts +99 -144
  175. package/src/device/plug.ts +110 -128
  176. package/src/device/robotvacuumcleaner.ts +189 -252
  177. package/src/device/waterdetector.ts +123 -139
  178. package/src/irdevice/airconditioner.ts +47 -52
  179. package/src/irdevice/airpurifier.ts +19 -18
  180. package/src/irdevice/camera.ts +11 -10
  181. package/src/irdevice/fan.ts +21 -20
  182. package/src/irdevice/irdevice.ts +95 -70
  183. package/src/irdevice/light.ts +17 -18
  184. package/src/irdevice/other.ts +78 -77
  185. package/src/irdevice/tv.ts +37 -36
  186. package/src/irdevice/vacuumcleaner.ts +11 -10
  187. package/src/irdevice/waterheater.ts +11 -10
  188. package/src/platform.ts +290 -272
  189. package/src/settings.ts +30 -239
  190. package/src/types/bledevicestatus.ts +305 -0
  191. package/src/types/devicelist.ts +124 -0
  192. package/src/types/deviceresponse.ts +15 -0
  193. package/src/types/devicestatus.ts +178 -0
  194. package/src/types/devicewebhookstatus.ts +196 -0
  195. package/src/types/irdevicelist.ts +15 -0
  196. package/src/types/pushbody.ts +9 -0
  197. package/src/utils.ts +33 -0
@@ -3,9 +3,9 @@
3
3
  * ceilinglight.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
- import { interval, Subject } from 'rxjs';
7
- import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
8
- import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
+ import { hs2rgb, m2hs } from '../utils.js';
7
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
8
+ import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
9
9
  /**
10
10
  * Platform Accessory
11
11
  * An instance of this class is created for each accessory your platform registers
@@ -32,7 +32,7 @@ export class CeilingLight extends deviceBase {
32
32
  // Initialize LightBulb Service
33
33
  accessory.context.LightBulb = accessory.context.LightBulb ?? {};
34
34
  this.LightBulb = {
35
- Name: accessory.context.LightBul.bName ?? accessory.displayName,
35
+ Name: accessory.context.LightBulb.Name ?? accessory.displayName,
36
36
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb),
37
37
  On: accessory.context.On ?? false,
38
38
  Hue: accessory.context.Hue ?? 0,
@@ -46,7 +46,7 @@ export class CeilingLight extends deviceBase {
46
46
  accessory.removeService(this.LightBulb.Service);
47
47
  this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
48
48
  accessory.context.adaptiveLighting = false;
49
- this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
49
+ this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`);
50
50
  }
51
51
  if (this.adaptiveLightingShift !== -1) {
52
52
  this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
@@ -54,10 +54,10 @@ export class CeilingLight extends deviceBase {
54
54
  });
55
55
  this.accessory.configureController(this.AdaptiveLightingController);
56
56
  this.accessory.context.adaptiveLighting = true;
57
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
57
+ this.debugLog(`adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
58
58
  + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
59
59
  }
60
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
60
+ this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
61
61
  // Initialize LightBulb Characteristics
62
62
  this.LightBulb.Service
63
63
  .setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
@@ -119,14 +119,14 @@ export class CeilingLight extends deviceBase {
119
119
  this.refreshStatus();
120
120
  // Update Homekit
121
121
  this.updateHomeKitCharacteristics();
122
+ //regisiter webhook event handler
123
+ this.registerWebhook();
122
124
  // Start an update interval
123
125
  interval(this.deviceRefreshRate * 1000)
124
126
  .pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
125
127
  .subscribe(async () => {
126
128
  await this.refreshStatus();
127
129
  });
128
- //regisiter webhook event handler
129
- this.registerWebhook(accessory, device);
130
130
  // Watch for Bulb change events
131
131
  // We put in a debounce of 100ms so we don't make duplicate calls
132
132
  this.doCeilingLightUpdate
@@ -138,9 +138,8 @@ export class CeilingLight extends deviceBase {
138
138
  await this.pushChanges();
139
139
  }
140
140
  catch (e) {
141
- this.apiError(e);
142
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
143
- + ` Error Message: ${JSON.stringify(e.message)}`);
141
+ await this.apiError(e);
142
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
144
143
  }
145
144
  this.ceilingLightUpdateInProgress = false;
146
145
  });
@@ -149,63 +148,34 @@ export class CeilingLight extends deviceBase {
149
148
  * Parse the device status from the SwitchBotBLE API
150
149
  */
151
150
  async BLEparseStatus(serviceData) {
152
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
153
- // State
154
- switch (serviceData.state) {
155
- case 'on':
156
- this.LightBulb.On = true;
157
- break;
158
- default:
159
- this.LightBulb.On = false;
160
- }
161
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
151
+ await this.debugLog('BLEparseStatus');
152
+ // On
153
+ this.LightBulb.On = serviceData.state;
154
+ await this.debugLog(`On: ${this.LightBulb.On}`);
162
155
  }
163
156
  /**
164
157
  * Parse the device status from the SwitchBot OpenAPI
165
158
  */
166
159
  async openAPIparseStatus(deviceStatus) {
167
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
168
- switch (deviceStatus.body.power) {
169
- case 'on':
170
- this.LightBulb.On = true;
171
- break;
172
- default:
173
- this.LightBulb.On = false;
174
- }
175
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
160
+ await this.debugLog('openAPIparseStatus');
161
+ // On
162
+ this.LightBulb.On = deviceStatus.power;
163
+ await this.debugLog(`On: ${this.LightBulb.On}`);
176
164
  // Brightness
177
- this.LightBulb.Brightness = Number(deviceStatus.body.brightness);
178
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
179
- // Color, Hue & Brightness
180
- if (deviceStatus.body.color) {
181
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(deviceStatus.body.color)}`);
182
- const [red, green, blue] = deviceStatus.body.color.split(':');
183
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
184
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
185
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
186
- const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
187
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
188
- + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
189
- // Hue
190
- this.LightBulb.Hue = hue;
191
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
192
- // Saturation
193
- this.LightBulb.Saturation = saturation;
194
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
195
- }
165
+ this.LightBulb.Brightness = deviceStatus.brightness;
166
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
196
167
  // ColorTemperature
197
- if (!Number.isNaN(deviceStatus.body.colorTemperature)) {
198
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${deviceStatus.body.colorTemperature}`);
199
- const mired = Math.round(1000000 / deviceStatus.body.colorTemperature);
200
- this.LightBulb.ColorTemperature = Number(mired);
201
- this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
202
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
168
+ if (!Number.isNaN(deviceStatus.colorTemperature)) {
169
+ await this.debugLog(`OpenAPI ColorTemperature: ${deviceStatus.colorTemperature}`);
170
+ const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
171
+ this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
172
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
203
173
  }
204
174
  // Firmware Version
205
- const version = deviceStatus.body.version?.toString();
206
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
207
- if (deviceStatus.body.version) {
208
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
175
+ const version = deviceStatus.version.toString();
176
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
177
+ if (deviceStatus.version) {
178
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
209
179
  this.accessory
210
180
  .getService(this.hap.Service.AccessoryInformation)
211
181
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -213,29 +183,43 @@ export class CeilingLight extends deviceBase {
213
183
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
214
184
  .updateValue(deviceVersion);
215
185
  this.accessory.context.deviceVersion = deviceVersion;
216
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
186
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
217
187
  }
218
188
  }
189
+ async parseStatusWebhook(context) {
190
+ await this.debugLog('parseStatusWebhook');
191
+ await this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${context.powerState}, ${context.brightness},`
192
+ + ` ${context.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
193
+ // On
194
+ this.LightBulb.On = context.powerState === 'ON' ? true : false;
195
+ await this.debugLog(`On: ${this.LightBulb.On}`);
196
+ // Brightness
197
+ this.LightBulb.Brightness = context.brightness;
198
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
199
+ // ColorTemperature
200
+ this.LightBulb.ColorTemperature = Math.max(Math.min(context.colorTemperature, 500), 140);
201
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
202
+ }
219
203
  /**
220
204
  * Asks the SwitchBot API for the latest device information
221
205
  */
222
206
  async refreshStatus() {
223
207
  if (!this.device.enableCloudService && this.OpenAPI) {
224
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
225
- /*} else if (this.BLE) {
226
- await this.BLERefreshStatus();*/
208
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
209
+ }
210
+ else if (this.BLE) {
211
+ await this.BLERefreshStatus();
227
212
  }
228
213
  else if (this.OpenAPI && this.platform.config.credentials?.token) {
229
214
  await this.openAPIRefreshStatus();
230
215
  }
231
216
  else {
232
217
  await this.offlineOff();
233
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
234
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
218
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
235
219
  }
236
220
  }
237
221
  async BLERefreshStatus() {
238
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
222
+ await this.debugLog('BLERefreshStatus');
239
223
  const switchbot = await this.switchbotBLE();
240
224
  if (switchbot === undefined) {
241
225
  await this.BLERefreshConnection(switchbot);
@@ -245,84 +229,56 @@ export class CeilingLight extends deviceBase {
245
229
  // Start to monitor advertisement packets
246
230
  const serviceData = await this.monitorAdvertisementPackets(switchbot);
247
231
  // Update HomeKit
248
- if (serviceData.model !== '' && serviceData.modelName !== '') {
232
+ if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
233
+ && serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
249
234
  await this.BLEparseStatus(serviceData);
250
235
  await this.updateHomeKitCharacteristics();
251
236
  }
252
237
  else {
253
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
238
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
254
239
  await this.BLERefreshConnection(switchbot);
255
240
  }
256
241
  })();
257
242
  }
258
243
  }
259
244
  async openAPIRefreshStatus() {
260
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
245
+ await this.debugLog('openAPIRefreshStatus');
261
246
  try {
262
247
  const { body, statusCode } = await this.deviceRefreshStatus();
263
248
  const deviceStatus = await body.json();
264
- await this.refreshStatusCodes(statusCode, deviceStatus);
249
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
265
250
  ;
266
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
267
- await this.successfulRefreshStatus(statusCode, deviceStatus);
268
- await this.openAPIparseStatus(deviceStatus);
251
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
252
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
253
+ await this.openAPIparseStatus(deviceStatus.body);
269
254
  await this.updateHomeKitCharacteristics();
270
255
  }
271
256
  else {
272
- await this.statusCodes(statusCode, deviceStatus);
257
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
258
+ await this.debugWarnLog(statusCode, deviceStatus);
273
259
  }
274
260
  }
275
261
  catch (e) {
276
262
  await this.apiError(e);
277
- await this.openAPIRefreshError(e);
263
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
278
264
  }
279
265
  }
280
- async registerWebhook(accessory, device) {
281
- if (device.webhook) {
282
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
283
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
266
+ async registerWebhook() {
267
+ if (this.device.webhook) {
268
+ await this.debugLog('is listening webhook.');
269
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
284
270
  try {
285
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
286
- const { powerState, brightness, colorTemperature } = context;
287
- const { On, Brightness, ColorTemperature } = this.LightBulb;
288
- this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
289
- '(powerState, brightness, colorTemperature) = ' +
290
- `Webhook:(${powerState}, ${brightness}, ${colorTemperature}), `
291
- + `current:(${On}, ${Brightness}, ${ColorTemperature})`);
292
- // On
293
- this.LightBulb.On = powerState === 'ON' ? true : false;
294
- if (accessory.context.Brightness !== this.LightBulb.On) {
295
- this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
296
- }
297
- else {
298
- this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
299
- }
300
- // Brightness
301
- this.LightBulb.Brightness = brightness;
302
- if (accessory.context.Brightness !== this.LightBulb.Brightness) {
303
- this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
304
- }
305
- else {
306
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
307
- }
308
- // ColorTemperature
309
- this.LightBulb.ColorTemperature = colorTemperature;
310
- if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
311
- this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
312
- }
313
- else {
314
- this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
315
- }
316
- this.updateHomeKitCharacteristics();
271
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
272
+ await this.parseStatusWebhook(context);
273
+ await this.updateHomeKitCharacteristics();
317
274
  }
318
275
  catch (e) {
319
- this.errorLog(`${device.deviceType}: ${accessory.displayName} `
320
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
276
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
321
277
  }
322
278
  };
323
279
  }
324
280
  else {
325
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
281
+ await this.debugLog('is not listening webhook.');
326
282
  }
327
283
  }
328
284
  /**
@@ -338,17 +294,32 @@ export class CeilingLight extends deviceBase {
338
294
  */
339
295
  async pushChanges() {
340
296
  if (!this.device.enableCloudService && this.OpenAPI) {
341
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
297
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
342
298
  }
343
299
  else if (this.BLE) {
344
300
  await this.BLEpushChanges();
345
301
  }
346
302
  else if (this.OpenAPI && this.platform.config.credentials?.token) {
347
303
  await this.openAPIpushChanges();
304
+ if (this.LightBulb.On) {
305
+ await this.debugLog(`On: ${this.LightBulb.On}`);
306
+ // Push Brightness Update
307
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
308
+ await this.pushBrightnessChanges();
309
+ // Push ColorTemperature Update
310
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
311
+ await this.pushColorTemperatureChanges();
312
+ // Push Hue & Saturation Update
313
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
314
+ await this.pushHueSaturationChanges();
315
+ }
316
+ else {
317
+ await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
318
+ }
348
319
  }
349
320
  else {
350
321
  await this.offlineOff();
351
- await this.pushChangeDisabled();
322
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
352
323
  }
353
324
  // Refresh the status from the API
354
325
  interval(15000)
@@ -359,70 +330,63 @@ export class CeilingLight extends deviceBase {
359
330
  });
360
331
  }
361
332
  async BLEpushChanges() {
362
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
333
+ await this.debugLog('BLEpushChanges');
363
334
  if (this.LightBulb.On !== this.accessory.context.On) {
364
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
365
- + ` BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
366
- const switchbot = await this.platform.connectBLE();
367
- // Convert to BLE Address
335
+ await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
336
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
368
337
  await this.convertBLEAddress();
369
- switchbot
370
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
371
- .then(async (device_list) => {
372
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
373
- return await this.retryBLE({
374
- max: await this.maxRetryBLE(),
375
- fn: async () => {
376
- if (this.LightBulb.On) {
377
- return await device_list[0].turnOn({ id: this.device.bleMac });
378
- }
379
- else {
380
- return await device_list[0].turnOff({ id: this.device.bleMac });
381
- }
382
- },
338
+ if (switchbot !== false) {
339
+ switchbot
340
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
341
+ .then(async (device_list) => {
342
+ this.infoLog(`On: ${this.LightBulb.On}`);
343
+ return await this.retryBLE({
344
+ max: await this.maxRetryBLE(),
345
+ fn: async () => {
346
+ if (this.LightBulb.On) {
347
+ return await device_list[0].turnOn({ id: this.device.bleMac });
348
+ }
349
+ else {
350
+ return await device_list[0].turnOff({ id: this.device.bleMac });
351
+ }
352
+ },
353
+ });
354
+ })
355
+ .then(async () => {
356
+ await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
357
+ this.LightBulb.On = false;
358
+ })
359
+ .catch(async (e) => {
360
+ await this.apiError(e);
361
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
362
+ await this.BLEPushConnection();
383
363
  });
384
- })
385
- .then(() => {
386
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
387
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
388
- + `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
389
- this.LightBulb.On = false;
390
- })
391
- .catch(async (e) => {
392
- this.apiError(e);
393
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
394
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
364
+ }
365
+ else {
366
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
395
367
  await this.BLEPushConnection();
396
- });
368
+ }
397
369
  }
398
370
  else {
399
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
400
- + ` No BLEpushChanges: On: ${this.LightBulb.On}, `
401
- + `OnCached: ${this.accessory.context.On}`);
371
+ await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
402
372
  }
403
373
  }
404
374
  async openAPIpushChanges() {
405
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
375
+ await this.debugLog('openAPIpushChanges');
406
376
  if (this.LightBulb.On !== this.accessory.context.On) {
407
- let command = '';
408
- if (this.LightBulb.On) {
409
- command = 'turnOn';
410
- }
411
- else {
412
- command = 'turnOff';
413
- }
377
+ const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
414
378
  const bodyChange = JSON.stringify({
415
379
  command: `${command}`,
416
380
  parameter: 'default',
417
381
  commandType: 'command',
418
382
  });
419
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
383
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
420
384
  try {
421
385
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
422
386
  const deviceStatus = await body.json();
423
- await this.pushStatusCodes(statusCode, deviceStatus);
424
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
425
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
387
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
388
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
389
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
426
390
  await this.updateHomeKitCharacteristics();
427
391
  }
428
392
  else {
@@ -431,48 +395,33 @@ export class CeilingLight extends deviceBase {
431
395
  }
432
396
  }
433
397
  catch (e) {
434
- this.apiError(e);
435
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
436
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
398
+ await this.apiError(e);
399
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
437
400
  }
438
401
  }
439
402
  else {
440
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.`
441
- + `On: ${this.LightBulb.On}, `
442
- + `OnCached: ${this.accessory.context.On}`);
443
- }
444
- // Push Hue & Saturation Update
445
- if (this.LightBulb.On) {
446
- await this.pushHueSaturationChanges();
447
- }
448
- // Push ColorTemperature Update
449
- if (this.LightBulb.On) {
450
- await this.pushColorTemperatureChanges();
451
- }
452
- // Push Brightness Update
453
- if (this.LightBulb.On) {
454
- await this.pushBrightnessChanges();
403
+ await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
455
404
  }
456
405
  }
457
406
  async pushHueSaturationChanges() {
458
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
459
- if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
460
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
461
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
407
+ await this.debugLog('pushHueSaturationChanges');
408
+ if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
409
+ await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
410
+ await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
462
411
  const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
463
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
412
+ await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
464
413
  const bodyChange = JSON.stringify({
465
414
  command: 'setColor',
466
415
  parameter: `${red}:${green}:${blue}`,
467
416
  commandType: 'command',
468
417
  });
469
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
418
+ await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
470
419
  try {
471
420
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
472
421
  const deviceStatus = await body.json();
473
- await this.pushStatusCodes(statusCode, deviceStatus);
474
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
475
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
422
+ await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
423
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
424
+ await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
476
425
  await this.updateHomeKitCharacteristics();
477
426
  }
478
427
  else {
@@ -481,18 +430,18 @@ export class CeilingLight extends deviceBase {
481
430
  }
482
431
  }
483
432
  catch (e) {
484
- this.apiError(e);
485
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
486
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
433
+ await this.apiError(e);
434
+ await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
435
+ + ` Error Message: ${JSON.stringify(e.message)}`);
487
436
  }
488
437
  }
489
438
  else {
490
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.LightBulb.Hue}, HueCached: `
491
- + `${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
439
+ await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
440
+ + ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
492
441
  }
493
442
  }
494
443
  async pushColorTemperatureChanges() {
495
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
444
+ await this.debugLog('pushColorTemperatureChanges');
496
445
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
497
446
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
498
447
  this.accessory.context.kelvin = kelvin;
@@ -501,13 +450,13 @@ export class CeilingLight extends deviceBase {
501
450
  parameter: `${kelvin}`,
502
451
  commandType: 'command',
503
452
  });
504
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
453
+ await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
505
454
  try {
506
455
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
507
456
  const deviceStatus = await body.json();
508
- await this.pushStatusCodes(statusCode, deviceStatus);
509
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
510
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
457
+ await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
458
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
459
+ await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
511
460
  await this.updateHomeKitCharacteristics();
512
461
  }
513
462
  else {
@@ -516,31 +465,31 @@ export class CeilingLight extends deviceBase {
516
465
  }
517
466
  }
518
467
  catch (e) {
519
- this.apiError(e);
520
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with`
521
- + ` ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
468
+ await this.apiError(e);
469
+ await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
470
+ + ` Error Message: ${JSON.stringify(e.message)}`);
522
471
  }
523
472
  }
524
473
  else {
525
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.`
526
- + `ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
474
+ await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
475
+ + ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
527
476
  }
528
477
  }
529
478
  async pushBrightnessChanges() {
530
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
479
+ await this.debugLog('pushBrightnessChanges');
531
480
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
532
481
  const bodyChange = JSON.stringify({
533
482
  command: 'setBrightness',
534
483
  parameter: `${this.LightBulb.Brightness}`,
535
484
  commandType: 'command',
536
485
  });
537
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
486
+ await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
538
487
  try {
539
488
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
540
489
  const deviceStatus = await body.json();
541
- await this.pushStatusCodes(statusCode, deviceStatus);
542
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
543
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
490
+ await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
491
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
492
+ await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
544
493
  await this.updateHomeKitCharacteristics();
545
494
  }
546
495
  else {
@@ -549,26 +498,25 @@ export class CeilingLight extends deviceBase {
549
498
  }
550
499
  }
551
500
  catch (e) {
552
- this.apiError(e);
553
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
554
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
501
+ await this.apiError(e);
502
+ await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
503
+ + ` Error Message: ${JSON.stringify(e.message)}`);
555
504
  }
556
505
  }
557
506
  else {
558
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.`
559
- + `Brightness: ${this.LightBulb.Brightness}, `
560
- + `BrightnessCached: ${this.accessory.context.Brightness}`);
507
+ await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
508
+ + ` BrightnessCached: ${this.accessory.context.Brightness}`);
561
509
  }
562
510
  }
563
511
  /**
564
512
  * Handle requests to set the value of the "On" characteristic
565
513
  */
566
514
  async OnSet(value) {
567
- if (this.LightBulb.On === this.accessory.context.On) {
568
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
515
+ if (this.LightBulb.On !== this.accessory.context.On) {
516
+ await this.infoLog(`Set On: ${value}`);
569
517
  }
570
518
  else {
571
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
519
+ await this.debugLog(`No Changes, Set On: ${value}`);
572
520
  }
573
521
  this.LightBulb.On = value;
574
522
  this.doCeilingLightUpdate.next();
@@ -577,14 +525,16 @@ export class CeilingLight extends deviceBase {
577
525
  * Handle requests to set the value of the "Brightness" characteristic
578
526
  */
579
527
  async BrightnessSet(value) {
580
- if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
581
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
582
- }
583
- else if (this.LightBulb.On) {
584
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
528
+ if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
529
+ await this.infoLog(`Set Brightness: ${value}`);
585
530
  }
586
531
  else {
587
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
532
+ if (this.LightBulb.On) {
533
+ this.debugLog(`No Changes, Brightness: ${value}`);
534
+ }
535
+ else {
536
+ this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
537
+ }
588
538
  }
589
539
  this.LightBulb.Brightness = value;
590
540
  this.doCeilingLightUpdate.next();
@@ -593,14 +543,16 @@ export class CeilingLight extends deviceBase {
593
543
  * Handle requests to set the value of the "ColorTemperature" characteristic
594
544
  */
595
545
  async ColorTemperatureSet(value) {
596
- if (this.LightBulb.ColorTemperature === this.accessory.context.ColorTemperature) {
597
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
598
- }
599
- else if (this.LightBulb.On) {
600
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
546
+ if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
547
+ this.infoLog(`Set ColorTemperature: ${value}`);
601
548
  }
602
549
  else {
603
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
550
+ if (this.LightBulb.On) {
551
+ this.debugLog(`No Changes, ColorTemperature: ${value}`);
552
+ }
553
+ else {
554
+ this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
555
+ }
604
556
  }
605
557
  const minKelvin = 2000;
606
558
  const maxKelvin = 9000;
@@ -622,14 +574,16 @@ export class CeilingLight extends deviceBase {
622
574
  * Handle requests to set the value of the "Hue" characteristic
623
575
  */
624
576
  async HueSet(value) {
625
- if (this.LightBulb.Hue === this.accessory.context.Hue) {
626
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
627
- }
628
- else if (this.LightBulb.On) {
629
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
577
+ if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
578
+ this.infoLog(`Set Hue: ${value}`);
630
579
  }
631
580
  else {
632
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
581
+ if (this.LightBulb.On) {
582
+ this.debugLog(`No Changes, Hue: ${value}`);
583
+ }
584
+ else {
585
+ this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
586
+ }
633
587
  }
634
588
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
635
589
  this.LightBulb.Hue = value;
@@ -639,14 +593,16 @@ export class CeilingLight extends deviceBase {
639
593
  * Handle requests to set the value of the "Saturation" characteristic
640
594
  */
641
595
  async SaturationSet(value) {
642
- if (this.LightBulb.Saturation === this.accessory.context.Saturation) {
643
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
644
- }
645
- else if (this.LightBulb.On) {
646
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
596
+ if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
597
+ this.infoLog(`Set Saturation: ${value}`);
647
598
  }
648
599
  else {
649
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
600
+ if (this.LightBulb.On) {
601
+ this.debugLog(`No Changes, Saturation: ${value}`);
602
+ }
603
+ else {
604
+ this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
605
+ }
650
606
  }
651
607
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
652
608
  this.LightBulb.Saturation = value;
@@ -667,24 +623,22 @@ export class CeilingLight extends deviceBase {
667
623
  async adaptiveLighting(device) {
668
624
  if (device.ceilinglight?.adaptiveLightingShift) {
669
625
  this.adaptiveLightingShift = device.ceilinglight.adaptiveLightingShift;
670
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
671
626
  }
672
627
  else {
673
628
  this.adaptiveLightingShift = 0;
674
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
675
629
  }
630
+ await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
676
631
  }
677
632
  async BLEPushConnection() {
678
633
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
679
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
634
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
680
635
  await this.openAPIpushChanges();
681
636
  }
682
637
  }
683
638
  async BLERefreshConnection(switchbot) {
684
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
685
- + ` ${JSON.stringify(switchbot)}`);
639
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
686
640
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
687
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
641
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
688
642
  await this.openAPIRefreshStatus();
689
643
  }
690
644
  }