@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/config.schema.json +9 -0
  5. package/dist/devices/bots.d.ts +37 -34
  6. package/dist/devices/bots.d.ts.map +1 -1
  7. package/dist/devices/bots.js +196 -243
  8. package/dist/devices/bots.js.map +1 -1
  9. package/dist/devices/colorbulb.d.ts +50 -50
  10. package/dist/devices/colorbulb.d.ts.map +1 -1
  11. package/dist/devices/colorbulb.js +131 -145
  12. package/dist/devices/colorbulb.js.map +1 -1
  13. package/dist/devices/contact.d.ts +29 -27
  14. package/dist/devices/contact.d.ts.map +1 -1
  15. package/dist/devices/contact.js +115 -138
  16. package/dist/devices/contact.js.map +1 -1
  17. package/dist/devices/curtains.d.ts +31 -29
  18. package/dist/devices/curtains.d.ts.map +1 -1
  19. package/dist/devices/curtains.js +176 -211
  20. package/dist/devices/curtains.js.map +1 -1
  21. package/dist/devices/humidifiers.d.ts +33 -33
  22. package/dist/devices/humidifiers.d.ts.map +1 -1
  23. package/dist/devices/humidifiers.js +189 -214
  24. package/dist/devices/humidifiers.js.map +1 -1
  25. package/dist/devices/meters.d.ts +31 -30
  26. package/dist/devices/meters.d.ts.map +1 -1
  27. package/dist/devices/meters.js +100 -124
  28. package/dist/devices/meters.js.map +1 -1
  29. package/dist/devices/motion.d.ts +26 -25
  30. package/dist/devices/motion.d.ts.map +1 -1
  31. package/dist/devices/motion.js +102 -120
  32. package/dist/devices/motion.js.map +1 -1
  33. package/dist/devices/plugs.d.ts +23 -23
  34. package/dist/devices/plugs.d.ts.map +1 -1
  35. package/dist/devices/plugs.js +63 -81
  36. package/dist/devices/plugs.js.map +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -22
  40. package/dist/index.js.map +1 -1
  41. package/dist/irdevices/airconditioners.d.ts +6 -6
  42. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  43. package/dist/irdevices/airconditioners.js +79 -105
  44. package/dist/irdevices/airconditioners.js.map +1 -1
  45. package/dist/irdevices/airpurifiers.d.ts +5 -5
  46. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  47. package/dist/irdevices/airpurifiers.js +42 -56
  48. package/dist/irdevices/airpurifiers.js.map +1 -1
  49. package/dist/irdevices/cameras.d.ts +5 -5
  50. package/dist/irdevices/cameras.d.ts.map +1 -1
  51. package/dist/irdevices/cameras.js +27 -31
  52. package/dist/irdevices/cameras.js.map +1 -1
  53. package/dist/irdevices/fans.d.ts +5 -5
  54. package/dist/irdevices/fans.d.ts.map +1 -1
  55. package/dist/irdevices/fans.js +38 -45
  56. package/dist/irdevices/fans.js.map +1 -1
  57. package/dist/irdevices/lights.d.ts +5 -5
  58. package/dist/irdevices/lights.d.ts.map +1 -1
  59. package/dist/irdevices/lights.js +33 -37
  60. package/dist/irdevices/lights.js.map +1 -1
  61. package/dist/irdevices/others.d.ts +5 -5
  62. package/dist/irdevices/others.d.ts.map +1 -1
  63. package/dist/irdevices/others.js +29 -34
  64. package/dist/irdevices/others.js.map +1 -1
  65. package/dist/irdevices/tvs.d.ts +5 -5
  66. package/dist/irdevices/tvs.d.ts.map +1 -1
  67. package/dist/irdevices/tvs.js +76 -91
  68. package/dist/irdevices/tvs.js.map +1 -1
  69. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  70. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  71. package/dist/irdevices/vacuumcleaners.js +27 -31
  72. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  73. package/dist/irdevices/waterheaters.d.ts +5 -5
  74. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  75. package/dist/irdevices/waterheaters.js +27 -31
  76. package/dist/irdevices/waterheaters.js.map +1 -1
  77. package/dist/platform.d.ts +12 -12
  78. package/dist/platform.d.ts.map +1 -1
  79. package/dist/platform.js +172 -241
  80. package/dist/platform.js.map +1 -1
  81. package/dist/settings.d.ts +2 -1
  82. package/dist/settings.d.ts.map +1 -1
  83. package/dist/settings.js +4 -4
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +71 -72
  86. package/src/devices/bots.ts +455 -929
  87. package/src/devices/colorbulb.ts +246 -473
  88. package/src/devices/contact.ts +208 -381
  89. package/src/devices/curtains.ts +321 -613
  90. package/src/devices/humidifiers.ts +323 -594
  91. package/src/devices/meters.ts +186 -331
  92. package/src/devices/motion.ts +184 -327
  93. package/src/devices/plugs.ts +107 -175
  94. package/src/index.ts +5 -5
  95. package/src/irdevices/airconditioners.ts +149 -360
  96. package/src/irdevices/airpurifiers.ts +80 -178
  97. package/src/irdevices/cameras.ts +51 -109
  98. package/src/irdevices/fans.ts +77 -174
  99. package/src/irdevices/lights.ts +57 -110
  100. package/src/irdevices/others.ts +62 -137
  101. package/src/irdevices/tvs.ts +124 -249
  102. package/src/irdevices/vacuumcleaners.ts +52 -112
  103. package/src/irdevices/waterheaters.ts +53 -115
  104. package/src/platform.ts +357 -768
  105. package/src/settings.ts +24 -17
