@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.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 (104) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/extensions.json +5 -0
  3. package/.vscode/settings.json +15 -0
  4. package/dist/devices/bots.d.ts +34 -35
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +241 -184
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +50 -50
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +145 -131
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/contact.d.ts +27 -29
  13. package/dist/devices/contact.d.ts.map +1 -1
  14. package/dist/devices/contact.js +138 -115
  15. package/dist/devices/contact.js.map +1 -1
  16. package/dist/devices/curtains.d.ts +29 -31
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +211 -176
  19. package/dist/devices/curtains.js.map +1 -1
  20. package/dist/devices/humidifiers.d.ts +33 -33
  21. package/dist/devices/humidifiers.d.ts.map +1 -1
  22. package/dist/devices/humidifiers.js +214 -189
  23. package/dist/devices/humidifiers.js.map +1 -1
  24. package/dist/devices/meters.d.ts +30 -31
  25. package/dist/devices/meters.d.ts.map +1 -1
  26. package/dist/devices/meters.js +124 -100
  27. package/dist/devices/meters.js.map +1 -1
  28. package/dist/devices/motion.d.ts +25 -26
  29. package/dist/devices/motion.d.ts.map +1 -1
  30. package/dist/devices/motion.js +120 -102
  31. package/dist/devices/motion.js.map +1 -1
  32. package/dist/devices/plugs.d.ts +23 -23
  33. package/dist/devices/plugs.d.ts.map +1 -1
  34. package/dist/devices/plugs.js +81 -63
  35. package/dist/devices/plugs.js.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +22 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/irdevices/airconditioners.d.ts +6 -6
  41. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  42. package/dist/irdevices/airconditioners.js +105 -79
  43. package/dist/irdevices/airconditioners.js.map +1 -1
  44. package/dist/irdevices/airpurifiers.d.ts +5 -5
  45. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  46. package/dist/irdevices/airpurifiers.js +56 -42
  47. package/dist/irdevices/airpurifiers.js.map +1 -1
  48. package/dist/irdevices/cameras.d.ts +5 -5
  49. package/dist/irdevices/cameras.d.ts.map +1 -1
  50. package/dist/irdevices/cameras.js +31 -27
  51. package/dist/irdevices/cameras.js.map +1 -1
  52. package/dist/irdevices/fans.d.ts +5 -5
  53. package/dist/irdevices/fans.d.ts.map +1 -1
  54. package/dist/irdevices/fans.js +45 -38
  55. package/dist/irdevices/fans.js.map +1 -1
  56. package/dist/irdevices/lights.d.ts +5 -5
  57. package/dist/irdevices/lights.d.ts.map +1 -1
  58. package/dist/irdevices/lights.js +37 -33
  59. package/dist/irdevices/lights.js.map +1 -1
  60. package/dist/irdevices/others.d.ts +5 -5
  61. package/dist/irdevices/others.d.ts.map +1 -1
  62. package/dist/irdevices/others.js +34 -29
  63. package/dist/irdevices/others.js.map +1 -1
  64. package/dist/irdevices/tvs.d.ts +5 -5
  65. package/dist/irdevices/tvs.d.ts.map +1 -1
  66. package/dist/irdevices/tvs.js +91 -76
  67. package/dist/irdevices/tvs.js.map +1 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  69. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  70. package/dist/irdevices/vacuumcleaners.js +31 -27
  71. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  72. package/dist/irdevices/waterheaters.d.ts +5 -5
  73. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  74. package/dist/irdevices/waterheaters.js +31 -27
  75. package/dist/irdevices/waterheaters.js.map +1 -1
  76. package/dist/platform.d.ts +12 -12
  77. package/dist/platform.d.ts.map +1 -1
  78. package/dist/platform.js +241 -172
  79. package/dist/platform.js.map +1 -1
  80. package/dist/settings.d.ts +1 -1
  81. package/dist/settings.d.ts.map +1 -1
  82. package/dist/settings.js +4 -4
  83. package/dist/settings.js.map +1 -1
  84. package/package.json +72 -71
  85. package/src/devices/bots.ts +927 -442
  86. package/src/devices/colorbulb.ts +473 -246
  87. package/src/devices/contact.ts +381 -208
  88. package/src/devices/curtains.ts +613 -321
  89. package/src/devices/humidifiers.ts +594 -323
  90. package/src/devices/meters.ts +331 -186
  91. package/src/devices/motion.ts +327 -184
  92. package/src/devices/plugs.ts +175 -107
  93. package/src/index.ts +5 -5
  94. package/src/irdevices/airconditioners.ts +360 -149
  95. package/src/irdevices/airpurifiers.ts +178 -80
  96. package/src/irdevices/cameras.ts +109 -51
  97. package/src/irdevices/fans.ts +174 -77
  98. package/src/irdevices/lights.ts +110 -57
  99. package/src/irdevices/others.ts +137 -62
  100. package/src/irdevices/tvs.ts +249 -124
  101. package/src/irdevices/vacuumcleaners.ts +112 -52
  102. package/src/irdevices/waterheaters.ts +115 -53
  103. package/src/platform.ts +768 -357
  104. package/src/settings.ts +17 -23
