@switchbot/homebridge-switchbot 1.10.2-beta.8 → 1.11.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 (52) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/config.schema.json +49 -0
  3. package/dist/device/bot.d.ts +43 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +26 -26
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +173 -145
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +38 -38
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +14 -14
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -11
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +14 -14
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +13 -13
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +17 -17
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/settings.d.ts +4 -1
  40. package/dist/settings.d.ts.map +1 -1
  41. package/dist/settings.js.map +1 -1
  42. package/package.json +76 -76
  43. package/src/device/bot.ts +50 -50
  44. package/src/device/colorbulb.ts +205 -162
  45. package/src/device/contact.ts +31 -30
  46. package/src/device/curtain.ts +68 -57
  47. package/src/device/humidifier.ts +65 -53
  48. package/src/device/lock.ts +22 -22
  49. package/src/device/meter.ts +25 -25
  50. package/src/device/motion.ts +27 -27
  51. package/src/device/plug.ts +20 -20
  52. package/src/settings.ts +5 -1
@@ -25,12 +25,6 @@ class ColorBulb {
25
25
  else {
26
26
  this.On = this.accessory.context.On;
27
27
  }
28
- this.Hue = 0;
29
- this.Brightness = 0;
30
- this.Saturation = 0;
31
- this.ColorTemperature = 140;
32
- this.minKelvin = 2000;
33
- this.maxKelvin = 9000;
34
28
  // this is subject we use to track when we need to POST changes to the SwitchBot API
35
29
  this.doColorBulbUpdate = new rxjs_1.Subject();
36
30
  this.colorBulbUpdateInProgress = false;
@@ -40,28 +34,28 @@ class ColorBulb {
40
34
  accessory
41
35
  .getService(this.platform.Service.AccessoryInformation)
42
36
  .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
43
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
37
+ .setCharacteristic(this.platform.Characteristic.Model, this.model(device))
44
38
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
45
39
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
46
40
  // you can create multiple services for each accessory
47
- (this.service = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
48
- `${accessory.displayName} Light Bulb`;
41
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
42
+ `${accessory.displayName} ${this.device.deviceType}`;
49
43
  if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
50
- this.accessory.removeService(this.service);
51
- this.service = this.accessory.addService(this.platform.Service.Lightbulb);
44
+ this.accessory.removeService(this.lightBulbService);
45
+ this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
52
46
  this.accessory.context.adaptiveLighting = false;
53
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
47
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
54
48
  }
55
49
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
56
50
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
57
51
  // accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
58
52
  // set the service name, this is what is displayed as the default name on the Home app
59
53
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
60
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
54
+ this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
61
55
  // handle on / off events using the On characteristic
62
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
56
+ this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
63
57
  // handle Brightness events using the Brightness characteristic
64
- this.service
58
+ this.lightBulbService
65
59
  .getCharacteristic(this.platform.Characteristic.Brightness)
66
60
  .setProps({
67
61
  minStep: this.minStep(device),
@@ -74,19 +68,25 @@ class ColorBulb {
74
68
  })
75
69
  .onSet(this.BrightnessSet.bind(this));
76
70
  // handle ColorTemperature events using the ColorTemperature characteristic
77
- this.service
78
- .getCharacteristic(this.platform.Characteristic.ColorTemperature)
79
- .setProps({
80
- minValue: 140,
81
- maxValue: 500,
82
- validValueRanges: [140, 500],
83
- })
84
- .onGet(() => {
85
- return this.ColorTemperature;
86
- })
87
- .onSet(this.ColorTemperatureSet.bind(this));
71
+ if (device.deviceType === 'Color Bulb') {
72
+ this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
73
+ this.lightBulbService
74
+ .getCharacteristic(this.platform.Characteristic.ColorTemperature)
75
+ .setProps({
76
+ minValue: 140,
77
+ maxValue: 500,
78
+ validValueRanges: [140, 500],
79
+ })
80
+ .onGet(() => {
81
+ return this.ColorTemperature;
82
+ })
83
+ .onSet(this.ColorTemperatureSet.bind(this));
84
+ }
85
+ else {
86
+ this.debugLog(`Color Bulb: ${accessory.displayName} ColorTemperature Characteristic Not Added`);
87
+ }
88
88
  // handle Hue events using the Hue characteristic
89
- this.service
89
+ this.lightBulbService
90
90
  .getCharacteristic(this.platform.Characteristic.Hue)
91
91
  .setProps({
92
92
  minValue: 0,
@@ -98,7 +98,7 @@ class ColorBulb {
98
98
  })
99
99
  .onSet(this.HueSet.bind(this));
100
100
  // handle Hue events using the Hue characteristic
101
- this.service
101
+ this.lightBulbService
102
102
  .getCharacteristic(this.platform.Characteristic.Saturation)
103
103
  .setProps({
104
104
  minValue: 0,
@@ -109,14 +109,14 @@ class ColorBulb {
109
109
  return this.Saturation;
110
110
  })
111
111
  .onSet(this.SaturationSet.bind(this));
112
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
112
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
113
113
  if (this.adaptiveLightingShift !== -1) {
114
- this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
114
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
115
115
  customTemperatureAdjustment: this.adaptiveLightingShift,
116
116
  });
117
117
  this.accessory.configureController(this.AdaptiveLightingController);
118
118
  this.accessory.context.adaptiveLighting = true;
119
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
119
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
120
120
  ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
121
121
  }
122
122
  // Update Homekit
@@ -124,8 +124,8 @@ class ColorBulb {
124
124
  // Start an update interval
125
125
  (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
126
126
  .pipe((0, operators_1.skipWhile)(() => this.colorBulbUpdateInProgress))
127
- .subscribe(() => {
128
- this.refreshStatus();
127
+ .subscribe(async () => {
128
+ await this.refreshStatus();
129
129
  });
130
130
  // Watch for Bulb change events
131
131
  // We put in a debounce of 100ms so we don't make duplicate calls
@@ -138,19 +138,19 @@ class ColorBulb {
138
138
  await this.pushChanges();
139
139
  }
140
140
  catch (e) {
141
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
141
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
142
142
  if (this.deviceLogging === 'debug') {
143
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
143
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
144
144
  }
145
145
  if (this.platform.debugMode) {
146
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
146
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
147
147
  }
148
148
  this.apiError(e);
149
149
  }
150
150
  this.colorBulbUpdateInProgress = false;
151
151
  });
152
152
  }
153
- parseStatus() {
153
+ async parseStatus() {
154
154
  switch (this.power) {
155
155
  case 'on':
156
156
  this.On = true;
@@ -158,53 +158,58 @@ class ColorBulb {
158
158
  default:
159
159
  this.On = false;
160
160
  }
161
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
161
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
162
162
  // Brightness
163
163
  this.Brightness = Number(this.brightness);
164
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
164
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
165
165
  // Color, Hue & Brightness
166
166
  if (this.color) {
167
- this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
167
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
168
168
  const [red, green, blue] = this.color.split(':');
169
- this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
170
- this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
171
- this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
169
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
170
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
171
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
172
172
  const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
173
- this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
173
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
174
174
  // Hue
175
175
  this.Hue = hue;
176
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
176
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
177
177
  // Saturation
178
178
  this.Saturation = saturation;
179
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
179
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
180
180
  }
181
181
  // ColorTemperature
182
- if (!Number.isNaN(this.colorTemperature)) {
183
- this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
184
- const mired = Math.round(1000000 / this.colorTemperature);
185
- this.ColorTemperature = Number(mired);
186
- this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
187
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
182
+ if (this.device.deviceType === 'Color Bulb') {
183
+ if (!Number.isNaN(this.colorTemperature)) {
184
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
185
+ const mired = Math.round(1000000 / this.colorTemperature);
186
+ this.ColorTemperature = Number(mired);
187
+ this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
188
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
189
+ }
188
190
  }
189
191
  }
190
192
  async refreshStatus() {
191
193
  try {
192
194
  this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
193
- this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
195
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
194
196
  this.power = this.deviceStatus.body.power;
195
197
  this.color = this.deviceStatus.body.color;
196
198
  this.brightness = this.deviceStatus.body.brightness;
197
- this.colorTemperature = this.deviceStatus.body.colorTemperature;
199
+ if (this.device.deviceType === 'Color Bulb') {
200
+ this.colorTemperature = this.deviceStatus.body.colorTemperature;
201
+ }
198
202
  this.parseStatus();
199
203
  this.updateHomeKitCharacteristics();
200
204
  }
201
205
  catch (e) {
202
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
206
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
203
207
  if (this.deviceLogging === 'debug') {
204
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
208
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
209
+ ` Error Message: ${JSON.stringify(e.message)}`);
205
210
  }
206
211
  if (this.platform.debugMode) {
207
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
212
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
208
213
  }
209
214
  this.apiError(e);
210
215
  }
@@ -239,11 +244,11 @@ class ColorBulb {
239
244
  else {
240
245
  payload.command = 'turnOff';
241
246
  }
242
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
247
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
243
248
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
244
249
  // Make the API request
245
250
  const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
246
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
251
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
247
252
  this.statusCode(push);
248
253
  this.OnCached = this.On;
249
254
  this.accessory.context.On = this.OnCached;
@@ -253,7 +258,7 @@ class ColorBulb {
253
258
  await this.pushBrightnessChanges();
254
259
  }
255
260
  // Push ColorTemperature Update
256
- if (this.On) {
261
+ if (this.On && this.device.deviceType === 'Color Bulb') {
257
262
  await this.pushColorTemperatureChanges();
258
263
  }
259
264
  // Push Hue & Saturation Update
@@ -262,12 +267,13 @@ class ColorBulb {
262
267
  }
263
268
  }
264
269
  catch (e) {
265
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
270
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
266
271
  if (this.deviceLogging === 'debug') {
267
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
272
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
273
+ ` Error Message: ${JSON.stringify(e.message)}`);
268
274
  }
269
275
  if (this.platform.debugMode) {
270
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
276
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
271
277
  }
272
278
  this.apiError(e);
273
279
  }
@@ -275,36 +281,37 @@ class ColorBulb {
275
281
  async pushHueSaturationChanges() {
276
282
  try {
277
283
  if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
278
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
279
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
284
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
285
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
280
286
  const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
281
- this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
287
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
282
288
  const payload = {
283
289
  commandType: 'command',
284
290
  command: 'setColor',
285
291
  parameter: `${red}:${green}:${blue}`,
286
292
  };
287
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
293
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
288
294
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
289
295
  // Make the API request
290
296
  const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
291
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
297
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
292
298
  this.statusCode(push);
293
299
  this.HueCached = this.Hue;
294
300
  this.SaturationCached = this.Saturation;
295
301
  }
296
302
  else {
297
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
303
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
298
304
  `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
299
305
  }
300
306
  }
301
307
  catch (e) {
302
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
308
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
303
309
  if (this.deviceLogging === 'debug') {
304
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
310
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
311
+ ` Error Message: ${JSON.stringify(e.message)}`);
305
312
  }
306
313
  if (this.platform.debugMode) {
307
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
314
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
308
315
  }
309
316
  this.apiError(e);
310
317
  }
@@ -319,26 +326,27 @@ class ColorBulb {
319
326
  command: 'setColorTemperature',
320
327
  parameter: `${kelvin}`,
321
328
  };
322
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
329
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
323
330
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
324
331
  // Make the API request
325
332
  const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
326
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
333
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
327
334
  this.statusCode(push);
328
335
  this.ColorTemperatureCached = this.ColorTemperature;
329
336
  }
330
337
  else {
331
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
338
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
332
339
  `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
333
340
  }
334
341
  }
335
342
  catch (e) {
336
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
343
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
337
344
  if (this.deviceLogging === 'debug') {
338
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
345
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
346
+ ` Error Message: ${JSON.stringify(e.message)}`);
339
347
  }
340
348
  if (this.platform.debugMode) {
341
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
349
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
342
350
  }
343
351
  this.apiError(e);
344
352
  }
@@ -351,135 +359,141 @@ class ColorBulb {
351
359
  command: 'setBrightness',
352
360
  parameter: `${this.Brightness}`,
353
361
  };
354
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
362
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
355
363
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
356
364
  // Make the API request
357
365
  const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
358
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
366
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
359
367
  this.statusCode(push);
360
368
  this.BrightnessCached = this.Brightness;
361
369
  }
362
370
  else {
363
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
371
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
372
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
364
373
  }
365
374
  }
366
375
  catch (e) {
367
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
376
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
368
377
  if (this.deviceLogging === 'debug') {
369
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
378
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
379
+ ` Error Message: ${JSON.stringify(e.message)}`);
370
380
  }
371
381
  if (this.platform.debugMode) {
372
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
382
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
373
383
  }
374
384
  this.apiError(e);
375
385
  }
376
386
  }
377
- updateHomeKitCharacteristics() {
387
+ async updateHomeKitCharacteristics() {
378
388
  if (this.On === undefined) {
379
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
389
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
380
390
  }
381
391
  else {
382
- this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
383
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
392
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
393
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
384
394
  }
385
395
  if (this.Brightness === undefined) {
386
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
396
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
387
397
  }
388
398
  else {
389
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
390
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
391
- }
392
- if (this.ColorTemperature === undefined) {
393
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
399
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
400
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
394
401
  }
395
- else {
396
- this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
397
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
402
+ if (this.device.deviceType === 'Color Bulb') {
403
+ if (this.ColorTemperature === undefined) {
404
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
405
+ }
406
+ else {
407
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
408
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
409
+ }
398
410
  }
399
411
  if (this.Hue === undefined) {
400
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
412
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
401
413
  }
402
414
  else {
403
- this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
404
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
415
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
416
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
405
417
  }
406
418
  if (this.Saturation === undefined) {
407
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
419
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
408
420
  }
409
421
  else {
410
- this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
411
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
422
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
423
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
412
424
  }
413
425
  }
414
426
  apiError(e) {
415
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
416
- this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
417
- this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
418
- this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
419
- this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
427
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
428
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
429
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
430
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
431
+ if (this.device.deviceType === 'Color Bulb') {
432
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
433
+ }
420
434
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
421
435
  }
422
436
  statusCode(push) {
423
437
  switch (push.data.statusCode) {
424
438
  case 151:
425
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
439
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
426
440
  break;
427
441
  case 152:
428
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
442
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
429
443
  break;
430
444
  case 160:
431
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
445
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
432
446
  break;
433
447
  case 161:
434
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
448
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
435
449
  this.offlineOff();
436
450
  break;
437
451
  case 171:
438
- this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
452
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
439
453
  this.offlineOff();
440
454
  break;
441
455
  case 190:
442
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
456
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
443
457
  ` Or command: ${JSON.stringify(push.data)} format is invalid`);
444
458
  break;
445
459
  case 100:
446
460
  if (this.platform.debugMode) {
447
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
461
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
448
462
  }
449
463
  break;
450
464
  default:
451
465
  if (this.platform.debugMode) {
452
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
466
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
453
467
  }
454
468
  }
455
469
  }
456
- offlineOff() {
470
+ async offlineOff() {
457
471
  if (this.device.offline) {
458
472
  this.On = false;
459
- this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
473
+ this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
460
474
  }
461
475
  }
462
476
  /**
463
477
  * Handle requests to set the value of the "On" characteristic
464
478
  */
465
- OnSet(value) {
466
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
479
+ async OnSet(value) {
480
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
467
481
  this.On = value;
468
482
  this.doColorBulbUpdate.next();
469
483
  }
470
484
  /**
471
485
  * Handle requests to set the value of the "Brightness" characteristic
472
486
  */
473
- BrightnessSet(value) {
474
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
487
+ async BrightnessSet(value) {
488
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
475
489
  this.Brightness = value;
476
490
  this.doColorBulbUpdate.next();
477
491
  }
478
492
  /**
479
493
  * Handle requests to set the value of the "ColorTemperature" characteristic
480
494
  */
481
- ColorTemperatureSet(value) {
482
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
495
+ async ColorTemperatureSet(value) {
496
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
483
497
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
484
498
  const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
485
499
  // Check and increase/decrease kelvin to range of device
@@ -489,30 +503,44 @@ class ColorBulb {
489
503
  }
490
504
  // Updating the hue/sat to the corresponding values mimics native adaptive lighting
491
505
  const hs = (0, settings_1.m2hs)(value);
492
- this.service.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
493
- this.service.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
506
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
507
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
494
508
  this.ColorTemperature = value;
495
509
  this.doColorBulbUpdate.next();
496
510
  }
497
511
  /**
498
512
  * Handle requests to set the value of the "Hue" characteristic
499
513
  */
500
- HueSet(value) {
501
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
502
- this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
514
+ async HueSet(value) {
515
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
516
+ if (this.device.deviceType === 'Color Bulb') {
517
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
518
+ }
503
519
  this.Hue = value;
504
520
  this.doColorBulbUpdate.next();
505
521
  }
506
522
  /**
507
523
  * Handle requests to set the value of the "Saturation" characteristic
508
524
  */
509
- SaturationSet(value) {
510
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
511
- this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
525
+ async SaturationSet(value) {
526
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
527
+ if (this.device.deviceType === 'Color Bulb') {
528
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
529
+ }
512
530
  this.Saturation = value;
513
531
  this.doColorBulbUpdate.next();
514
532
  }
515
- config(device) {
533
+ model(device) {
534
+ let model;
535
+ if (device.deviceType === 'Strip Light') {
536
+ model = 'W1701100';
537
+ }
538
+ else {
539
+ model = 'W1401400';
540
+ }
541
+ return model;
542
+ }
543
+ async config(device) {
516
544
  let config = {};
517
545
  if (device.colorbulb) {
518
546
  config = device.colorbulb;
@@ -533,45 +561,45 @@ class ColorBulb {
533
561
  config['offline'] = device.offline;
534
562
  }
535
563
  if (Object.entries(config).length !== 0) {
536
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
564
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
537
565
  }
538
566
  }
539
- refreshRate(device) {
567
+ async refreshRate(device) {
540
568
  if (device.refreshRate) {
541
569
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
542
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
570
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
543
571
  }
544
572
  else if (this.platform.config.options.refreshRate) {
545
573
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
546
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
574
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
547
575
  }
548
576
  }
549
- logs(device) {
577
+ async logs(device) {
550
578
  if (this.platform.debugMode) {
551
579
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
552
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
580
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
553
581
  }
554
582
  else if (device.logging) {
555
583
  this.deviceLogging = this.accessory.context.logging = device.logging;
556
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
584
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
557
585
  }
558
586
  else if (this.platform.config.options?.logging) {
559
587
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
560
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
588
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
561
589
  }
562
590
  else {
563
591
  this.deviceLogging = this.accessory.context.logging = 'standard';
564
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
592
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
565
593
  }
566
594
  }
567
- adaptiveLighting(device) {
595
+ async adaptiveLighting(device) {
568
596
  if (device.colorbulb?.adaptiveLightingShift) {
569
597
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
570
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
598
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
571
599
  }
572
600
  else {
573
601
  this.adaptiveLightingShift = 0;
574
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
602
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
575
603
  }
576
604
  }
577
605
  minStep(device) {