@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3

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 (103) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/config.schema.json +83 -11
  3. package/dist/devices/bots.d.ts +13 -3
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +162 -105
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +13 -3
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +161 -96
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +13 -3
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +117 -63
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +14 -5
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +198 -140
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +13 -3
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +180 -127
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +13 -3
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +121 -63
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +13 -3
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +104 -45
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +13 -3
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +99 -35
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +11 -3
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +80 -45
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +11 -3
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +68 -31
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +11 -3
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +64 -24
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +11 -3
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +74 -35
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +11 -3
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +65 -25
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +11 -3
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +71 -31
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +11 -3
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +81 -42
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +11 -3
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +64 -24
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +11 -3
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +64 -24
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/platform.d.ts +10 -10
  72. package/dist/platform.d.ts.map +1 -1
  73. package/dist/platform.js +290 -307
  74. package/dist/platform.js.map +1 -1
  75. package/dist/settings.d.ts +4 -1
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/nodemon.json +1 -1
  79. package/package.json +70 -66
  80. package/src/devices/bots.ts +169 -105
  81. package/src/devices/colorbulb.ts +170 -99
  82. package/src/devices/contact.ts +124 -64
  83. package/src/devices/curtains.ts +207 -145
  84. package/src/devices/humidifiers.ts +187 -129
  85. package/src/devices/meters.ts +128 -64
  86. package/src/devices/motion.ts +110 -45
  87. package/src/devices/plugs.ts +104 -36
  88. package/src/irdevices/airconditioners.ts +85 -45
  89. package/src/irdevices/airpurifiers.ts +73 -31
  90. package/src/irdevices/cameras.ts +69 -24
  91. package/src/irdevices/fans.ts +79 -36
  92. package/src/irdevices/lights.ts +70 -25
  93. package/src/irdevices/others.ts +76 -31
  94. package/src/irdevices/tvs.ts +86 -42
  95. package/src/irdevices/vacuumcleaners.ts +69 -24
  96. package/src/irdevices/waterheaters.ts +69 -24
  97. package/src/platform.ts +285 -302
  98. package/src/settings.ts +4 -1
  99. package/dist/devices/indoorcam.d.ts +0 -64
  100. package/dist/devices/indoorcam.d.ts.map +0 -1
  101. package/dist/devices/indoorcam.js +0 -249
  102. package/dist/devices/indoorcam.js.map +0 -1
  103. package/src/devices/indoorcam.ts +0 -309