@@ -1,9 +1,28 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.ColorBulb = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const settings_1 = require("../settings");
23
+ const rxjs = __importStar(require("rxjs"));
24
+ const operators = __importStar(require("rxjs/operators"));
25
+ const settings = __importStar(require("../settings"));
7
26
  /**
8
27
  * Platform Accessory
9
28
  * An instance of this class is created for each accessory your platform registers
@@ -32,22 +51,24 @@ class ColorBulb {
32
51
  this.minKelvin = 2000;
33
52
  this.maxKelvin = 9000;
34
53
  // this is subject we use to track when we need to POST changes to the SwitchBot API
35
- this.doColorBulbUpdate = new rxjs_1.Subject();
54
+ this.doColorBulbUpdate = new rxjs.Subject();
36
55
  this.colorBulbUpdateInProgress = false;
37
56
  // Retrieve initial values and updateHomekit
38
57
  this.refreshStatus();
39
58
  // set accessory information
40
59
  accessory
41
60
  .getService(this.platform.Service.AccessoryInformation)
42
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
43
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
61
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
62
+ .setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-COLORBULB-W1401400")
44
63
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
45
64
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
46
65
  // you can create multiple services for each accessory
47
66
  (this.service =
48
67
  accessory.getService(this.platform.Service.Lightbulb) ||
49
- accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
50
- if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
68
+ accessory.addService(this.platform.Service.Lightbulb)),
69
+ `${accessory.displayName} Light Bulb`;
70
+ if (this.adaptiveLightingShift === -1 &&
71
+ this.accessory.context.adaptiveLighting) {
51
72
  this.accessory.removeService(this.service);
52
73
  this.service = this.accessory.addService(this.platform.Service.Lightbulb);
53
74
  this.accessory.context.adaptiveLighting = false;
@@ -60,10 +81,12 @@ class ColorBulb {
60
81
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
61
82
  this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
62
83
  // handle on / off events using the On characteristic
63
- this.service.getCharacteristic(this.platform.Characteristic.On)
84
+ this.service
85
+ .getCharacteristic(this.platform.Characteristic.On)
64
86
  .onSet(this.OnSet.bind(this));
65
87
  // handle Brightness events using the Brightness characteristic
66
- this.service.getCharacteristic(this.platform.Characteristic.Brightness)
88
+ this.service
89
+ .getCharacteristic(this.platform.Characteristic.Brightness)
67
90
  .setProps({
68
91
  minStep: this.minStep(device),
69
92
  minValue: 0,
@@ -75,7 +98,8 @@ class ColorBulb {
75
98
  })
76
99
  .onSet(this.BrightnessSet.bind(this));
77
100
  // handle ColorTemperature events using the ColorTemperature characteristic
78
- this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature)
101
+ this.service
102
+ .getCharacteristic(this.platform.Characteristic.ColorTemperature)
79
103
  .setProps({
80
104
  minValue: 140,
81
105
  maxValue: 500,
@@ -86,7 +110,8 @@ class ColorBulb {
86
110
  })
87
111
  .onSet(this.ColorTemperatureSet.bind(this));
88
112
  // handle Hue events using the Hue characteristic
89
- this.service.getCharacteristic(this.platform.Characteristic.Hue)
113
+ this.service
114
+ .getCharacteristic(this.platform.Characteristic.Hue)
90
115
  .setProps({
91
116
  minValue: 0,
92
117
  maxValue: 360,
@@ -97,7 +122,8 @@ class ColorBulb {
97
122
  })
98
123
  .onSet(this.HueSet.bind(this));
99
124
  // handle Hue events using the Hue characteristic
100
- this.service.getCharacteristic(this.platform.Characteristic.Saturation)
125
+ this.service
126
+ .getCharacteristic(this.platform.Characteristic.Saturation)
101
127
  .setProps({
102
128
  minValue: 0,
103
129
  maxValue: 100,
@@ -109,41 +135,39 @@ class ColorBulb {
109
135
  .onSet(this.SaturationSet.bind(this));
110
136
  this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
111
137
  if (this.adaptiveLightingShift !== -1) {
112
- this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
113
- customTemperatureAdjustment: this.adaptiveLightingShift,
114
- });
138
+ this.AdaptiveLightingController =
139
+ new platform.api.hap.AdaptiveLightingController(this.service, {
140
+ customTemperatureAdjustment: this.adaptiveLightingShift,
141
+ });
115
142
  this.accessory.configureController(this.AdaptiveLightingController);
116
143
  this.accessory.context.adaptiveLighting = true;
117
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
118
- + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
144
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
145
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
119
146
  }
120
147
  // Update Homekit
121
148
  this.updateHomeKitCharacteristics();
122
149
  // Start an update interval
123
- (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
124
- .pipe((0, operators_1.skipWhile)(() => this.colorBulbUpdateInProgress))
150
+ rxjs
151
+ .interval(this.deviceRefreshRate * 1000)
152
+ .pipe(operators.skipWhile(() => this.colorBulbUpdateInProgress))
125
153
  .subscribe(() => {
126
154
  this.refreshStatus();
127
155
  });
128
156
  // Watch for Bulb change events
129
157
  // We put in a debounce of 100ms so we don't make duplicate calls
130
158
  this.doColorBulbUpdate
131
- .pipe((0, operators_1.tap)(() => {
159
+ .pipe(operators.tap(() => {
132
160
  this.colorBulbUpdateInProgress = true;
133
- }), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
161
+ }), operators.debounceTime(this.platform.config.options.pushRate * 1000))
134
162
  .subscribe(async () => {
135
163
  try {
136
164
  await this.pushChanges();
137
165
  }
138
166
  catch (e) {
139
167
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
140
- if (this.deviceLogging === 'debug') {
141
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
142
- + ` Error Message: ${JSON.stringify(e.message)}`);
143
- }
144
- if (this.platform.debugMode) {
145
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
146
- + ` Error: ${JSON.stringify(e)}`);
168
+ if (this.deviceLogging.includes("debug")) {
169
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` +
170
+ ` Error Message: ${JSON.stringify(e.message)}`);
147
171
  }
148
172
  this.apiError(e);
149
173
  }
@@ -152,7 +176,7 @@ class ColorBulb {
152
176
  }
153
177
  parseStatus() {
154
178
  switch (this.power) {
155
- case 'on':
179
+ case "on":
156
180
  this.On = true;
157
181
  break;
158
182
  default:
@@ -165,12 +189,12 @@ class ColorBulb {
165
189
  // Color, Hue & Brightness
166
190
  if (this.color) {
167
191
  this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
168
- const [red, green, blue] = this.color.split(':');
192
+ const [red, green, blue] = this.color.split(":");
169
193
  this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
170
194
  this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
171
195
  this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
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)))}`);
196
+ const [hue, saturation] = settings.rgb2hs(Number(red), Number(green), Number(blue));
197
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(settings.rgb2hs(Number(red), Number(green), Number(blue)))}`);
174
198
  // Hue
175
199
  this.Hue = hue;
176
200
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
@@ -189,7 +213,7 @@ class ColorBulb {
189
213
  }
190
214
  async refreshStatus() {
191
215
  try {
192
- this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
216
+ this.deviceStatus = (await this.platform.axios.get(`${settings.DeviceURL}/${this.device.deviceId}/status`)).data;
193
217
  this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
194
218
  this.power = this.deviceStatus.body.power;
195
219
  this.color = this.deviceStatus.body.color;
@@ -200,45 +224,41 @@ class ColorBulb {
200
224
  }
201
225
  catch (e) {
202
226
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
203
- if (this.deviceLogging === 'debug') {
204
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
205
- + ` Error Message: ${JSON.stringify(e.message)}`);
206
- }
207
- if (this.platform.debugMode) {
208
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
209
- + ` Error: ${JSON.stringify(e)}`);
227
+ if (this.deviceLogging.includes("debug")) {
228
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
229
+ ` Error Message: ${JSON.stringify(e.message)}`);
210
230
  }
211
231
  this.apiError(e);
212
232
  }
213
233
  }
214
234
  /**
215
- * Pushes the requested changes to the SwitchBot API
216
- * deviceType commandType Command command parameter Description
217
- * Color Bulb - "command" "turnOff" "default" = set to OFF state
218
- * Color Bulb - "command" "turnOn" "default" = set to ON state
219
- * Color Bulb - "command" "toggle" "default" = toggle state
220
- * Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
221
- * Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
222
- * Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
223
- */
235
+ * Pushes the requested changes to the SwitchBot API
236
+ * deviceType commandType Command command parameter Description
237
+ * Color Bulb - "command" "turnOff" "default" = set to OFF state
238
+ * Color Bulb - "command" "turnOn" "default" = set to ON state
239
+ * Color Bulb - "command" "toggle" "default" = toggle state
240
+ * Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
241
+ * Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
242
+ * Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
243
+ */
224
244
  async pushChanges() {
225
245
  try {
226
246
  if (this.On !== this.OnCached) {
227
247
  // Push On Update
228
248
  const payload = {
229
- commandType: 'command',
230
- parameter: 'default',
249
+ commandType: "command",
250
+ parameter: "default",
231
251
  };
232
252
  if (this.On) {
233
- payload.command = 'turnOn';
253
+ payload.command = "turnOn";
234
254
  }
235
255
  else {
236
- payload.command = 'turnOff';
256
+ payload.command = "turnOff";
237
257
  }
238
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
239
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
258
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
259
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
240
260
  // Make the API request
241
- const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
261
+ const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
242
262
  this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
243
263
  this.statusCode(push);
244
264
  this.OnCached = this.On;
@@ -259,52 +279,49 @@ class ColorBulb {
259
279
  }
260
280
  catch (e) {
261
281
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
262
- if (this.deviceLogging === 'debug') {
263
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
264
- + ` Error Message: ${JSON.stringify(e.message)}`);
265
- }
266
- if (this.platform.debugMode) {
267
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
268
- + ` Error: ${JSON.stringify(e)}`);
282
+ if (this.deviceLogging.includes("debug")) {
283
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
284
+ ` Error Message: ${JSON.stringify(e.message)}`);
269
285
  }
270
286
  this.apiError(e);
271
287
  }
272
288
  }