@@ -1,9 +1,9 @@
1
- import * as axios from "axios";
2
- import * as rxjs from "rxjs";
3
- import * as platform from "../platform";
4
- import * as operators from "rxjs/operators";
5
- import * as homebridge from "homebridge";
6
- import * as settings from "../settings";
1
+ import { AxiosResponse } from 'axios';
2
+ import { interval, Subject } from 'rxjs';
3
+ import { SwitchBotPlatform } from '../platform';
4
+ import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
+ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
6
+ import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs, deviceStatus } from '../settings';
7
7
 
8
8
  /**
9
9
  * Platform Accessory
@@ -12,29 +12,29 @@ import * as settings from "../settings";
12
12
  */
13
13
  export class ColorBulb {
14
14
  // Services
15
- service!: homebridge.Service;
15
+ service!: Service;
16
16
 
17
17
  // Characteristic Values
18
- On!: homebridge.CharacteristicValue;
19
- OnCached!: homebridge.CharacteristicValue;
20
- Hue!: homebridge.CharacteristicValue;
21
- HueCached!: homebridge.CharacteristicValue;
22
- Saturation!: homebridge.CharacteristicValue;
23
- SaturationCached!: homebridge.CharacteristicValue;
24
- Brightness!: homebridge.CharacteristicValue;
25
- BrightnessCached!: homebridge.CharacteristicValue;
26
- ColorTemperature!: homebridge.CharacteristicValue;
27
- ColorTemperatureCached!: homebridge.CharacteristicValue;
18
+ On!: CharacteristicValue;
19
+ OnCached!: CharacteristicValue;
20
+ Hue!: CharacteristicValue;
21
+ HueCached!: CharacteristicValue;
22
+ Saturation!: CharacteristicValue;
23
+ SaturationCached!: CharacteristicValue;
24
+ Brightness!: CharacteristicValue;
25
+ BrightnessCached!: CharacteristicValue;
26
+ ColorTemperature!: CharacteristicValue;
27
+ ColorTemperatureCached!: CharacteristicValue;
28
28
 
29
29
  // OpenAPI Others
30
- power: settings.deviceStatus["power"];
31
- color: settings.deviceStatus["color"];
32
- brightness: settings.deviceStatus["brightness"];
33
- colorTemperature: settings.deviceStatus["colorTemperature"];
34
- deviceStatus!: settings.deviceStatusResponse;
30
+ power: deviceStatus['power'];
31
+ color: deviceStatus['color'];
32
+ brightness: deviceStatus['brightness'];
33
+ colorTemperature: deviceStatus['colorTemperature'];
34
+ deviceStatus!: deviceStatusResponse;
35
35
 
36
36
  // BLE Others
37
- switchbot!: settings.switchbot;
37
+ switchbot!: switchbot;
38
38
 
39
39
  // Config
40
40
  set_minStep?: number;
@@ -43,22 +43,19 @@ export class ColorBulb {
43
43
  adaptiveLightingShift?: number;
44
44
 
45
45
  // Adaptive Lighting
46
- AdaptiveLightingController?:
47
- | homebridge.ControllerConstructor
48
- | homebridge.Controller<homebridge.ControllerServiceMap>;
49
-
46
+ AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
50
47
  minKelvin: number;
51
48
  maxKelvin: number;
52
49
 
53
50
  // Updates
54
51
  colorBulbUpdateInProgress!: boolean;
55
- doColorBulbUpdate!: rxjs.Subject<void>;
52
+ doColorBulbUpdate!: Subject<void>;
56
53
  cacheKelvin!: number;
57
54
 
58
55
  constructor(
59
- private readonly platform: platform.SwitchBotPlatform,
60
- private accessory: homebridge.PlatformAccessory,
61
- public device: settings.device & settings.devicesConfig,
56
+ private readonly platform: SwitchBotPlatform,
57
+ private accessory: PlatformAccessory,
58
+ public device: device & devicesConfig,
62
59
  ) {
63
60
  // default placeholders
64
61
  this.logs(device);
@@ -77,42 +74,32 @@ export class ColorBulb {
77
74
  this.minKelvin = 2000;
78
75
  this.maxKelvin = 9000;
79
76
  // this is subject we use to track when we need to POST changes to the SwitchBot API
80
- this.doColorBulbUpdate = new rxjs.Subject();
77
+ this.doColorBulbUpdate = new Subject();
81
78
  this.colorBulbUpdateInProgress = false;
82
79
 
80
+
83
81
  // Retrieve initial values and updateHomekit
84
82
  this.refreshStatus();
85
83
 
86
84
  // set accessory information
87
85
  accessory
88
86
  .getService(this.platform.Service.AccessoryInformation)!
89
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
90
- .setCharacteristic(
91
- this.platform.Characteristic.Model,
92
- "SWITCHBOT-COLORBULB-W1401400",
93
- )
94
- .setCharacteristic(
95
- this.platform.Characteristic.SerialNumber,
96
- device.deviceId!,
97
- );
87
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
88
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
89
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
98
90
 
99
91
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
100
92
  // you can create multiple services for each accessory
101
93
  (this.service =
102
94
  accessory.getService(this.platform.Service.Lightbulb) ||
103
- accessory.addService(this.platform.Service.Lightbulb)),
104
- `${accessory.displayName} Light Bulb`;
95
+ accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
96
+
105
97
 
106
- if (
107
- this.adaptiveLightingShift === -1 &&
108
- this.accessory.context.adaptiveLighting
109
- ) {
98
+ if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
110
99
  this.accessory.removeService(this.service);
111
100
  this.service = this.accessory.addService(this.platform.Service.Lightbulb);
112
101
  this.accessory.context.adaptiveLighting = false;
113
- this.debugLog(
114
- `Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`,
115
- );
102
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
116
103
  }
117
104
 
118
105
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -121,19 +108,14 @@ export class ColorBulb {
121
108
 
122
109
  // set the service name, this is what is displayed as the default name on the Home app
123
110
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
124
- this.service.setCharacteristic(
125
- this.platform.Characteristic.Name,
126
- accessory.displayName,
127
- );
111
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
128
112
 
129
113
  // handle on / off events using the On characteristic
130
- this.service
131
- .getCharacteristic(this.platform.Characteristic.On)
114
+ this.service.getCharacteristic(this.platform.Characteristic.On)
132
115
  .onSet(this.OnSet.bind(this));
133
116
 
134
117
  // handle Brightness events using the Brightness characteristic
135
- this.service
136
- .getCharacteristic(this.platform.Characteristic.Brightness)
118
+ this.service.getCharacteristic(this.platform.Characteristic.Brightness)
137
119
  .setProps({
138
120
  minStep: this.minStep(device),
139
121
  minValue: 0,
@@ -146,8 +128,7 @@ export class ColorBulb {
146
128
  .onSet(this.BrightnessSet.bind(this));
147
129
 
148
130
  // handle ColorTemperature events using the ColorTemperature characteristic
149
- this.service
150
- .getCharacteristic(this.platform.Characteristic.ColorTemperature)
131
+ this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature)
151
132
  .setProps({
152
133
  minValue: 140,
153
134
  maxValue: 500,
@@ -158,9 +139,9 @@ export class ColorBulb {
158
139
  })
159
140
  .onSet(this.ColorTemperatureSet.bind(this));
160
141
 
142
+
161
143
  // handle Hue events using the Hue characteristic
162
- this.service
163
- .getCharacteristic(this.platform.Characteristic.Hue)
144
+ this.service.getCharacteristic(this.platform.Characteristic.Hue)
164
145
  .setProps({
165
146
  minValue: 0,
166
147
  maxValue: 360,
@@ -172,8 +153,7 @@ export class ColorBulb {
172
153
  .onSet(this.HueSet.bind(this));
173
154
 
174
155
  // handle Hue events using the Hue characteristic
175
- this.service
176
- .getCharacteristic(this.platform.Characteristic.Saturation)
156
+ this.service.getCharacteristic(this.platform.Characteristic.Saturation)
177
157
  .setProps({
178
158
  minValue: 0,
179
159
  maxValue: 100,
@@ -184,29 +164,24 @@ export class ColorBulb {
184
164
  })
185
165
  .onSet(this.SaturationSet.bind(this));
186
166
 
187
- this.debugLog(
188
- `Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
189
- );
167
+
168
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
190
169
  if (this.adaptiveLightingShift !== -1) {
191
- this.AdaptiveLightingController =
192
- new platform.api.hap.AdaptiveLightingController(this.service, {
193
- customTemperatureAdjustment: this.adaptiveLightingShift,
194
- });
170
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
171
+ customTemperatureAdjustment: this.adaptiveLightingShift,
172
+ });
195
173
  this.accessory.configureController(this.AdaptiveLightingController);
196
174
  this.accessory.context.adaptiveLighting = true;
197
- this.debugLog(
198
- `Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
199
- ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
200
- );
175
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
176
+ + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
201
177
  }
202
178
 
203
179
  // Update Homekit
204
180
  this.updateHomeKitCharacteristics();
205
181
 
206
182
  // Start an update interval
207
- rxjs
208
- .interval(this.deviceRefreshRate * 1000)
209
- .pipe(operators.skipWhile(() => this.colorBulbUpdateInProgress))
183
+ interval(this.deviceRefreshRate * 1000)
184
+ .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
210
185
  .subscribe(() => {
211
186
  this.refreshStatus();
212
187
  });
@@ -215,23 +190,23 @@ export class ColorBulb {
215
190
  // We put in a debounce of 100ms so we don't make duplicate calls
216
191
  this.doColorBulbUpdate
217
192
  .pipe(
218
- operators.tap(() => {
193
+ tap(() => {
219
194
  this.colorBulbUpdateInProgress = true;
220
195
  }),
221
- operators.debounceTime(this.platform.config.options!.pushRate! * 1000),
196
+ debounceTime(this.platform.config.options!.pushRate! * 1000),
222
197
  )
223
198
  .subscribe(async () => {
224
199
  try {
225
200
  await this.pushChanges();
226
201
  } catch (e: any) {
227
- this.errorLog(
228
- `Color Bulb: ${this.accessory.displayName} failed pushChanges`,
229
- );
230
- if (this.deviceLogging.includes("debug")) {
231
- this.errorLog(
232
- `Color Bulb: ${this.accessory.displayName} failed pushChanges,` +
233
- ` Error Message: ${JSON.stringify(e.message)}`,
234
- );
202
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
203
+ if (this.deviceLogging === 'debug') {
204
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
205
+ + ` Error Message: ${JSON.stringify(e.message)}`);
206
+ }
207
+ if (this.platform.debugMode) {
208
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
209
+ + ` Error: ${JSON.stringify(e)}`);
235
210
  }
236
211
  this.apiError(e);
237
212
  }
@@ -241,7 +216,7 @@ export class ColorBulb {
241
216
 
242
217
  parseStatus() {
243
218
  switch (this.power) {
244
- case "on":
219
+ case 'on':
245
220
  this.On = true;
246
221
  break;
247
222
  default:
@@ -251,87 +226,44 @@ export class ColorBulb {
251
226
 
252
227
  // Brightness
253
228
  this.Brightness = Number(this.brightness);
254
- this.debugLog(
255
- `Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`,
256
- );
229
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
257
230
 
258
231
  // Color, Hue & Brightness
259
232
  if (this.color) {
260
- this.debugLog(
261
- `Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(
262
- this.color,
263
- )}`,
264
- );
265
- const [red, green, blue] = this.color!.split(":");
266
- this.debugLog(
267
- `Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`,
268
- );
269
- this.debugLog(
270
- `Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(
271
- green,
272
- )}`,
273
- );
274
- this.debugLog(
275
- `Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(
276
- blue,
277
- )}`,
278
- );
279
-
280
- const [hue, saturation] = settings.rgb2hs(
281
- Number(red),
282
- Number(green),
283
- Number(blue),
284
- );
285
- this.debugLog(
286
- `Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(
287
- settings.rgb2hs(Number(red), Number(green), Number(blue)),
288
- )}`,
289
- );
233
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
234
+ const [red, green, blue] = this.color!.split(':');
235
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
236
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
237
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
238
+
239
+ const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
240
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
290
241
 
291
242
  // Hue
292
243
  this.Hue = hue;
293
- this.debugLog(
294
- `Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`,
295
- );
244
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
296
245
 
297
246
  // Saturation
298
247
  this.Saturation = saturation;
299
- this.debugLog(
300
- `Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`,
301
- );
248
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
302
249
  }
303
250
 
304
251
  // ColorTemperature
305
252
  if (!Number.isNaN(this.colorTemperature)) {
306
- this.debugLog(
307
- `Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`,
308
- );
253
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
309
254
  const mired = Math.round(1000000 / this.colorTemperature!);
310
255
 
311
256
  this.ColorTemperature = Number(mired);
312
257
 
313
- this.ColorTemperature = Math.max(
314
- Math.min(this.ColorTemperature, 500),
315
- 140,
316
- );
317
- this.debugLog(
318
- `Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`,
319
- );
258
+ this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
259
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
320
260
  }
321
261
  }
322
262
 
323
263
  async refreshStatus() {
324
264
  try {
325
- this.deviceStatus = (
326
- await this.platform.axios.get(
327
- `${settings.DeviceURL}/${this.device.deviceId}/status`,
328
- )
329
- ).data;
330
- this.debugLog(
331
- `Color Bulb: ${
332
- this.accessory.displayName
333
- } refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
334
- );
265
+ this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
266
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
335
267
  this.power = this.deviceStatus.body.power;
336
268
  this.color = this.deviceStatus.body.color;
337
269
  this.brightness = this.deviceStatus.body.brightness;
@@ -339,59 +271,50 @@ export class ColorBulb {
339
271
  this.parseStatus();
340
272
  this.updateHomeKitCharacteristics();
341
273
  } catch (e: any) {
342
- this.errorLog(
343
- `Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
344
- );
345
- if (this.deviceLogging.includes("debug")) {
346
- this.errorLog(
347
- `Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
348
- ` Error Message: ${JSON.stringify(e.message)}`,
349
- );
274
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
275
+ if (this.deviceLogging === 'debug') {
276
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
277
+ + ` Error Message: ${JSON.stringify(e.message)}`);
278
+ }
279
+ if (this.platform.debugMode) {
280
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
281
+ + ` Error: ${JSON.stringify(e)}`);
350
282
  }
351
283
  this.apiError(e);
352
284
  }
353
285
  }
354
286
 
355
287
  /**
356
- * Pushes the requested changes to the SwitchBot API
357
- * deviceType commandType Command command parameter Description
358
- * Color Bulb - "command" "turnOff" "default" = set to OFF state
359
- * Color Bulb - "command" "turnOn" "default" = set to ON state
360
- * Color Bulb - "command" "toggle" "default" = toggle state
361
- * Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
362
- * Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
363
- * Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
364
- */
288
+ * Pushes the requested changes to the SwitchBot API
289
+ * deviceType commandType Command command parameter Description
290
+ * Color Bulb - "command" "turnOff" "default" = set to OFF state
291
+ * Color Bulb - "command" "turnOn" "default" = set to ON state
292
+ * Color Bulb - "command" "toggle" "default" = toggle state
293
+ * Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
294
+ * Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
295
+ * Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
296
+ */
365
297
  async pushChanges() {
366
298
  try {
367
299
  if (this.On !== this.OnCached) {
368
300
  // Push On Update
369
301
  const payload = {
370
- commandType: "command",
371
- parameter: "default",
372
- } as settings.payload;
302
+ commandType: 'command',
303
+ parameter: 'default',
304
+ } as payload;
373
305
 
374
306
  if (this.On) {
375
- payload.command = "turnOn";
307
+ payload.command = 'turnOn';
376
308
  } else {
377
- payload.command = "turnOff";
309
+ payload.command = 'turnOff';
378
310
  }
379
311
 
380
- this.infoLog(
381
- `Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
382
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
383
- );
312
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
313
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
384
314
 
385
315
  // Make the API request
386
- const push: any = await this.platform.axios.post(
387
- `${settings.DeviceURL}/${this.device.deviceId}/commands`,
388
- payload,
389
- );
390
- this.debugLog(
391
- `Color Bulb: ${
392
- this.accessory.displayName
393
- } pushChanges: ${JSON.stringify(push.data)}`,
394
- );
316
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
317
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
395
318
  this.statusCode(push);
396
319
  this.OnCached = this.On;
397
320
  this.accessory.context.On = this.OnCached;
@@ -410,15 +333,16 @@ export class ColorBulb {
410
333
  if (this.On) {
411
334
  await this.pushHueSaturationChanges();
412
335
  }
336
+
413
337
  } catch (e: any) {
414
- this.errorLog(
415
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
416
- );
417
- if (this.deviceLogging.includes("debug")) {
418
- this.errorLog(
419
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
420
- ` Error Message: ${JSON.stringify(e.message)}`,
421
- );
338
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
339
+ if (this.deviceLogging === 'debug') {
340
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
341
+ + ` Error Message: ${JSON.stringify(e.message)}`);
342
+ }
343
+ if (this.platform.debugMode) {
344
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
345
+ + ` Error: ${JSON.stringify(e)}`);
422
346
  }
423
347
  this.apiError(e);
424
348
  }
@@ -426,72 +350,41 @@ export class ColorBulb {
426
350
 
427
351
  private async pushHueSaturationChanges() {
428
352
  try {
429
- if (
430
- this.Hue !== this.HueCached ||
431
- this.Saturation !== this.SaturationCached
432
- ) {
433
- this.debugLog(
434
- `Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(
435
- this.Hue,
436
- )}`,
437
- );
438
- this.debugLog(
439
- `Color Bulb: ${
440
- this.accessory.displayName
441
- } Saturation: ${JSON.stringify(this.Saturation)}`,
442
- );
443
-
444
- const [red, green, blue] = settings.hs2rgb(
445
- Number(this.Hue),
446
- Number(this.Saturation),
447
- );
448
- this.debugLog(
449
- `Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([
450
- red,
451
- green,
452
- blue,
453
- ])}`,
454
- );
353
+ if ((this.Hue !== this.HueCached) || (this.Saturation !== this.SaturationCached)) {
354
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
355
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
356
+
357
+ const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
358
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
455
359
 
456
360
  const payload = {
457
- commandType: "command",
458
- command: "setColor",
361
+ commandType: 'command',
362
+ command: 'setColor',
459
363
  parameter: `${red}:${green}:${blue}`,
460
- } as settings.payload;
364
+ } as payload;
461
365
 
462
- this.infoLog(
463
- `Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
464
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
465
- );
366
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
367
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
466
368
 
467
369
  // Make the API request
468
- const push: any = await this.platform.axios.post(
469
- `${settings.DeviceURL}/${this.device.deviceId}/commands`,
470
- payload,
471
- );
472
- this.debugLog(
473
- `Color Bulb: ${
474
- this.accessory.displayName
475
- } pushChanges: ${JSON.stringify(push.data)}`,
476
- );
370
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
371
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
477
372
  this.statusCode(push);
478
373
  this.HueCached = this.Hue;
479
374
  this.SaturationCached = this.Saturation;
480
375
  } else {
481
- this.debugLog(
482
- `Color Bulb: ${this.accessory.displayName} No Changes.` +
483
- `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
484
- );
376
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
377
+ + `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
485
378
  }
486
379
  } catch (e: any) {
487
- this.errorLog(
488
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
489
- );
490
- if (this.deviceLogging.includes("debug")) {
491
- this.errorLog(
492
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
493
- ` Error Message: ${JSON.stringify(e.message)}`,
494
- );
380
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
381
+ if (this.deviceLogging === 'debug') {
382
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
383
+ + ` Error Message: ${JSON.stringify(e.message)}`);
384
+ }
385
+ if (this.platform.debugMode) {
386
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
387
+ + ` Error: ${JSON.stringify(e)}`);
495
388
  }
496
389
  this.apiError(e);
497
390
  }
@@ -504,43 +397,32 @@ export class ColorBulb {
504
397
  this.cacheKelvin = kelvin;
505
398
 
506
399
  const payload = {
507
- commandType: "command",
508
- command: "setColorTemperature",
400
+ commandType: 'command',
401
+ command: 'setColorTemperature',
509
402
  parameter: `${kelvin}`,
510
- } as settings.payload;
403
+ } as payload;
511
404
 
512
- this.infoLog(
513
- `Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
514
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
515
- );
405
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
406
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
516
407
 
517
408
  // Make the API request
518
- const push: any = await this.platform.axios.post(
519
- `${settings.DeviceURL}/${this.device.deviceId}/commands`,
520
- payload,
521
- );
522
- this.debugLog(
523
- `Color Bulb: ${
524
- this.accessory.displayName
525
- } pushChanges: ${JSON.stringify(push.data)}`,
526
- );
409
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
410
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
527
411
  this.statusCode(push);
528
412
  this.ColorTemperatureCached = this.ColorTemperature;
529
413
  } else {
530
- this.debugLog(
531
- `Color Bulb: ${this.accessory.displayName} No Changes.` +
532
- `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`,
533
- );
414
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
415
+ + `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
534
416
  }
535
417
  } catch (e: any) {
536
- this.errorLog(
537
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
538
- );
539
- if (this.deviceLogging.includes("debug")) {
540
- this.errorLog(
541
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
542
- ` Error Message: ${JSON.stringify(e.message)}`,
543
- );
418
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
419
+ if (this.deviceLogging === 'debug') {
420
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
421
+ + ` Error Message: ${JSON.stringify(e.message)}`);
422
+ }
423
+ if (this.platform.debugMode) {
424
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
425
+ + ` Error: ${JSON.stringify(e)}`);
544
426
  }
545
427
  this.apiError(e);
546
428
  }
@@ -550,43 +432,32 @@ export class ColorBulb {
550
432
  try {
551
433
  if (this.Brightness !== this.BrightnessCached) {
552
434
  const payload = {
553
- commandType: "command",
554
- command: "setBrightness",
435
+ commandType: 'command',
436
+ command: 'setBrightness',
555
437
  parameter: `${this.Brightness}`,
556
- } as settings.payload;
438
+ } as payload;
557
439
 
558
- this.infoLog(
559
- `Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
560
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
561
- );
440
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
441
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
562
442
 
563
443
  // Make the API request
564
- const push: any = await this.platform.axios.post(
565
- `${settings.DeviceURL}/${this.device.deviceId}/commands`,
566
- payload,
567
- );
568
- this.debugLog(
569
- `Color Bulb: ${
570
- this.accessory.displayName
571
- } pushChanges: ${JSON.stringify(push.data)}`,
572
- );
444
+ const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
445
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
573
446
  this.statusCode(push);
574
447
  this.BrightnessCached = this.Brightness;
575
448
  } else {
576
- this.debugLog(
577
- `Color Bulb: ${this.accessory.displayName} No Changes.` +
578
- `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
579
- );
449
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
450
+ + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
580
451
  }
581
452
  } catch (e: any) {
582
- this.errorLog(
583
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
584
- );
585
- if (this.deviceLogging.includes("debug")) {
586
- this.errorLog(
587
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
588
- ` Error Message: ${JSON.stringify(e.message)}`,
589
- );
453
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
454
+ if (this.deviceLogging === 'debug') {
455
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
456
+ + ` Error Message: ${JSON.stringify(e.message)}`);
457
+ }
458
+ if (this.platform.debugMode) {
459
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
460
+ + ` Error: ${JSON.stringify(e)}`);
590
461
  }
591
462
  this.apiError(e);
592
463
  }
@@ -596,133 +467,75 @@ export class ColorBulb {
596
467
  if (this.On === undefined) {
597
468
  this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
598
469
  } else {
599
- this.service.updateCharacteristic(
600
- this.platform.Characteristic.On,
601
- this.On,
602
- );
603
- this.debugLog(
604
- `Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
605
- );
470
+ this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
471
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
606
472
  }
607
473
  if (this.Brightness === undefined) {
608
- this.debugLog(
609
- `Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`,
610
- );
474
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
611
475
  } else {
612
- this.service.updateCharacteristic(
613
- this.platform.Characteristic.Brightness,
614
- this.Brightness,
615
- );
616
- this.debugLog(
617
- `Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`,
618
- );
476
+ this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
477
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
619
478
  }
620
479
  if (this.ColorTemperature === undefined) {
621
- this.debugLog(
622
- `Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`,
623
- );
480
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
624
481
  } else {
625
- this.service.updateCharacteristic(
626
- this.platform.Characteristic.ColorTemperature,
627
- this.ColorTemperature,
628
- );
629
- this.debugLog(
630
- `Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`,
631
- );
482
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
483
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
632
484
  }
633
485
  if (this.Hue === undefined) {
634
- this.debugLog(
635
- `Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`,
636
- );
486
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
637
487
  } else {
638
- this.service.updateCharacteristic(
639
- this.platform.Characteristic.Hue,
640
- this.Hue,
641
- );
642
- this.debugLog(
643
- `Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`,
644
- );
488
+ this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
489
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
645
490
  }
646
491
  if (this.Saturation === undefined) {
647
- this.debugLog(
648
- `Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`,
649
- );
492
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
650
493
  } else {
651
- this.service.updateCharacteristic(
652
- this.platform.Characteristic.Saturation,
653
- this.Saturation,
654
- );
655
- this.debugLog(
656
- `Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`,
657
- );
494
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
495
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
658
496
  }
659
497
  }
660
498
 
661
499
  public apiError(e: any) {
662
500
  this.service.updateCharacteristic(this.platform.Characteristic.On, e);
663
501
  this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
664
- this.service.updateCharacteristic(
665
- this.platform.Characteristic.Brightness,
666
- e,
667
- );
668
- this.service.updateCharacteristic(
669
- this.platform.Characteristic.Saturation,
670
- e,
671
- );
672
- this.service.updateCharacteristic(
673
- this.platform.Characteristic.ColorTemperature,
674
- e,
675
- );
502
+ this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
503
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
504
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
676
505
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
677
506
  }
678
507
 
679
- private statusCode(push: axios.AxiosResponse<{ statusCode: number }>) {
508
+ private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
680
509
  switch (push.data.statusCode) {
681
510
  case 151:
682
- this.errorLog(
683
- `Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`,
684
- );
511
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
685
512
  break;
686
513
  case 152:
687
- this.errorLog(
688
- `Color Bulb: ${this.accessory.displayName} Device not found.`,
689
- );
514
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
690
515
  break;
691
516
  case 160:
692
- this.errorLog(
693
- `Color Bulb: ${this.accessory.displayName} Command is not supported.`,
694
- );
517
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
695
518
  break;
696
519
  case 161:
697
- this.errorLog(
698
- `Color Bulb: ${this.accessory.displayName} Device is offline.`,
699
- );
520
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
700
521
  this.offlineOff();
701
522
  break;
702
523
  case 171:
703
- this.errorLog(
704
- `Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`,
705
- );
524
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
706
525
  this.offlineOff();
707
526
  break;
708
527
  case 190:
709
- this.errorLog(
710
- `Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
711
- ` Or command: ${JSON.stringify(push.data)} format is invalid`,
712
- );
528
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
529
+ + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
713
530
  break;
714
531
  case 100:
715
532
  if (this.platform.debugMode) {
716
- this.debugLog(
717
- `Color Bulb: ${this.accessory.displayName} Command successfully sent.`,
718
- );
533
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
719
534
  }
720
535
  break;
721
536
  default:
722
537
  if (this.platform.debugMode) {
723
- this.debugLog(
724
- `Color Bulb: ${this.accessory.displayName} Unknown statusCode.`,
725
- );
538
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
726
539
  }
727
540
  }
728
541
  }
@@ -730,16 +543,14 @@ export class ColorBulb {
730
543
  private offlineOff() {
731
544
  if (this.device.offline) {
732
545
  this.On = false;
733
- this.service
734
- .getCharacteristic(this.platform.Characteristic.On)
735
- .updateValue(this.On);
546
+ this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
736
547
  }
737
548
  }
738
549
 
739
550
  /**
740
551
  * Handle requests to set the value of the "On" characteristic
741
552
  */
742
- OnSet(value: homebridge.CharacteristicValue) {
553
+ OnSet(value: CharacteristicValue) {
743
554
  this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
744
555
 
745
556
  this.On = value;
@@ -749,10 +560,8 @@ export class ColorBulb {
749
560
  /**
750
561
  * Handle requests to set the value of the "Brightness" characteristic
751
562
  */
752
- BrightnessSet(value: homebridge.CharacteristicValue) {
753
- this.debugLog(
754
- `Color Bulb: ${this.accessory.displayName} Brightness: ${value}`,
755
- );
563
+ BrightnessSet(value: CharacteristicValue) {
564
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
756
565
 
757
566
  this.Brightness = value;
758
567
  this.doColorBulbUpdate.next();
@@ -761,10 +570,9 @@ export class ColorBulb {
761
570
  /**
762
571
  * Handle requests to set the value of the "ColorTemperature" characteristic
763
572
  */
764
- ColorTemperatureSet(value: homebridge.CharacteristicValue) {
765
- this.debugLog(
766
- `Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`,
767
- );
573
+ ColorTemperatureSet(value: CharacteristicValue) {
574
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
575
+
768
576
 
769
577
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
770
578
  const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
@@ -777,131 +585,97 @@ export class ColorBulb {
777
585
  }
778
586
 
779
587
  // Updating the hue/sat to the corresponding values mimics native adaptive lighting
780
- const hs = settings.m2hs(value);
588
+ const hs = m2hs(value);
781
589
  this.service.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
782
- this.service.updateCharacteristic(
783
- this.platform.Characteristic.Saturation,
784
- hs[1],
785
- );
590
+ this.service.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
786
591
 
787
592
  this.ColorTemperature = value;
788
593
  this.doColorBulbUpdate.next();
789
594
  }
790
595
 
791
596
  /**
792
- * Handle requests to set the value of the "Hue" characteristic
793
- */
794
- HueSet(value: homebridge.CharacteristicValue) {
597
+ * Handle requests to set the value of the "Hue" characteristic
598
+ */
599
+ HueSet(value: CharacteristicValue) {
795
600
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
796
601
 
797
- this.service.updateCharacteristic(
798
- this.platform.Characteristic.ColorTemperature,
799
- 140,
800
- );
602
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
801
603
 
802
604
  this.Hue = value;
803
605
  this.doColorBulbUpdate.next();
804
606
  }
805
607
 
806
608
  /**
807
- * Handle requests to set the value of the "Saturation" characteristic
808
- */
809
- SaturationSet(value: homebridge.CharacteristicValue) {
810
- this.debugLog(
811
- `Color Bulb: ${this.accessory.displayName} Saturation: ${value}`,
812
- );
609
+ * Handle requests to set the value of the "Saturation" characteristic
610
+ */
611
+ SaturationSet(value: CharacteristicValue) {
612
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
813
613
 
814
- this.service.updateCharacteristic(
815
- this.platform.Characteristic.ColorTemperature,
816
- 140,
817
- );
614
+ this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
818
615
 
819
616
  this.Saturation = value;
820
617
  this.doColorBulbUpdate.next();
821
618
  }
822
619
 
823
- config(device: settings.device & settings.devicesConfig) {
620
+ config(device: device & devicesConfig) {
824
621
  let config = {};
825
622
  if (device.colorbulb) {
826
623
  config = device.colorbulb;
827
624
  }
828
625
  if (device.ble) {
829
- config["ble"] = device.ble;
626
+ config['ble'] = device.ble;
830
627
  }
831
628
  if (device.logging !== undefined) {
832
- config["logging"] = device.logging;
629
+ config['logging'] = device.logging;
833
630
  }
834
631
  if (device.refreshRate !== undefined) {
835
- config["refreshRate"] = device.refreshRate;
632
+ config['refreshRate'] = device.refreshRate;
836
633
  }
837
634
  if (device.scanDuration !== undefined) {
838
- config["scanDuration"] = device.scanDuration;
635
+ config['scanDuration'] = device.scanDuration;
839
636
  }
840
637
  if (Object.entries(config).length !== 0) {
841
- this.warnLog(
842
- `Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(
843
- config,
844
- )}`,
845
- );
638
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
846
639
  }
847
640
  }
848
641
 
849
- refreshRate(device: settings.device & settings.devicesConfig) {
642
+ refreshRate(device: device & devicesConfig) {
850
643
  if (device.refreshRate) {
851
- this.deviceRefreshRate = this.accessory.context.refreshRate =
852
- device.refreshRate;
853
- this.debugLog(
854
- `Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
855
- );
644
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
645
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
856
646
  } else if (this.platform.config.options!.refreshRate) {
857
- this.deviceRefreshRate = this.accessory.context.refreshRate =
858
- this.platform.config.options!.refreshRate;
859
- this.debugLog(
860
- `Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
861
- );
647
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
648
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
862
649
  }
863
650
  }
864
651
 
865
- logs(device: settings.device & settings.devicesConfig) {
652
+ logs(device: device & devicesConfig) {
866
653
  if (this.platform.debugMode) {
867
- this.deviceLogging = this.accessory.context.logging = "debugMode";
868
- this.debugLog(
869
- `Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
870
- );
654
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
655
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
871
656
  } else if (device.logging) {
872
657
  this.deviceLogging = this.accessory.context.logging = device.logging;
873
- this.debugLog(
874
- `Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
875
- );
658
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
876
659
  } else if (this.platform.config.options?.logging) {
877
- this.deviceLogging = this.accessory.context.logging =
878
- this.platform.config.options?.logging;
879
- this.debugLog(
880
- `Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
881
- );
660
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
661
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
882
662
  } else {
883
- this.deviceLogging = this.accessory.context.logging = "standard";
884
- this.debugLog(
885
- `Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
886
- );
663
+ this.deviceLogging = this.accessory.context.logging = 'standard';
664
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
887
665
  }
888
666
  }
889
667
 
890
- adaptiveLighting(device: settings.device & settings.devicesConfig) {
668
+ adaptiveLighting(device: device & devicesConfig) {
891
669
  if (device.colorbulb?.adaptiveLightingShift) {
892
670
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
893
- this.debugLog(
894
- `Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
895
- );
671
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
896
672
  } else {
897
673
  this.adaptiveLightingShift = 0;
898
- this.debugLog(
899
- `Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
900
- );
674
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
901
675
  }
902
676
  }
903
677
 
904
- minStep(device: settings.device & settings.devicesConfig): number {
678
+ minStep(device: device & devicesConfig): number {
905
679
  if (device.colorbulb?.set_minStep) {
906
680
  this.set_minStep = device.colorbulb?.set_minStep;
907
681
  } else {
@@ -911,8 +685,8 @@ export class ColorBulb {
911
685
  }
912
686
 
913
687
  /**
914
- * Logging for Device
915
- */
688
+ * Logging for Device
689
+ */
916
690
  infoLog(...log: any[]) {
917
691
  if (this.enablingDeviceLogging()) {
918
692
  this.platform.log.info(String(...log));
@@ -933,8 +707,8 @@ export class ColorBulb {
933
707
 
934
708
  debugLog(...log: any[]) {
935
709
  if (this.enablingDeviceLogging()) {
936
- if (this.deviceLogging === "debug") {
937
- this.platform.log.info("[DEBUG]", String(...log));
710
+ if (this.deviceLogging === 'debug') {
711
+ this.platform.log.info('[DEBUG]', String(...log));
938
712
  } else {
939
713
  this.platform.log.debug(String(...log));
940
714
  }
@@ -942,8 +716,7 @@ export class ColorBulb {
942
716
  }
943
717
 
944
718
  enablingDeviceLogging(): boolean {
945
- return (
946
- this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
947
- );
719
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
948
720
  }
949
721
  }
722
+