@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4

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