273
289
  async pushHueSaturationChanges() {
274
290
  try {
275
- if ((this.Hue !== this.HueCached) || (this.Saturation !== this.SaturationCached)) {
291
+ if (this.Hue !== this.HueCached ||
292
+ this.Saturation !== this.SaturationCached) {
276
293
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
277
294
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
278
- const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
279
- this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
295
+ const [red, green, blue] = settings.hs2rgb(Number(this.Hue), Number(this.Saturation));
296
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([
297
+ red,
298
+ green,
299
+ blue,
300
+ ])}`);
280
301
  const payload = {
281
- commandType: 'command',
282
- command: 'setColor',
302
+ commandType: "command",
303
+ command: "setColor",
283
304
  parameter: `${red}:${green}:${blue}`,
284
305
  };
285
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
286
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
306
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
307
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
287
308
  // Make the API request
288
- const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
309
+ const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
289
310
  this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
290
311
  this.statusCode(push);
291
312
  this.HueCached = this.Hue;
292
313
  this.SaturationCached = this.Saturation;
293
314
  }
294
315
  else {
295
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
296
- + `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
316
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
317
+ `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
297
318
  }
298
319
  }
299
320
  catch (e) {
300
321
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
301
- if (this.deviceLogging === 'debug') {
302
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
303
- + ` Error Message: ${JSON.stringify(e.message)}`);
304
- }
305
- if (this.platform.debugMode) {
306
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
307
- + ` Error: ${JSON.stringify(e)}`);
322
+ if (this.deviceLogging.includes("debug")) {
323
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
324
+ ` Error Message: ${JSON.stringify(e.message)}`);
308
325
  }
309
326
  this.apiError(e);
310
327
  }
@@ -315,32 +332,28 @@ class ColorBulb {
315
332
  const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
316
333
  this.cacheKelvin = kelvin;
317
334
  const payload = {
318
- commandType: 'command',
319
- command: 'setColorTemperature',
335
+ commandType: "command",
336
+ command: "setColorTemperature",
320
337
  parameter: `${kelvin}`,
321
338
  };
322
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
323
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
339
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
340
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
324
341
  // Make the API request
325
- const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
342
+ const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
326
343
  this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
327
344
  this.statusCode(push);
328
345
  this.ColorTemperatureCached = this.ColorTemperature;
329
346
  }
330
347
  else {
331
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
332
- + `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
348
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
349
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
333
350
  }
334
351
  }
335
352
  catch (e) {
336
353
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
337
- if (this.deviceLogging === 'debug') {
338
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
339
- + ` Error Message: ${JSON.stringify(e.message)}`);
340
- }
341
- if (this.platform.debugMode) {
342
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
343
- + ` Error: ${JSON.stringify(e)}`);
354
+ if (this.deviceLogging.includes("debug")) {
355
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
356
+ ` Error Message: ${JSON.stringify(e.message)}`);
344
357
  }