@@ -13,18 +13,18 @@ class Curtain {
13
13
  this.platform = platform;
14
14
  this.accessory = accessory;
15
15
  this.device = device;
16
- this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
17
- this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
18
- // Curtain Config
19
- this.platform.device(`Curtain: ${this.accessory.displayName} Config: (ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},`
20
- + ` hide_lightsensor: ${device.curtain?.hide_lightsensor}, set_minLux: ${device.curtain?.set_minLux}, set_maxLux: `
21
- + `${device.curtain?.set_maxLux}, refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: `
22
- + `${device.curtain?.set_min}, set_minStep: ${device.curtain?.set_minStep})`);
23
16
  // default placeholders
17
+ this.refreshRate();
18
+ this.logs();
24
19
  this.setMinMax();
25
20
  this.CurrentPosition = 0;
26
21
  this.TargetPosition = 0;
27
22
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
23
+ // Curtain Config
24
+ this.debugLog(`Curtain: ${this.accessory.displayName} Config: (ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},`
25
+ + ` hide_lightsensor: ${device.curtain?.hide_lightsensor}, set_minLux: ${device.curtain?.set_minLux}, set_maxLux: `
26
+ + `${device.curtain?.set_maxLux}, refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: `
27
+ + `${device.curtain?.set_min}, set_minStep: ${device.curtain?.set_minStep})`);
28
28
  // this is subject we use to track when we need to POST changes to the SwitchBot API
29
29
  this.doCurtainUpdate = new rxjs_1.Subject();
30
30
  this.curtainUpdateInProgress = false;
@@ -72,36 +72,36 @@ class Curtain {
72
72
  .onSet(this.TargetPositionSet.bind(this));
73
73
  // Light Sensor Service
74
74
  if (device.curtain?.hide_lightsensor) {
75
- this.platform.device(`Curtain: ${accessory.displayName} Removing Light Sensor Service`);
75
+ this.debugLog(`Curtain: ${accessory.displayName} Removing Light Sensor Service`);
76
76
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
77
77
  accessory.removeService(this.lightSensorService);
78
78
  }
79
79
  else if (!this.lightSensorService) {
80
- this.platform.device(`Curtain: ${accessory.displayName} Add Light Sensor Service`);
80
+ this.debugLog(`Curtain: ${accessory.displayName} Add Light Sensor Service`);
81
81
  (this.lightSensorService =
82
82
  this.accessory.getService(this.platform.Service.LightSensor) ||
83
83
  this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`;
84
84
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
85
85
  }
86
86
  else {
87
- this.platform.device(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
87
+ this.debugLog(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`);
88
88
  }
89
89
  // Update Homekit
90
90
  this.updateHomeKitCharacteristics();
91
91
  // Start an update interval
92
- (0, rxjs_1.interval)(this.platform.config.options.refreshRate * 1000)
92
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
93
93
  .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
94
94
  .subscribe(() => {
95
95
  this.refreshStatus();
96
96
  });
97
97
  // update slide progress
98
- (0, rxjs_1.interval)(this.curtainRefreshRate() * 1000)
98
+ (0, rxjs_1.interval)(this.curtainRefreshRate * 1000)
99
99
  .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
100
100
  .subscribe(() => {
101
101
  if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
102
102
  return;
103
103
  }
104
- this.platform.debug(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
104
+ this.debugLog(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
105
105
  this.refreshStatus();
106
106
  });
107
107
  // Watch for Curtain change events
@@ -115,37 +115,73 @@ class Curtain {
115
115
  await this.pushChanges();
116
116
  }
117
117
  catch (e) {
118
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges`);
119
- if (this.deviceDebug) {
120
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
118
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges`);
119
+ if (this.deviceLogging === 'debug') {
120
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,`
121
121
  + ` Error Message: ${JSON.stringify(e.message)}`);
122
122
  }
123
- if (this.debugDebug) {
124
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges,`
123
+ if (this.platform.debugMode) {
124
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,`
125
125
  + ` Error: ${JSON.stringify(e)}`);
126
126
  }
127
- this.apiError(e);
127
+ this.apiError();
128
128
  }
129
129
  this.curtainUpdateInProgress = false;
130
130
  });
131
131
  }
132
- connectBLE() {
133
- const switchbot = new node_switchbot_1.default();
134
- this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
135
- this.platform.device(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
136
- return switchbot;
137
- }
138
- curtainRefreshRate() {
132
+ refreshRate() {
133
+ // refreshRate
134
+ if (this.device.refreshRate) {
135
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
136
+ if (this.platform.debugMode) {
137
+ this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
138
+ }
139
+ }
140
+ else if (this.platform.config.options.refreshRate) {
141
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
142
+ if (this.platform.debugMode) {
143
+ this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
144
+ }
145
+ }
146
+ // curtainRefreshRate
139
147
  if (this.device?.curtain?.refreshRate) {
140
- this.refreshRate = this.device?.curtain?.refreshRate;
148
+ this.curtainRefreshRate = this.device?.curtain?.refreshRate;
149
+ if (this.platform.debugMode) {
150
+ this.warnLog(`Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`);
151
+ }
152
+ }
153
+ else {
154
+ this.curtainRefreshRate = 5;
155
+ if (this.deviceLogging === 'debug') {
156
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
157
+ }
158
+ }
159
+ }
160
+ logs() {
161
+ if (this.device.logging) {
162
+ this.deviceLogging = this.accessory.context.logging = this.device.logging;
163
+ if (this.platform.debugMode) {
164
+ this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
165
+ }
166
+ }
167
+ else if (this.platform.config.options?.logging) {
168
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
169
+ if (this.platform.debugMode) {
170
+ this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
171
+ }
141
172
  }
142
173
  else {
143
- this.refreshRate = 5;
144
- if (this.platform.config.options?.debug === 'device') {
145
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`);
174
+ this.deviceLogging = this.accessory.context.logging = 'standard';
175
+ if (this.platform.debugMode) {
176
+ this.warnLog('Using Device Standard Logging');
146
177
  }
147
178
  }
148
- return this.refreshRate;
179
+ }
180
+ connectBLE() {
181
+ const switchbot = new node_switchbot_1.default();
182
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
183
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
184
+ return switchbot;
149
185
  }
150
186
  minStep() {
151
187
  if (this.device.curtain?.set_minStep) {
@@ -183,37 +219,37 @@ class Curtain {
183
219
  }
184
220
  }
185
221
  async BLEparseStatus() {
186
- this.platform.debug(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
222
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE parseStatus`);
187
223
  this.setMinMax();
188
224
  this.CurrentPosition = 100 - Number(this.position);
189
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
225
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
190
226
  if (this.setNewTarget) {
191
- this.platform.log.info(`Curtain: ${this.accessory.displayName} Checking Status ...`);
227
+ this.infoLog(`Curtain: ${this.accessory.displayName} Checking Status ...`);
192
228
  }
193
229
  if (this.setNewTarget) {
194
230
  this.setMinMax();
195
231
  if (this.TargetPosition > this.CurrentPosition) {
196
- this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
232
+ this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
197
233
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
198
234
  }
199
235
  else if (this.TargetPosition < this.CurrentPosition) {
200
- this.platform.debug(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
236
+ this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
201
237
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
202
238
  }
203
239
  else {
204
- this.platform.debug(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
240
+ this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
205
241
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
206
242
  }
207
243
  }
208
244
  else {
209
- this.platform.debug(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
245
+ this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
210
246
  if (!this.setNewTarget) {
211
247
  // If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.
212
248
  this.TargetPosition = this.CurrentPosition;
213
249
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
214
250
  }
215
251
  }
216
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
252
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
217
253
  + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
218
254
  if (!this.device.curtain?.hide_lightsensor) {
219
255
  this.set_minLux = this.minLux();
@@ -223,47 +259,47 @@ class Curtain {
223
259
  switch (this.lightLevel) {
224
260
  case 1:
225
261
  this.CurrentAmbientLightLevel = this.set_minLux;
226
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
262
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
227
263
  break;
228
264
  case 2:
229
265
  this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels);
230
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
266
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
231
267
  + ` Calculation: ${((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels)}`);
232
268
  break;
233
269
  case 3:
234
270
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2);
235
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
271
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
236
272
  break;
237
273
  case 4:
238
274
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3);
239
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
275
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
240
276
  break;
241
277
  case 5:
242
278
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4);
243
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
279
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
244
280
  break;
245
281
  case 6:
246
282
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5);
247
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
283
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
248
284
  break;
249
285
  case 7:
250
286
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6);
251
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
287
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
252
288
  break;
253
289
  case 8:
254
290
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7);
255
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
291
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
256
292
  break;
257
293
  case 9:
258
294
  this.CurrentAmbientLightLevel = (((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8);
259
- this.platform.device(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
295
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
260
296
  break;
261
297
  case 10:
262
298
  default:
263
299
  this.CurrentAmbientLightLevel = this.set_maxLux;
264
- this.platform.device();
300
+ this.debugLog();
265
301
  }
266
- this.platform.debug(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
302
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
267
303
  + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
268
304
  }
269
305
  // Battery
@@ -274,42 +310,42 @@ class Curtain {
274
310
  else {
275
311
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
276
312
  }
277
- this.platform.debug(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
313
+ this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
278
314
  }
279
315
  async openAPIparseStatus() {
280
316
  if (this.platform.config.credentials?.openToken) {
281
- this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
317
+ this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI parseStatus`);
282
318
  // CurrentPosition
283
319
  this.setMinMax();
284
320
  this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition;
285
- this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
321
+ this.debugLog(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
286
322
  if (this.setNewTarget) {
287
- this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`);
323
+ this.infoLog(`Checking ${this.accessory.displayName} Status ...`);
288
324
  }
289
325
  if (this.deviceStatus.body.moving) {
290
326
  this.setMinMax();
291
327
  if (this.TargetPosition > this.CurrentPosition) {
292
- this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
328
+ this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
293
329
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
294
330
  }
295
331
  else if (this.TargetPosition < this.CurrentPosition) {
296
- this.platform.debug(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
332
+ this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
297
333
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
298
334
  }
299
335
  else {
300
- this.platform.debug(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
336
+ this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
301
337
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
302
338
  }
303
339
  }
304
340
  else {
305
- this.platform.debug(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
341
+ this.debugLog(`Curtain: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
306
342
  if (!this.setNewTarget) {
307
343
  /*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
308
344
  this.TargetPosition = this.CurrentPosition;
309
345
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
310
346
  }
311
347
  }
312
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
348
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},`
313
349
  + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
314
350
  if (!this.device.curtain?.hide_lightsensor) {
315
351
  this.set_minLux = this.minLux();
@@ -323,7 +359,7 @@ class Curtain {
323
359
  default:
324
360
  this.CurrentAmbientLightLevel = this.set_maxLux;
325
361
  }
326
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
362
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
327
363
  }
328
364
  }
329
365
  }
@@ -336,7 +372,7 @@ class Curtain {
336
372
  }
337
373
  }
338
374
  async BLERefreshStatus() {
339
- this.platform.debug(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
375
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE refreshStatus`);
340
376
  // eslint-disable-next-line @typescript-eslint/no-var-requires
341
377
  const switchbot = this.connectBLE();
342
378
  // Start to monitor advertisement packets
@@ -351,16 +387,16 @@ class Curtain {
351
387
  this.battery = ad.serviceData.battery;
352
388
  this.position = ad.serviceData.position;
353
389
  this.lightLevel = ad.serviceData.lightLevel;
354
- this.platform.device(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
355
- this.platform.device(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, `
390
+ this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
391
+ this.debugLog(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, `
356
392
  + `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
357
393
  if (this.serviceData) {
358
394
  this.connected = true;
359
- this.platform.device(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
395
+ this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
360
396
  }
361
397
  else {
362
398
  this.connected = false;
363
- this.platform.device(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
399
+ this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
364
400
  }
365
401
  };
366
402
  // Wait 10 seconds
@@ -373,49 +409,49 @@ class Curtain {
373
409
  this.updateHomeKitCharacteristics();
374
410
  }
375
411
  else {
376
- this.platform.log.error(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
412
+ this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
377
413
  if (this.platform.config.credentials?.openToken) {
378
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
414
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
379
415
  await this.openAPIRefreshStatus();
380
416
  }
381
417
  }
382
418
  }).catch(async (e) => {
383
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
384
- if (this.deviceDebug) {
385
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
419
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
420
+ if (this.deviceLogging === 'debug') {
421
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
386
422
  + ` Error Message: ${JSON.stringify(e.message)}`);
387
423
  }
388
- if (this.debugDebug) {
389
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
424
+ if (this.platform.debugMode) {
425
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
390
426
  + ` Error: ${JSON.stringify(e)}`);
391
427
  }
392
428
  if (this.platform.config.credentials?.openToken) {
393
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
429
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
394
430
  await this.openAPIRefreshStatus();
395
431
  }
396
- this.apiError(e);
432
+ this.apiError();
397
433
  });
398
434
  }
399
435
  async openAPIRefreshStatus() {
400
436
  if (this.platform.config.credentials?.openToken) {
401
- this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
437
+ this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
402
438
  try {
403
439
  this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
404
- this.platform.debug(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
440
+ this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
405
441
  this.parseStatus();
406
442
  this.updateHomeKitCharacteristics();
407
443
  }
408
444
  catch (e) {
409
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
410
- if (this.deviceDebug) {
411
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
445
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
446
+ if (this.deviceLogging === 'debug') {
447
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
412
448
  + ` Error Message: ${JSON.stringify(e.message)}`);
413
449
  }
414
- if (this.debugDebug) {
415
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
450
+ if (this.platform.debugMode) {
451
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
416
452
  + ` Error: ${JSON.stringify(e)}`);
417
453
  }
418
- this.apiError(e);
454
+ this.apiError();
419
455
  }
420
456
  }
421
457
  }
@@ -435,183 +471,174 @@ class Curtain {
435
471
  }
436
472
  async BLEpushChanges() {
437
473
  if (this.TargetPosition !== this.CurrentPosition) {
438
- this.platform.debug(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
474
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
439
475
  const switchbot = this.connectBLE();
440
476
  switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
441
- this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
477
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
442
478
  return device_list[0].runToPos(100 - Number(this.TargetPosition));
443
479
  }).then(() => {
444
- this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
480
+ this.debugLog(`Curtain: ${this.accessory.displayName} Done.`);
445
481
  }).catch(async (e) => {
446
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
447
- if (this.deviceDebug) {
448
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
482
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
483
+ if (this.deviceLogging === 'debug') {
484
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
449
485
  + ` Error Message: ${JSON.stringify(e.message)}`);
450
486
  }
451
- if (this.debugDebug) {
452
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
487
+ if (this.platform.debugMode) {
488
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
453
489
  + ` Error: ${JSON.stringify(e)}`);
454
490
  }
455
491
  if (this.platform.config.credentials?.openToken) {
456
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
492
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
457
493
  await this.OpenAPIpushChanges();
458
494
  }
459
- this.apiError(e);
495
+ this.apiError();
460
496
  });
461
497
  }
462
498
  else {
463
- this.platform.debug(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
499
+ this.debugLog(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
464
500
  + ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
465
501
  }
466
502
  }
467
503
  async OpenAPIpushChanges() {
468
504
  if (this.platform.config.credentials?.openToken) {
469
505
  try {
470
- this.platform.debug(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
506
+ this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
471
507
  if (this.TargetPosition !== this.CurrentPosition) {
472
- this.platform.debug(`Pushing ${this.TargetPosition}`);
508
+ this.debugLog(`Pushing ${this.TargetPosition}`);
473
509
  const adjustedTargetPosition = 100 - Number(this.TargetPosition);
474
510
  const payload = {
475
511
  commandType: 'command',
476
512
  command: 'setPosition',
477
513
  parameter: `0,ff,${adjustedTargetPosition}`,
478
514
  };
479
- this.platform.log.info(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
515
+ this.infoLog(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
480
516
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
481
517
  // Make the API request
482
518
  const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
483
- this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
519
+ this.debugLog(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
484
520
  this.statusCode(push);
485
521
  }
486
522
  else {
487
- this.platform.debug(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
523
+ this.debugLog(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
488
524
  + ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
489
525
  }
490
526
  }
491
527
  catch (e) {
492
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
493
- if (this.deviceDebug) {
494
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
528
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
529
+ if (this.deviceLogging === 'debug') {
530
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
495
531
  + ` Error Message: ${JSON.stringify(e.message)}`);
496
532
  }
497
- if (this.debugDebug) {
498
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
533
+ if (this.platform.debugMode) {
534
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
499
535
  + ` Error: ${JSON.stringify(e)}`);
500
536
  }
501
- this.apiError(e);
537
+ this.apiError();
502
538
  }
503
539
  }
504
540
  }
505
541
  updateHomeKitCharacteristics() {
506
542
  this.setMinMax();
507
543
  if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
508
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
544
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
509
545
  }
510
546
  else {
511
547
  this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
512
- this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
548
+ this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
513
549
  }
514
550
  if (this.PositionState === undefined) {
515
- this.platform.debug(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
551
+ this.debugLog(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`);
516
552
  }
517
553
  else {
518
- this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
554
+ this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
519
555
  }
520
556
  if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
521
- this.platform.debug(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
557
+ this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
522
558
  }
523
559
  else {
524
560
  this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
525
- this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
561
+ this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
526
562
  }
527
563
  if (!this.device.curtain?.hide_lightsensor) {
528
564
  if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
529
- this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
565
+ this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
530
566
  }
531
567
  else {
532
568
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
533
- this.platform.device(`Curtain: ${this.accessory.displayName}`
569
+ this.debugLog(`Curtain: ${this.accessory.displayName}`
534
570
  + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
535
571
  }
536
572
  }
537
573
  if (this.device.ble) {
538
574
  if (this.BatteryLevel === undefined) {
539
- this.platform.debug(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
575
+ this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
540
576
  }
541
577
  else {
542
578
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
543
- this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
579
+ this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
544
580
  }
545
581
  if (this.StatusLowBattery === undefined) {
546
- this.platform.debug(`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
582
+ this.debugLog(`Curtain: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
547
583
  }
548
584
  else {
549
585
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
550
- this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
586
+ this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
551
587
  }
552
588
  }
553
589
  }
554
- apiError(e) {
555
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
556
- this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e);
557
- this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
558
- if (!this.device.curtain?.hide_lightsensor) {
559
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
560
- }
561
- if (this.device.ble) {
562
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
563
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
564
- }
590
+ apiError() {
591
+ throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */);
565
592
  }
566
593
  statusCode(push) {
567
594
  switch (push.data.statusCode) {
568
595
  case 151:
569
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Command not supported by this device type.`);
596
+ this.errorLog(`Curtain: ${this.accessory.displayName} Command not supported by this device type.`);
570
597
  break;
571
598
  case 152:
572
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Device not found.`);
599
+ this.errorLog(`Curtain: ${this.accessory.displayName} Device not found.`);
573
600
  break;
574
601
  case 160:
575
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Command is not supported.`);
602
+ this.errorLog(`Curtain: ${this.accessory.displayName} Command is not supported.`);
576
603
  break;
577
604
  case 161:
578
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Device is offline.`);
605
+ this.errorLog(`Curtain: ${this.accessory.displayName} Device is offline.`);
579
606
  break;
580
607
  case 171:
581
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
608
+ this.errorLog(`Curtain: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
582
609
  break;
583
610
  case 190:
584
- this.platform.log.error(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
611
+ this.errorLog(`Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
585
612
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
586
613
  break;
587
614
  case 100:
588
- this.platform.debug(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
615
+ this.debugLog(`Curtain: ${this.accessory.displayName} Command successfully sent.`);
589
616
  break;
590
617
  default:
591
- this.platform.debug(`Curtain: ${this.accessory.displayName} Unknown statusCode.`);
618
+ this.debugLog(`Curtain: ${this.accessory.displayName} Unknown statusCode.`);
592
619
  }
593
620
  }
594
621
  /**
595
622
  * Handle requests to set the value of the "Target Position" characteristic
596
623
  */
597
624
  TargetPositionSet(value) {
598
- this.platform.debug(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
625
+ this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${value}`);
599
626
  this.TargetPosition = value;
600
627
  this.setMinMax();
601
628
  if (value > this.CurrentPosition) {
602
629
  this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
603
630
  this.setNewTarget = true;
604
- this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
631
+ this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
605
632
  }
606
633
  else if (value < this.CurrentPosition) {
607
634
  this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
608
635
  this.setNewTarget = true;
609
- this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
636
+ this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
610
637
  }
611
638
  else {
612
639
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
613
640
  this.setNewTarget = false;
614
- this.platform.debug(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
641
+ this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
615
642
  }
616
643
  this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
617
644
  this.service.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
@@ -622,7 +649,7 @@ class Curtain {
622
649
  clearTimeout(this.setNewTargetTimer);
623
650
  if (this.setNewTarget) {
624
651
  this.setNewTargetTimer = setTimeout(() => {
625
- this.platform.debug(`Curtain: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
652
+ this.debugLog(`Curtain: ${this.accessory.displayName} setNewTarget ${this.setNewTarget} timeout`);
626
653
  this.setNewTarget = false;
627
654
  }, 10000);
628
655
  }
@@ -640,6 +667,37 @@ class Curtain {
640
667
  }
641
668
  }
642
669
  }
670
+ /**
671
+ * Logging for Device
672
+ */
673
+ infoLog(...log) {
674
+ if (this.enablingDeviceLogging()) {
675
+ this.platform.log.info(String(...log));
676
+ }
677
+ }
678
+ warnLog(...log) {
679
+ if (this.enablingDeviceLogging()) {
680
+ this.platform.log.warn(String(...log));
681
+ }
682
+ }
683
+ errorLog(...log) {
684
+ if (this.enablingDeviceLogging()) {
685
+ this.platform.log.error(String(...log));
686
+ }
687
+ }
688
+ debugLog(...log) {
689
+ if (this.enablingDeviceLogging()) {
690
+ if (this.deviceLogging === 'debug') {
691
+ this.platform.log.info('[DEBUG]', String(...log));
692
+ }
693
+ else {
694
+ this.platform.log.debug(String(...log));
695
+ }
696
+ }
697
+ }
698
+ enablingDeviceLogging() {
699
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
700
+ }
643
701
  }
644
702
  exports.Curtain = Curtain;
645
703
  //# sourceMappingURL=curtains.js.map