345
358
  this.apiError(e);
346
359
  }
@@ -349,32 +362,28 @@ class ColorBulb {
349
362
  try {
350
363
  if (this.Brightness !== this.BrightnessCached) {
351
364
  const payload = {
352
- commandType: 'command',
353
- command: 'setBrightness',
365
+ commandType: "command",
366
+ command: "setBrightness",
354
367
  parameter: `${this.Brightness}`,
355
368
  };
356
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
357
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
369
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
370
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
358
371
  // Make the API request
359
- const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
372
+ const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
360
373
  this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
361
374
  this.statusCode(push);
362
375
  this.BrightnessCached = this.Brightness;
363
376
  }
364
377
  else {
365
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
366
- + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
378
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
379
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
367
380
  }
368
381
  }
369
382
  catch (e) {
370
383
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
371
- if (this.deviceLogging === 'debug') {
372
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
373
- + ` Error Message: ${JSON.stringify(e.message)}`);
374
- }
375
- if (this.platform.debugMode) {
376
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
377
- + ` Error: ${JSON.stringify(e)}`);
384
+ if (this.deviceLogging.includes("debug")) {
385
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
386
+ ` Error Message: ${JSON.stringify(e.message)}`);
378
387
  }
379
388
  this.apiError(e);
380
389
  }
@@ -444,8 +453,8 @@ class ColorBulb {
444
453
  this.offlineOff();
445
454
  break;
446
455
  case 190:
447
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
448
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
456
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
457
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
449
458
  break;
450
459
  case 100:
451
460
  if (this.platform.debugMode) {
@@ -461,7 +470,9 @@ class ColorBulb {
461
470
  offlineOff() {
462
471
  if (this.device.offline) {
463
472
  this.On = false;
464
- this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
473
+ this.service
474
+ .getCharacteristic(this.platform.Characteristic.On)
475
+ .updateValue(this.On);
465
476
  }
466
477
  }
467
478
  /**
@@ -493,15 +504,15 @@ class ColorBulb {
493
504
  return;
494
505
  }
495
506
  // Updating the hue/sat to the corresponding values mimics native adaptive lighting
496
- const hs = (0, settings_1.m2hs)(value);
507
+ const hs = settings.m2hs(value);
497
508
  this.service.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
498
509
  this.service.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
499
510
  this.ColorTemperature = value;
500
511
  this.doColorBulbUpdate.next();
501
512
  }
502
513
  /**
503
- * Handle requests to set the value of the "Hue" characteristic
504
- */
514
+ * Handle requests to set the value of the "Hue" characteristic
515
+ */
505
516
  HueSet(value) {
506
517
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
507
518
  this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
@@ -509,8 +520,8 @@ class ColorBulb {
509
520
  this.doColorBulbUpdate.next();
510
521
  }
511
522
  /**
512
- * Handle requests to set the value of the "Saturation" characteristic
513
- */
523
+ * Handle requests to set the value of the "Saturation" characteristic
524
+ */
514
525
  SaturationSet(value) {
515
526
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
516
527
  this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
@@ -523,16 +534,16 @@ class ColorBulb {
523
534
  config = device.colorbulb;
524
535
  }
525
536
  if (device.ble) {
526
- config['ble'] = device.ble;
537
+ config["ble"] = device.ble;
527
538
  }
528
539
  if (device.logging !== undefined) {
529
- config['logging'] = device.logging;
540
+ config["logging"] = device.logging;
530
541
  }
531
542
  if (device.refreshRate !== undefined) {
532
- config['refreshRate'] = device.refreshRate;
543
+ config["refreshRate"] = device.refreshRate;
533
544
  }
534
545
  if (device.scanDuration !== undefined) {
535
- config['scanDuration'] = device.scanDuration;
546
+ config["scanDuration"] = device.scanDuration;
536
547
  }
537
548
  if (Object.entries(config).length !== 0) {
538
549
  this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
@@ -540,17 +551,19 @@ class ColorBulb {
540
551
  }
541
552
  refreshRate(device) {
542
553
  if (device.refreshRate) {
543
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
554
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
555
+ device.refreshRate;
544
556
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
545
557
  }
546
558
  else if (this.platform.config.options.refreshRate) {
547
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
559
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
560
+ this.platform.config.options.refreshRate;
548
561
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
549
562
  }
550
563
  }
551
564
  logs(device) {
552
565
  if (this.platform.debugMode) {
553
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
566
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
554
567
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
555
568
  }
556
569
  else if (device.logging) {
@@ -558,11 +571,12 @@ class ColorBulb {
558
571
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
559
572
  }
560
573
  else if (this.platform.config.options?.logging) {
561
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
574
+ this.deviceLogging = this.accessory.context.logging =
575
+ this.platform.config.options?.logging;
562
576
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
563
577
  }
564
578
  else {
565
- this.deviceLogging = this.accessory.context.logging = 'standard';
579
+ this.deviceLogging = this.accessory.context.logging = "standard";
566
580
  this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
567
581
  }
568
582
  }
@@ -586,8 +600,8 @@ class ColorBulb {
586
600
  return this.set_minStep;
587
601
  }
588
602
  /**
589
- * Logging for Device
590
- */
603
+ * Logging for Device
604
+ */
591
605
  infoLog(...log) {
592
606
  if (this.enablingDeviceLogging()) {
593
607
  this.platform.log.info(String(...log));
@@ -605,8 +619,8 @@ class ColorBulb {
605
619
  }
606
620
  debugLog(...log) {
607
621
  if (this.enablingDeviceLogging()) {
608
- if (this.deviceLogging === 'debug') {
609
- this.platform.log.info('[DEBUG]', String(...log));
622
+ if (this.deviceLogging === "debug") {
623
+ this.platform.log.info("[DEBUG]", String(...log));
610
624
  }
611
625
  else {
612
626
  this.platform.log.debug(String(...log));
@@ -614,7 +628,7 @@ class ColorBulb {
614
628
  }
615
629
  }
616
630
  enablingDeviceLogging() {
617
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
631
+ return (this.deviceLogging.includes("debug") || this.deviceLogging === "standard");
618
632
  }
619
633
  }
620
634
  exports.ColorBulb = ColorBulb;